2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2014-06-06 00:09:25 +00:00
|
|
|
//
|
|
|
|
// This file implements the "bridge" between Java and C++ and enables
|
|
|
|
// calling c++ rocksdb::Env methods from Java side.
|
|
|
|
|
2018-04-13 00:55:14 +00:00
|
|
|
#include "rocksdb/env.h"
|
2015-03-22 17:30:51 +00:00
|
|
|
#include "include/org_rocksdb_Env.h"
|
2014-06-06 00:09:25 +00:00
|
|
|
#include "include/org_rocksdb_RocksEnv.h"
|
2015-03-22 17:30:51 +00:00
|
|
|
#include "include/org_rocksdb_RocksMemEnv.h"
|
2014-06-06 00:09:25 +00:00
|
|
|
|
|
|
|
/*
|
2015-03-22 17:30:51 +00:00
|
|
|
* Class: org_rocksdb_Env
|
2014-06-06 00:09:25 +00:00
|
|
|
* Method: getDefaultEnvInternal
|
|
|
|
* Signature: ()J
|
|
|
|
*/
|
2018-04-13 00:55:14 +00:00
|
|
|
jlong Java_org_rocksdb_Env_getDefaultEnvInternal(JNIEnv* /*env*/,
|
|
|
|
jclass /*jclazz*/) {
|
2014-06-06 00:09:25 +00:00
|
|
|
return reinterpret_cast<jlong>(rocksdb::Env::Default());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-03-22 17:30:51 +00:00
|
|
|
* Class: org_rocksdb_Env
|
2014-06-06 00:09:25 +00:00
|
|
|
* Method: setBackgroundThreads
|
|
|
|
* Signature: (JII)V
|
|
|
|
*/
|
2018-04-13 00:55:14 +00:00
|
|
|
void Java_org_rocksdb_Env_setBackgroundThreads(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/, jlong jhandle,
|
|
|
|
jint num, jint priority) {
|
2014-06-06 00:09:25 +00:00
|
|
|
auto* rocks_env = reinterpret_cast<rocksdb::Env*>(jhandle);
|
|
|
|
switch (priority) {
|
2015-03-22 17:30:51 +00:00
|
|
|
case org_rocksdb_Env_FLUSH_POOL:
|
2014-06-06 00:09:25 +00:00
|
|
|
rocks_env->SetBackgroundThreads(num, rocksdb::Env::Priority::LOW);
|
|
|
|
break;
|
2015-03-22 17:30:51 +00:00
|
|
|
case org_rocksdb_Env_COMPACTION_POOL:
|
2014-06-06 00:09:25 +00:00
|
|
|
rocks_env->SetBackgroundThreads(num, rocksdb::Env::Priority::HIGH);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-03-22 17:30:51 +00:00
|
|
|
* Class: org_rocksdb_sEnv
|
2014-06-06 00:09:25 +00:00
|
|
|
* Method: getThreadPoolQueueLen
|
|
|
|
* Signature: (JI)I
|
|
|
|
*/
|
2018-04-13 00:55:14 +00:00
|
|
|
jint Java_org_rocksdb_Env_getThreadPoolQueueLen(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/, jlong jhandle,
|
|
|
|
jint pool_id) {
|
2014-06-06 00:09:25 +00:00
|
|
|
auto* rocks_env = reinterpret_cast<rocksdb::Env*>(jhandle);
|
|
|
|
switch (pool_id) {
|
|
|
|
case org_rocksdb_RocksEnv_FLUSH_POOL:
|
|
|
|
return rocks_env->GetThreadPoolQueueLen(rocksdb::Env::Priority::LOW);
|
|
|
|
case org_rocksdb_RocksEnv_COMPACTION_POOL:
|
|
|
|
return rocks_env->GetThreadPoolQueueLen(rocksdb::Env::Priority::HIGH);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-03-22 17:30:51 +00:00
|
|
|
* Class: org_rocksdb_RocksMemEnv
|
|
|
|
* Method: createMemEnv
|
|
|
|
* Signature: ()J
|
|
|
|
*/
|
2018-04-13 00:55:14 +00:00
|
|
|
jlong Java_org_rocksdb_RocksMemEnv_createMemEnv(JNIEnv* /*env*/,
|
|
|
|
jclass /*jclazz*/) {
|
|
|
|
return reinterpret_cast<jlong>(rocksdb::NewMemEnv(rocksdb::Env::Default()));
|
2015-03-22 17:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksMemEnv
|
2014-06-06 00:09:25 +00:00
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 00:55:14 +00:00
|
|
|
void Java_org_rocksdb_RocksMemEnv_disposeInternal(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jhandle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* e = reinterpret_cast<rocksdb::Env*>(jhandle);
|
|
|
|
assert(e != nullptr);
|
|
|
|
delete e;
|
2014-06-06 00:09:25 +00:00
|
|
|
}
|