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.
|
|
|
|
|
|
|
|
#include "rocksjni/portal.h"
|
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"
|
|
|
|
|
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(
|
|
|
|
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) {
|
|
|
|
auto rate_limiter_mode = rocksdb::RateLimiterModeJni::toCppRateLimiterMode(
|
|
|
|
jrate_limiter_mode);
|
2017-02-28 01:26:12 +01:00
|
|
|
auto * sptr_rate_limiter =
|
|
|
|
new std::shared_ptr<rocksdb::RateLimiter>(rocksdb::NewGenericRateLimiter(
|
|
|
|
static_cast<int64_t>(jrate_bytes_per_second),
|
|
|
|
static_cast<int64_t>(jrefill_period_micros),
|
2018-01-08 21:20:48 +01:00
|
|
|
static_cast<int32_t>(jfairness),
|
|
|
|
rate_limiter_mode,
|
|
|
|
jauto_tune));
|
2016-10-07 21:32:21 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
return reinterpret_cast<jlong>(sptr_rate_limiter);
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RateLimiter_disposeInternal(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* handle =
|
2016-10-07 21:32:21 +02:00
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::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
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RateLimiter_setBytesPerSecond(
|
|
|
|
JNIEnv* env, jobject jobj, jlong handle,
|
|
|
|
jlong jbytes_per_second) {
|
2017-02-28 01:26:12 +01:00
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(handle)->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
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_RateLimiter_getBytesPerSecond(
|
|
|
|
JNIEnv* env, jobject jobj, jlong handle) {
|
|
|
|
return reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(handle)->get()->
|
|
|
|
GetBytesPerSecond();
|
|
|
|
}
|
|
|
|
|
2016-10-07 21:32:21 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: request
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RateLimiter_request(
|
|
|
|
JNIEnv* env, jobject jobj, jlong handle,
|
|
|
|
jlong jbytes) {
|
2017-02-28 01:26:12 +01:00
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(handle)->get()->
|
|
|
|
Request(jbytes, rocksdb::Env::IO_TOTAL);
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: getSingleBurstBytes
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_RateLimiter_getSingleBurstBytes(
|
2017-02-28 01:26:12 +01:00
|
|
|
JNIEnv* env, jobject jobj, jlong handle) {
|
|
|
|
return reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(handle)->
|
|
|
|
get()->GetSingleBurstBytes();
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: getTotalBytesThrough
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_RateLimiter_getTotalBytesThrough(
|
2017-02-28 01:26:12 +01:00
|
|
|
JNIEnv* env, jobject jobj, jlong handle) {
|
|
|
|
return reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(handle)->
|
|
|
|
get()->GetTotalBytesThrough();
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RateLimiter
|
|
|
|
* Method: getTotalRequests
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_RateLimiter_getTotalRequests(
|
2017-02-28 01:26:12 +01:00
|
|
|
JNIEnv* env, jobject jobj, jlong handle) {
|
|
|
|
return reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(handle)->
|
|
|
|
get()->GetTotalRequests();
|
2016-10-07 21:32:21 +02:00
|
|
|
}
|