Skip to content

Commit 8f81709

Browse files
committed
Add JNI bindings
1 parent 9010525 commit 8f81709

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

java/rocksjni/secondary_cache.cc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 JNI bindings for SecondaryCache
7+
8+
#include <jni.h>
9+
10+
#include "include/org_rocksdb_SecondaryCache.h"
11+
#include "rocksdb/cache.h"
12+
#include "rocksjni/cplusplus_to_java_convert.h"
13+
#include "rocksjni/portal.h"
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
/*
20+
* Class: org_rocksdb_SecondaryCache_CompressedSecondaryCache
21+
* Method: newCompressedSecondaryCacheInstance
22+
* Signature: (J)J
23+
*/
24+
JNIEXPORT jlong JNICALL Java_org_rocksdb_SecondaryCache_00024CompressedSecondaryCache_newCompressedSecondaryCacheInstance__J(
25+
JNIEnv* /*env*/, jclass /*jcls*/, jlong jcapacity) {
26+
auto opts = ROCKSDB_NAMESPACE::CompressedSecondaryCacheOptions();
27+
opts.capacity = static_cast<size_t>(jcapacity);
28+
auto cache = opts.MakeSharedSecondaryCache();
29+
auto* cache_ptr =
30+
new std::shared_ptr<ROCKSDB_NAMESPACE::SecondaryCache>(cache);
31+
return GET_CPLUSPLUS_POINTER(cache_ptr);
32+
}
33+
34+
/*
35+
* Class: org_rocksdb_SecondaryCache_CompressedSecondaryCache
36+
* Method: newCompressedSecondaryCacheInstance
37+
* Signature: (JIZD)J
38+
*/
39+
JNIEXPORT jlong JNICALL Java_org_rocksdb_SecondaryCache_00024CompressedSecondaryCache_newCompressedSecondaryCacheInstance__JIZD(
40+
JNIEnv* /*env*/, jclass /*jcls*/, jlong jcapacity, jint jnum_shard_bits,
41+
jboolean jstrict_capacity_limit, jdouble jhigh_pri_pool_ratio) {
42+
auto opts = ROCKSDB_NAMESPACE::CompressedSecondaryCacheOptions();
43+
opts.capacity = static_cast<size_t>(jcapacity);
44+
opts.num_shard_bits = static_cast<int>(jnum_shard_bits);
45+
opts.strict_capacity_limit = static_cast<bool>(jstrict_capacity_limit);
46+
opts.high_pri_pool_ratio = static_cast<double>(jhigh_pri_pool_ratio);
47+
48+
auto cache = opts.MakeSharedSecondaryCache();
49+
auto* cache_ptr =
50+
new std::shared_ptr<ROCKSDB_NAMESPACE::SecondaryCache>(cache);
51+
return GET_CPLUSPLUS_POINTER(cache_ptr);
52+
}
53+
54+
/*
55+
* Class: org_rocksdb_SecondaryCache
56+
* Method: disposeInternalJni
57+
* Signature: (J)V
58+
*/
59+
JNIEXPORT void JNICALL Java_org_rocksdb_SecondaryCache_disposeInternalJni(JNIEnv* /*env*/,
60+
jobject /*jobj*/,
61+
jlong jhandle) {
62+
auto* cache =
63+
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SecondaryCache>*>(
64+
jhandle);
65+
assert(cache != nullptr);
66+
delete cache;
67+
}
68+
69+
#ifdef __cplusplus
70+
}
71+
#endif

0 commit comments

Comments
 (0)