2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02: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 02:09:25 +02:00
|
|
|
//
|
|
|
|
// This file implements the "bridge" between Java and C++ and enables
|
|
|
|
// calling c++ rocksdb::Env methods from Java side.
|
|
|
|
|
2015-03-22 18:30:51 +01:00
|
|
|
#include "include/org_rocksdb_Env.h"
|
2014-06-06 02:09:25 +02:00
|
|
|
#include "include/org_rocksdb_RocksEnv.h"
|
2015-03-22 18:30:51 +01:00
|
|
|
#include "include/org_rocksdb_RocksMemEnv.h"
|
2014-06-06 02:09:25 +02:00
|
|
|
#include "rocksdb/env.h"
|
|
|
|
|
|
|
|
/*
|
2015-03-22 18:30:51 +01:00
|
|
|
* Class: org_rocksdb_Env
|
2014-06-06 02:09:25 +02:00
|
|
|
* Method: getDefaultEnvInternal
|
|
|
|
* Signature: ()J
|
|
|
|
*/
|
2015-03-22 18:30:51 +01:00
|
|
|
jlong Java_org_rocksdb_Env_getDefaultEnvInternal(
|
2014-11-06 23:12:36 +01:00
|
|
|
JNIEnv* env, jclass jclazz) {
|
2014-06-06 02:09:25 +02:00
|
|
|
return reinterpret_cast<jlong>(rocksdb::Env::Default());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-03-22 18:30:51 +01:00
|
|
|
* Class: org_rocksdb_Env
|
2014-06-06 02:09:25 +02:00
|
|
|
* Method: setBackgroundThreads
|
|
|
|
* Signature: (JII)V
|
|
|
|
*/
|
2015-03-22 18:30:51 +01:00
|
|
|
void Java_org_rocksdb_Env_setBackgroundThreads(
|
2014-06-06 02:09:25 +02:00
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle,
|
|
|
|
jint num, jint priority) {
|
|
|
|
auto* rocks_env = reinterpret_cast<rocksdb::Env*>(jhandle);
|
|
|
|
switch (priority) {
|
2015-03-22 18:30:51 +01:00
|
|
|
case org_rocksdb_Env_FLUSH_POOL:
|
2014-06-06 02:09:25 +02:00
|
|
|
rocks_env->SetBackgroundThreads(num, rocksdb::Env::Priority::LOW);
|
|
|
|
break;
|
2015-03-22 18:30:51 +01:00
|
|
|
case org_rocksdb_Env_COMPACTION_POOL:
|
2014-06-06 02:09:25 +02:00
|
|
|
rocks_env->SetBackgroundThreads(num, rocksdb::Env::Priority::HIGH);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-03-22 18:30:51 +01:00
|
|
|
* Class: org_rocksdb_sEnv
|
2014-06-06 02:09:25 +02:00
|
|
|
* Method: getThreadPoolQueueLen
|
|
|
|
* Signature: (JI)I
|
|
|
|
*/
|
2015-03-22 18:30:51 +01:00
|
|
|
jint Java_org_rocksdb_Env_getThreadPoolQueueLen(
|
2014-06-06 02:09:25 +02:00
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jint pool_id) {
|
|
|
|
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 18:30:51 +01:00
|
|
|
* Class: org_rocksdb_RocksMemEnv
|
|
|
|
* Method: createMemEnv
|
|
|
|
* Signature: ()J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_RocksMemEnv_createMemEnv(
|
|
|
|
JNIEnv* env, jclass jclazz) {
|
|
|
|
return reinterpret_cast<jlong>(rocksdb::NewMemEnv(
|
|
|
|
rocksdb::Env::Default()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksMemEnv
|
2014-06-06 02:09:25 +02:00
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2015-03-22 18:30:51 +01:00
|
|
|
void Java_org_rocksdb_RocksMemEnv_disposeInternal(
|
2014-06-06 02:09:25 +02:00
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* e = reinterpret_cast<rocksdb::Env*>(jhandle);
|
|
|
|
assert(e != nullptr);
|
|
|
|
delete e;
|
2014-06-06 02:09:25 +02:00
|
|
|
}
|