]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/rocksjni/env.cc
add subtree-ish sources for 12.0.3
[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 the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same 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 "include/org_rocksdb_Env.h"
10 #include "include/org_rocksdb_RocksEnv.h"
11 #include "include/org_rocksdb_RocksMemEnv.h"
12 #include "rocksdb/env.h"
13
14 /*
15 * Class: org_rocksdb_Env
16 * Method: getDefaultEnvInternal
17 * Signature: ()J
18 */
19 jlong Java_org_rocksdb_Env_getDefaultEnvInternal(
20 JNIEnv* env, 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(
30 JNIEnv* env, 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(
49 JNIEnv* env, jobject jobj, jlong jhandle, jint pool_id) {
50 auto* rocks_env = reinterpret_cast<rocksdb::Env*>(jhandle);
51 switch (pool_id) {
52 case org_rocksdb_RocksEnv_FLUSH_POOL:
53 return rocks_env->GetThreadPoolQueueLen(rocksdb::Env::Priority::LOW);
54 case org_rocksdb_RocksEnv_COMPACTION_POOL:
55 return rocks_env->GetThreadPoolQueueLen(rocksdb::Env::Priority::HIGH);
56 }
57 return 0;
58 }
59
60 /*
61 * Class: org_rocksdb_RocksMemEnv
62 * Method: createMemEnv
63 * Signature: ()J
64 */
65 jlong Java_org_rocksdb_RocksMemEnv_createMemEnv(
66 JNIEnv* env, jclass jclazz) {
67 return reinterpret_cast<jlong>(rocksdb::NewMemEnv(
68 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(
77 JNIEnv* env, jobject jobj, jlong jhandle) {
78 auto* e = reinterpret_cast<rocksdb::Env*>(jhandle);
79 assert(e != nullptr);
80 delete e;
81 }