]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/rocksjni/ratelimiterjni.cc
add subtree-ish sources for 12.0.3
[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 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++ for RateLimiter.
7
8 #include "rocksjni/portal.h"
9 #include "include/org_rocksdb_RateLimiter.h"
10 #include "rocksdb/rate_limiter.h"
11
12 /*
13 * Class: org_rocksdb_RateLimiter
14 * Method: newRateLimiterHandle
15 * Signature: (JJI)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) {
20 auto * sptr_rate_limiter =
21 new std::shared_ptr<rocksdb::RateLimiter>(rocksdb::NewGenericRateLimiter(
22 static_cast<int64_t>(jrate_bytes_per_second),
23 static_cast<int64_t>(jrefill_period_micros),
24 static_cast<int32_t>(jfairness)));
25
26 return reinterpret_cast<jlong>(sptr_rate_limiter);
27 }
28
29 /*
30 * Class: org_rocksdb_RateLimiter
31 * Method: disposeInternal
32 * Signature: (J)V
33 */
34 void Java_org_rocksdb_RateLimiter_disposeInternal(
35 JNIEnv* env, jobject jobj, jlong jhandle) {
36 auto* handle =
37 reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(jhandle);
38 delete handle; // delete std::shared_ptr
39 }
40
41 /*
42 * Class: org_rocksdb_RateLimiter
43 * Method: setBytesPerSecond
44 * Signature: (JJ)V
45 */
46 void Java_org_rocksdb_RateLimiter_setBytesPerSecond(
47 JNIEnv* env, jobject jobj, jlong handle,
48 jlong jbytes_per_second) {
49 reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(handle)->get()->
50 SetBytesPerSecond(jbytes_per_second);
51 }
52
53 /*
54 * Class: org_rocksdb_RateLimiter
55 * Method: request
56 * Signature: (JJ)V
57 */
58 void Java_org_rocksdb_RateLimiter_request(
59 JNIEnv* env, jobject jobj, jlong handle,
60 jlong jbytes) {
61 reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(handle)->get()->
62 Request(jbytes, rocksdb::Env::IO_TOTAL);
63 }
64
65 /*
66 * Class: org_rocksdb_RateLimiter
67 * Method: getSingleBurstBytes
68 * Signature: (J)J
69 */
70 jlong Java_org_rocksdb_RateLimiter_getSingleBurstBytes(
71 JNIEnv* env, jobject jobj, jlong handle) {
72 return reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(handle)->
73 get()->GetSingleBurstBytes();
74 }
75
76 /*
77 * Class: org_rocksdb_RateLimiter
78 * Method: getTotalBytesThrough
79 * Signature: (J)J
80 */
81 jlong Java_org_rocksdb_RateLimiter_getTotalBytesThrough(
82 JNIEnv* env, jobject jobj, jlong handle) {
83 return reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(handle)->
84 get()->GetTotalBytesThrough();
85 }
86
87 /*
88 * Class: org_rocksdb_RateLimiter
89 * Method: getTotalRequests
90 * Signature: (J)J
91 */
92 jlong Java_org_rocksdb_RateLimiter_getTotalRequests(
93 JNIEnv* env, jobject jobj, jlong handle) {
94 return reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(handle)->
95 get()->GetTotalRequests();
96 }