2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2014-09-20 01:11:59 +02:00
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
* Signature: (JJI)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_RateLimiter_newRateLimiterHandle(
|
|
|
|
JNIEnv* env, jclass jclazz, jlong jrate_bytes_per_second,
|
|
|
|
jlong jrefill_period_micros, jint jfairness) {
|
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),
|
|
|
|
static_cast<int32_t>(jfairness)));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
}
|