]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/java/src/main/java/org/rocksdb/Env.java
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / Env.java
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
7c673cae
FG
5
6package org.rocksdb;
7
494da23a
TL
8import java.util.Arrays;
9import java.util.List;
10
7c673cae
FG
11/**
12 * Base class for all Env implementations in RocksDB.
13 */
14public abstract class Env extends RocksObject {
494da23a 15
f67539c2
TL
16 static {
17 RocksDB.loadLibrary();
18 }
19
494da23a
TL
20 private static final Env DEFAULT_ENV = new RocksEnv(getDefaultEnvInternal());
21 static {
22 /**
23 * The Ownership of the Default Env belongs to C++
24 * and so we disown the native handle here so that
25 * we cannot accidentally free it from Java.
26 */
27 DEFAULT_ENV.disOwnNativeHandle();
28 }
7c673cae
FG
29
30 /**
31 * <p>Returns the default environment suitable for the current operating
32 * system.</p>
33 *
34 * <p>The result of {@code getDefault()} is a singleton whose ownership
35 * belongs to rocksdb c++. As a result, the returned RocksEnv will not
494da23a 36 * have the ownership of its c++ resource, and calling its dispose()/close()
7c673cae
FG
37 * will be no-op.</p>
38 *
39 * @return the default {@link org.rocksdb.RocksEnv} instance.
40 */
41 public static Env getDefault() {
494da23a 42 return DEFAULT_ENV;
7c673cae
FG
43 }
44
45 /**
1e59de90
TL
46 * <p>Sets the number of background worker threads of the low priority
47 * pool for this environment.</p>
7c673cae
FG
48 * <p>Default number: 1</p>
49 *
494da23a 50 * @param number the number of threads
7c673cae
FG
51 *
52 * @return current {@link RocksEnv} instance.
53 */
494da23a
TL
54 public Env setBackgroundThreads(final int number) {
55 return setBackgroundThreads(number, Priority.LOW);
56 }
57
58 /**
59 * <p>Gets the number of background worker threads of the pool
60 * for this environment.</p>
61 *
f67539c2
TL
62 * @param priority the priority id of a specified thread pool.
63 *
494da23a
TL
64 * @return the number of threads.
65 */
66 public int getBackgroundThreads(final Priority priority) {
67 return getBackgroundThreads(nativeHandle_, priority.getValue());
7c673cae
FG
68 }
69
70 /**
71 * <p>Sets the number of background worker threads of the specified thread
72 * pool for this environment.</p>
73 *
494da23a
TL
74 * @param number the number of threads
75 * @param priority the priority id of a specified thread pool.
7c673cae
FG
76 *
77 * <p>Default number: 1</p>
78 * @return current {@link RocksEnv} instance.
79 */
494da23a
TL
80 public Env setBackgroundThreads(final int number, final Priority priority) {
81 setBackgroundThreads(nativeHandle_, number, priority.getValue());
7c673cae
FG
82 return this;
83 }
84
85 /**
86 * <p>Returns the length of the queue associated with the specified
87 * thread pool.</p>
88 *
494da23a 89 * @param priority the priority id of a specified thread pool.
7c673cae
FG
90 *
91 * @return the thread pool queue length.
92 */
494da23a
TL
93 public int getThreadPoolQueueLen(final Priority priority) {
94 return getThreadPoolQueueLen(nativeHandle_, priority.getValue());
7c673cae
FG
95 }
96
494da23a
TL
97 /**
98 * Enlarge number of background worker threads of a specific thread pool
99 * for this environment if it is smaller than specified. 'LOW' is the default
100 * pool.
101 *
102 * @param number the number of threads.
f67539c2 103 * @param priority the priority id of a specified thread pool.
494da23a
TL
104 *
105 * @return current {@link RocksEnv} instance.
106 */
107 public Env incBackgroundThreadsIfNeeded(final int number,
108 final Priority priority) {
109 incBackgroundThreadsIfNeeded(nativeHandle_, number, priority.getValue());
110 return this;
111 }
7c673cae 112
494da23a
TL
113 /**
114 * Lower IO priority for threads from the specified pool.
115 *
116 * @param priority the priority id of a specified thread pool.
f67539c2
TL
117 *
118 * @return current {@link RocksEnv} instance.
494da23a
TL
119 */
120 public Env lowerThreadPoolIOPriority(final Priority priority) {
121 lowerThreadPoolIOPriority(nativeHandle_, priority.getValue());
122 return this;
7c673cae
FG
123 }
124
494da23a
TL
125 /**
126 * Lower CPU priority for threads from the specified pool.
127 *
128 * @param priority the priority id of a specified thread pool.
f67539c2
TL
129 *
130 * @return current {@link RocksEnv} instance.
494da23a
TL
131 */
132 public Env lowerThreadPoolCPUPriority(final Priority priority) {
133 lowerThreadPoolCPUPriority(nativeHandle_, priority.getValue());
134 return this;
7c673cae
FG
135 }
136
137 /**
494da23a
TL
138 * Returns the status of all threads that belong to the current Env.
139 *
140 * @return the status of all threads belong to this env.
f67539c2
TL
141 *
142 * @throws RocksDBException if the thread list cannot be acquired.
7c673cae 143 */
494da23a
TL
144 public List<ThreadStatus> getThreadList() throws RocksDBException {
145 return Arrays.asList(getThreadList(nativeHandle_));
146 }
147
148 Env(final long nativeHandle) {
149 super(nativeHandle);
150 }
7c673cae
FG
151
152 private static native long getDefaultEnvInternal();
153 private native void setBackgroundThreads(
494da23a
TL
154 final long handle, final int number, final byte priority);
155 private native int getBackgroundThreads(final long handle,
156 final byte priority);
157 private native int getThreadPoolQueueLen(final long handle,
158 final byte priority);
159 private native void incBackgroundThreadsIfNeeded(final long handle,
160 final int number, final byte priority);
161 private native void lowerThreadPoolIOPriority(final long handle,
162 final byte priority);
163 private native void lowerThreadPoolCPUPriority(final long handle,
164 final byte priority);
165 private native ThreadStatus[] getThreadList(final long handle)
166 throws RocksDBException;
7c673cae 167}