summaryrefslogtreecommitdiffstats
path: root/src/rocksdb/java/rocksjni/concurrent_task_limiter.cc
blob: 0b0b2d27172b444f30553d05389287795431aff7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//  Copyright (c) Meta Platforms, Inc. and affiliates.
//
//  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).

#include "rocksdb/concurrent_task_limiter.h"

#include <jni.h>

#include <memory>
#include <string>

#include "include/org_rocksdb_ConcurrentTaskLimiterImpl.h"
#include "rocksjni/cplusplus_to_java_convert.h"
#include "rocksjni/portal.h"

/*
 * Class:     org_rocksdb_ConcurrentTaskLimiterImpl
 * Method:    newConcurrentTaskLimiterImpl0
 * Signature: (Ljava/lang/String;I)J
 */
jlong Java_org_rocksdb_ConcurrentTaskLimiterImpl_newConcurrentTaskLimiterImpl0(
    JNIEnv* env, jclass, jstring jname, jint limit) {
  jboolean has_exception = JNI_FALSE;
  std::string name =
      ROCKSDB_NAMESPACE::JniUtil::copyStdString(env, jname, &has_exception);
  if (JNI_TRUE == has_exception) {
    return 0;
  }

  auto* ptr = new std::shared_ptr<ROCKSDB_NAMESPACE::ConcurrentTaskLimiter>(
      ROCKSDB_NAMESPACE::NewConcurrentTaskLimiter(name, limit));

  return GET_CPLUSPLUS_POINTER(ptr);
}

/*
 * Class:     org_rocksdb_ConcurrentTaskLimiterImpl
 * Method:    name
 * Signature: (J)Ljava/lang/String;
 */
jstring Java_org_rocksdb_ConcurrentTaskLimiterImpl_name(JNIEnv* env, jclass,
                                                        jlong handle) {
  const auto& limiter = *reinterpret_cast<
      std::shared_ptr<ROCKSDB_NAMESPACE::ConcurrentTaskLimiter>*>(handle);
  return ROCKSDB_NAMESPACE::JniUtil::toJavaString(env, &limiter->GetName());
}

/*
 * Class:     org_rocksdb_ConcurrentTaskLimiterImpl
 * Method:    setMaxOutstandingTask
 * Signature: (JI)V
 */
void Java_org_rocksdb_ConcurrentTaskLimiterImpl_setMaxOutstandingTask(
    JNIEnv*, jclass, jlong handle, jint max_outstanding_task) {
  const auto& limiter = *reinterpret_cast<
      std::shared_ptr<ROCKSDB_NAMESPACE::ConcurrentTaskLimiter>*>(handle);
  limiter->SetMaxOutstandingTask(static_cast<int32_t>(max_outstanding_task));
}

/*
 * Class:     org_rocksdb_ConcurrentTaskLimiterImpl
 * Method:    resetMaxOutstandingTask
 * Signature: (J)V
 */
void Java_org_rocksdb_ConcurrentTaskLimiterImpl_resetMaxOutstandingTask(
    JNIEnv*, jclass, jlong handle) {
  const auto& limiter = *reinterpret_cast<
      std::shared_ptr<ROCKSDB_NAMESPACE::ConcurrentTaskLimiter>*>(handle);
  limiter->ResetMaxOutstandingTask();
}

/*
 * Class:     org_rocksdb_ConcurrentTaskLimiterImpl
 * Method:    outstandingTask
 * Signature: (J)I
 */
jint Java_org_rocksdb_ConcurrentTaskLimiterImpl_outstandingTask(JNIEnv*, jclass,
                                                                jlong handle) {
  const auto& limiter = *reinterpret_cast<
      std::shared_ptr<ROCKSDB_NAMESPACE::ConcurrentTaskLimiter>*>(handle);
  return static_cast<jint>(limiter->GetOutstandingTask());
}

/*
 * Class:     org_rocksdb_ConcurrentTaskLimiterImpl
 * Method:    disposeInternal
 * Signature: (J)V
 */
void Java_org_rocksdb_ConcurrentTaskLimiterImpl_disposeInternal(JNIEnv*,
                                                                jobject,
                                                                jlong jhandle) {
  auto* ptr = reinterpret_cast<
      std::shared_ptr<ROCKSDB_NAMESPACE::ConcurrentTaskLimiter>*>(jhandle);
  delete ptr;  // delete std::shared_ptr
}