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