mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +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:
@@ -12,8 +12,9 @@ package org.rocksdb;
|
||||
* Note that dispose() must be called before an Options instance
|
||||
* become out-of-scope to release the allocated memory in c++.
|
||||
*/
|
||||
public class BackupableDBOptions {
|
||||
public class BackupableDBOptions extends RocksObject {
|
||||
public BackupableDBOptions(String path) {
|
||||
super();
|
||||
newBackupableDBOptions(path);
|
||||
}
|
||||
|
||||
@@ -31,22 +32,13 @@ public class BackupableDBOptions {
|
||||
* Release the memory allocated for the current instance
|
||||
* in the c++ side.
|
||||
*/
|
||||
public synchronized void dispose() {
|
||||
@Override public synchronized void dispose() {
|
||||
if (isInitialized()) {
|
||||
dispose(nativeHandle_);
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void finalize() {
|
||||
dispose();
|
||||
}
|
||||
|
||||
boolean isInitialized() {
|
||||
return nativeHandle_ != 0;
|
||||
}
|
||||
|
||||
private native void newBackupableDBOptions(String path);
|
||||
private native String backupDir(long handle);
|
||||
private native void dispose(long handle);
|
||||
long nativeHandle_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user