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.
6 // This file implements the "bridge" between Java and C++ for RateLimiter.
8 #include "rocksjni/portal.h"
9 #include "include/org_rocksdb_RateLimiter.h"
10 #include "rocksdb/rate_limiter.h"
13 * Class: org_rocksdb_RateLimiter
14 * Method: newRateLimiterHandle
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
)));
26 return reinterpret_cast<jlong
>(sptr_rate_limiter
);
30 * Class: org_rocksdb_RateLimiter
31 * Method: disposeInternal
34 void Java_org_rocksdb_RateLimiter_disposeInternal(
35 JNIEnv
* env
, jobject jobj
, jlong jhandle
) {
37 reinterpret_cast<std::shared_ptr
<rocksdb::RateLimiter
> *>(jhandle
);
38 delete handle
; // delete std::shared_ptr
42 * Class: org_rocksdb_RateLimiter
43 * Method: setBytesPerSecond
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
);
54 * Class: org_rocksdb_RateLimiter
58 void Java_org_rocksdb_RateLimiter_request(
59 JNIEnv
* env
, jobject jobj
, jlong handle
,
61 reinterpret_cast<std::shared_ptr
<rocksdb::RateLimiter
> *>(handle
)->get()->
62 Request(jbytes
, rocksdb::Env::IO_TOTAL
);
66 * Class: org_rocksdb_RateLimiter
67 * Method: getSingleBurstBytes
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();
77 * Class: org_rocksdb_RateLimiter
78 * Method: getTotalBytesThrough
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();
88 * Class: org_rocksdb_RateLimiter
89 * Method: getTotalRequests
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();