[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:
Yueh-Hsuan Chiang
2014-05-01 01:44:46 -07:00
parent 096f5be0ed
commit 61955a0dda
13 changed files with 94 additions and 107 deletions

View File

@@ -11,14 +11,14 @@ package org.rocksdb;
* Note that developers should call WriteOptions.dispose() to release the
* c++ side memory before a WriteOptions instance runs out of scope.
*/
public class WriteOptions {
public class WriteOptions extends RocksObject {
public WriteOptions() {
nativeHandle_ = 0;
super();
newWriteOptions();
}
public synchronized void dispose() {
if (nativeHandle_ != 0) {
@Override public synchronized void dispose() {
if (isInitialized()) {
dispose0(nativeHandle_);
}
}
@@ -91,16 +91,10 @@ public class WriteOptions {
return disableWAL(nativeHandle_);
}
@Override protected void finalize() {
dispose();
}
private native void newWriteOptions();
private native void setSync(long handle, boolean flag);
private native boolean sync(long handle);
private native void setDisableWAL(long handle, boolean flag);
private native boolean disableWAL(long handle);
private native void dispose0(long handle);
protected long nativeHandle_;
}