2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2014-09-20 01:11:59 +02:00
|
|
|
//
|
|
|
|
// This file implements the "bridge" between Java and C++ for RateLimiter.
|
|
|
|
|
2016-10-07 21:32:21 +02:00
|
|
|
#include "include/org_rocksdb_RateLimiter.h"
|
2014-09-20 01:11:59 +02:00
|
|
|
#include "rocksdb/rate_limiter.h"
|
2022-03-01 18:02:15 +01:00
|
|
|
#include "rocksjni/cplusplus_to_java_convert.h"
|
2018-04-13 02:55:14 +02:00
|
|
|
#include "rocksjni/portal.h"
|
2014-09-20 01:11:59 +02:00
|
|
|
|
2016-10-07 21:32:21 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: newRateLimiterHandle
|
2018-01-08 21:20:48 +01:00
|
|
|
* Signature: (JJIBZ)J
|
2016-10-07 21:32:21 +02:00
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_RateLimiter_newRateLimiterHandle(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* /*env*/, jclass /*jclazz*/, jlong jrate_bytes_per_second,
|
2018-01-08 21:20:48 +01:00
|
|
|
jlong jrefill_period_micros, jint jfairness, jbyte jrate_limiter_mode,
|
|
|
|
jboolean jauto_tune) {
|
2018-04-13 02:55:14 +02:00
|
|
|
auto rate_limiter_mode =
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RateLimiterModeJni::toCppRateLimiterMode(
|
|
|
|
jrate_limiter_mode);
|
|
|
|
auto* sptr_rate_limiter = new std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>(
|
|
|
|
ROCKSDB_NAMESPACE::NewGenericRateLimiter(
|
2017-02-28 01:26:12 +01:00
|
|
|
static_cast<int64_t>(jrate_bytes_per_second),
|
|
|
|
static_cast<int64_t>(jrefill_period_micros),
|
2018-04-13 02:55:14 +02:00
|
|
|
static_cast<int32_t>(jfairness), rate_limiter_mode, jauto_tune));
|
2016-10-07 21:32:21 +02:00
|
|
|
|
2022-03-01 18:02:15 +01:00
|
|
|
return GET_CPLUSPLUS_POINTER(sptr_rate_limiter);
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RateLimiter_disposeInternal(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jhandle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* handle =
|
2020-02-20 21:07:53 +01:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(
|
|
|
|
jhandle);
|
2017-02-28 01:26:12 +01:00
|
|
|
delete handle; // delete std::shared_ptr
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: setBytesPerSecond
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RateLimiter_setBytesPerSecond(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle,
|
|
|
|
jlong jbytes_per_second) {
|
2020-02-20 21:07:53 +01:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(handle)
|
2018-04-13 02:55:14 +02:00
|
|
|
->get()
|
|
|
|
->SetBytesPerSecond(jbytes_per_second);
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|
|
|
|
|
2018-01-08 21:20:48 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: getBytesPerSecond
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RateLimiter_getBytesPerSecond(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(
|
|
|
|
handle)
|
2018-04-13 02:55:14 +02:00
|
|
|
->get()
|
|
|
|
->GetBytesPerSecond();
|
2018-01-08 21:20:48 +01:00
|
|
|
}
|
|
|
|
|
2016-10-07 21:32:21 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: request
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RateLimiter_request(JNIEnv* /*env*/, jobject /*jobj*/,
|
|
|
|
jlong handle, jlong jbytes) {
|
2020-02-20 21:07:53 +01:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(handle)
|
2018-04-13 02:55:14 +02:00
|
|
|
->get()
|
2020-02-20 21:07:53 +01:00
|
|
|
->Request(jbytes, ROCKSDB_NAMESPACE::Env::IO_TOTAL);
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: getSingleBurstBytes
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RateLimiter_getSingleBurstBytes(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(
|
|
|
|
handle)
|
2018-04-13 02:55:14 +02:00
|
|
|
->get()
|
|
|
|
->GetSingleBurstBytes();
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: getTotalBytesThrough
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RateLimiter_getTotalBytesThrough(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(
|
|
|
|
handle)
|
2018-04-13 02:55:14 +02:00
|
|
|
->get()
|
|
|
|
->GetTotalBytesThrough();
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: getTotalRequests
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RateLimiter_getTotalRequests(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::RateLimiter>*>(
|
|
|
|
handle)
|
2018-04-13 02:55:14 +02:00
|
|
|
->get()
|
|
|
|
->GetTotalRequests();
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|