mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
[Java] Add RocksObject, the base class of all java objects with a c++ pointer.
Summary: Add RocksObject, the base class of all java objects which has a c++ pointer. While the finalizer of a RocksObject will release its c++ resource, it is suggested to call its RocksObject.dispose() to manually release its c++ resource. Existing RocksDB java classes are now extending RocksObject. Test Plan: make rocksdbjava make jtest make jdb_bench Reviewers: haobo, dhruba, sdong, ankgup87, rsumbaly, swapnilghike, zzbennett Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D18411
This commit is contained in:
@@ -18,7 +18,7 @@ import org.rocksdb.util.Environment;
|
||||
* All methods of this class could potentially throw RocksDBException, which
|
||||
* indicates sth wrong at the rocksdb library side and the call failed.
|
||||
*/
|
||||
public class RocksDB {
|
||||
public class RocksDB extends RocksObject {
|
||||
public static final int NOT_FOUND = -1;
|
||||
private static final String[] compressionLibs_ = {
|
||||
"snappy", "zlib", "bzip2", "lz4", "lz4hc"};
|
||||
@@ -114,12 +114,21 @@ public class RocksDB {
|
||||
return db;
|
||||
}
|
||||
|
||||
public synchronized void close() {
|
||||
if (nativeHandle_ != 0) {
|
||||
close0();
|
||||
@Override public synchronized void dispose() {
|
||||
if (isInitialized()) {
|
||||
dispose(nativeHandle_);
|
||||
nativeHandle_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the RocksDB instance.
|
||||
* This function is equivalent to dispose().
|
||||
*/
|
||||
public void close() {
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the database entry for "key" to "value".
|
||||
*
|
||||
@@ -314,7 +323,7 @@ public class RocksDB {
|
||||
* Private constructor.
|
||||
*/
|
||||
protected RocksDB() {
|
||||
nativeHandle_ = 0;
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,8 +370,7 @@ public class RocksDB {
|
||||
long handle, long writeOptHandle,
|
||||
byte[] key, int keyLen) throws RocksDBException;
|
||||
protected native long iterator0(long optHandle);
|
||||
protected native void close0();
|
||||
protected native void dispose(long handle);
|
||||
|
||||
protected long nativeHandle_;
|
||||
protected Filter filter_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user