]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/rocksjni/env.cc
5433faf00bfb79277ecfb7a83119aa084728a30c
[ceph.git] / ceph / src / rocksdb / java / rocksjni / env.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5 //
6 // This file implements the "bridge" between Java and C++ and enables
7 // calling c++ rocksdb::Env methods from Java side.
8
9 #include "rocksdb/env.h"
10 #include "include/org_rocksdb_Env.h"
11 #include "include/org_rocksdb_RocksEnv.h"
12 #include "include/org_rocksdb_RocksMemEnv.h"
13
14 /*
15 * Class: org_rocksdb_Env
16 * Method: getDefaultEnvInternal
17 * Signature: ()J
18 */
19 jlong Java_org_rocksdb_Env_getDefaultEnvInternal(JNIEnv* /*env*/,
20 jclass /*jclazz*/) {
21 return reinterpret_cast<jlong>(rocksdb::Env::Default());
22 }
23
24 /*
25 * Class: org_rocksdb_Env
26 * Method: setBackgroundThreads
27 * Signature: (JII)V
28 */
29 void Java_org_rocksdb_Env_setBackgroundThreads(JNIEnv* /*env*/,
30 jobject /*jobj*/, jlong jhandle,
31 jint num, jint priority) {
32 auto* rocks_env = reinterpret_cast<rocksdb::Env*>(jhandle);
33 switch (priority) {
34 case org_rocksdb_Env_FLUSH_POOL:
35 rocks_env->SetBackgroundThreads(num, rocksdb::Env::Priority::LOW);
36 break;
37 case org_rocksdb_Env_COMPACTION_POOL:
38 rocks_env->SetBackgroundThreads(num, rocksdb::Env::Priority::HIGH);
39 break;
40 }
41 }
42
43 /*
44 * Class: org_rocksdb_sEnv
45 * Method: getThreadPoolQueueLen
46 * Signature: (JI)I
47 */
48 jint Java_org_rocksdb_Env_getThreadPoolQueueLen(JNIEnv* /*env*/,
49 jobject /*jobj*/, jlong jhandle,
50 jint pool_id) {
51 auto* rocks_env = reinterpret_cast<rocksdb::Env*>(jhandle);
52 switch (pool_id) {
53 case org_rocksdb_RocksEnv_FLUSH_POOL:
54 return rocks_env->GetThreadPoolQueueLen(rocksdb::Env::Priority::LOW);
55 case org_rocksdb_RocksEnv_COMPACTION_POOL:
56 return rocks_env->GetThreadPoolQueueLen(rocksdb::Env::Priority::HIGH);
57 }
58 return 0;
59 }
60
61 /*
62 * Class: org_rocksdb_RocksMemEnv
63 * Method: createMemEnv
64 * Signature: ()J
65 */
66 jlong Java_org_rocksdb_RocksMemEnv_createMemEnv(JNIEnv* /*env*/,
67 jclass /*jclazz*/) {
68 return reinterpret_cast<jlong>(rocksdb::NewMemEnv(rocksdb::Env::Default()));
69 }
70
71 /*
72 * Class: org_rocksdb_RocksMemEnv
73 * Method: disposeInternal
74 * Signature: (J)V
75 */
76 void Java_org_rocksdb_RocksMemEnv_disposeInternal(JNIEnv* /*env*/,
77 jobject /*jobj*/,
78 jlong jhandle) {
79 auto* e = reinterpret_cast<rocksdb::Env*>(jhandle);
80 assert(e != nullptr);
81 delete e;
82 }