]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/rocksjni/ratelimiterjni.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / java / rocksjni / ratelimiterjni.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++ for RateLimiter.
7
8 #include "include/org_rocksdb_RateLimiter.h"
9 #include "rocksdb/rate_limiter.h"
10 #include "rocksjni/cplusplus_to_java_convert.h"
11 #include "rocksjni/portal.h"
12
13 /*
14 * Class: org_rocksdb_RateLimiter
15 * Method: newRateLimiterHandle
16 * Signature: (JJIBZ)J
17 */
18 jlong Java_org_rocksdb_RateLimiter_newRateLimiterHandle(
19 JNIEnv* /*env*/, jclass /*jclazz*/, jlong jrate_bytes_per_second,
20 jlong jrefill_period_micros, jint jfairness, jbyte jrate_limiter_mode,
21 jboolean jauto_tune) {
22 auto rate_limiter_mode =
23 ROCKSDB_NAMESPACE::RateLimiterModeJni::toCppRateLimiterMode(
24 jrate_limiter_mode);
25 auto* sptr_rate_limiter = new std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>(
26 ROCKSDB_NAMESPACE::NewGenericRateLimiter(
27 static_cast<int64_t>(jrate_bytes_per_second),
28 static_cast<int64_t>(jrefill_period_micros),
29 static_cast<int32_t>(jfairness), rate_limiter_mode, jauto_tune));
30
31 return GET_CPLUSPLUS_POINTER(sptr_rate_limiter);
32 }
33
34 /*
35 * Class: org_rocksdb_RateLimiter
36 * Method: disposeInternal
37 * Signature: (J)V
38 */
39 void Java_org_rocksdb_RateLimiter_disposeInternal(JNIEnv* /*env*/,
40 jobject /*jobj*/,
41 jlong jhandle) {
42 auto* handle =
43 reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(
44 jhandle);
45 delete handle; // delete std::shared_ptr
46 }
47
48 /*
49 * Class: org_rocksdb_RateLimiter
50 * Method: setBytesPerSecond
51 * Signature: (JJ)V
52 */
53 void Java_org_rocksdb_RateLimiter_setBytesPerSecond(JNIEnv* /*env*/,
54 jobject /*jobj*/,
55 jlong handle,
56 jlong jbytes_per_second) {
57 reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(handle)
58 ->get()
59 ->SetBytesPerSecond(jbytes_per_second);
60 }
61
62 /*
63 * Class: org_rocksdb_RateLimiter
64 * Method: getBytesPerSecond
65 * Signature: (J)J
66 */
67 jlong Java_org_rocksdb_RateLimiter_getBytesPerSecond(JNIEnv* /*env*/,
68 jobject /*jobj*/,
69 jlong handle) {
70 return reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(
71 handle)
72 ->get()
73 ->GetBytesPerSecond();
74 }
75
76 /*
77 * Class: org_rocksdb_RateLimiter
78 * Method: request
79 * Signature: (JJ)V
80 */
81 void Java_org_rocksdb_RateLimiter_request(JNIEnv* /*env*/, jobject /*jobj*/,
82 jlong handle, jlong jbytes) {
83 reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(handle)
84 ->get()
85 ->Request(jbytes, ROCKSDB_NAMESPACE::Env::IO_TOTAL);
86 }
87
88 /*
89 * Class: org_rocksdb_RateLimiter
90 * Method: getSingleBurstBytes
91 * Signature: (J)J
92 */
93 jlong Java_org_rocksdb_RateLimiter_getSingleBurstBytes(JNIEnv* /*env*/,
94 jobject /*jobj*/,
95 jlong handle) {
96 return reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(
97 handle)
98 ->get()
99 ->GetSingleBurstBytes();
100 }
101
102 /*
103 * Class: org_rocksdb_RateLimiter
104 * Method: getTotalBytesThrough
105 * Signature: (J)J
106 */
107 jlong Java_org_rocksdb_RateLimiter_getTotalBytesThrough(JNIEnv* /*env*/,
108 jobject /*jobj*/,
109 jlong handle) {
110 return reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(
111 handle)
112 ->get()
113 ->GetTotalBytesThrough();
114 }
115
116 /*
117 * Class: org_rocksdb_RateLimiter
118 * Method: getTotalRequests
119 * Signature: (J)J
120 */
121 jlong Java_org_rocksdb_RateLimiter_getTotalRequests(JNIEnv* /*env*/,
122 jobject /*jobj*/,
123 jlong handle) {
124 return reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(
125 handle)
126 ->get()
127 ->GetTotalRequests();
128 }