]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/Env.java
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / Env.java
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5
6 package org.rocksdb;
7
8 /**
9 * Base class for all Env implementations in RocksDB.
10 */
11 public abstract class Env extends RocksObject {
12 public static final int FLUSH_POOL = 0;
13 public static final int COMPACTION_POOL = 1;
14
15 /**
16 * <p>Returns the default environment suitable for the current operating
17 * system.</p>
18 *
19 * <p>The result of {@code getDefault()} is a singleton whose ownership
20 * belongs to rocksdb c++. As a result, the returned RocksEnv will not
21 * have the ownership of its c++ resource, and calling its dispose()
22 * will be no-op.</p>
23 *
24 * @return the default {@link org.rocksdb.RocksEnv} instance.
25 */
26 public static Env getDefault() {
27 return default_env_;
28 }
29
30 /**
31 * <p>Sets the number of background worker threads of the flush pool
32 * for this environment.</p>
33 * <p>Default number: 1</p>
34 *
35 * @param num the number of threads
36 *
37 * @return current {@link RocksEnv} instance.
38 */
39 public Env setBackgroundThreads(final int num) {
40 return setBackgroundThreads(num, FLUSH_POOL);
41 }
42
43 /**
44 * <p>Sets the number of background worker threads of the specified thread
45 * pool for this environment.</p>
46 *
47 * @param num the number of threads
48 * @param poolID the id to specified a thread pool. Should be either
49 * FLUSH_POOL or COMPACTION_POOL.
50 *
51 * <p>Default number: 1</p>
52 * @return current {@link RocksEnv} instance.
53 */
54 public Env setBackgroundThreads(final int num, final int poolID) {
55 setBackgroundThreads(nativeHandle_, num, poolID);
56 return this;
57 }
58
59 /**
60 * <p>Returns the length of the queue associated with the specified
61 * thread pool.</p>
62 *
63 * @param poolID the id to specified a thread pool. Should be either
64 * FLUSH_POOL or COMPACTION_POOL.
65 *
66 * @return the thread pool queue length.
67 */
68 public int getThreadPoolQueueLen(final int poolID) {
69 return getThreadPoolQueueLen(nativeHandle_, poolID);
70 }
71
72
73 protected Env(final long nativeHandle) {
74 super(nativeHandle);
75 }
76
77 static {
78 default_env_ = new RocksEnv(getDefaultEnvInternal());
79 }
80
81 /**
82 * <p>The static default Env. The ownership of its native handle
83 * belongs to rocksdb c++ and is not able to be released on the Java
84 * side.</p>
85 */
86 static Env default_env_;
87
88 private static native long getDefaultEnvInternal();
89 private native void setBackgroundThreads(
90 long handle, int num, int priority);
91 private native int getThreadPoolQueueLen(long handle, int poolID);
92 }