[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,9 +11,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 ReadOptions {
public class ReadOptions extends RocksObject {
public ReadOptions() {
nativeHandle_ = 0;
super();
newReadOptions();
}
private native void newReadOptions();
@@ -24,7 +24,7 @@ public class ReadOptions {
*
* Calling other methods after dispose() leads to undefined behavior.
*/
public synchronized void dispose() {
@Override public synchronized void dispose() {
if (isInitialized()) {
dispose(nativeHandle_);
}
@@ -127,10 +127,4 @@ public class ReadOptions {
}
private native void setTailing(
long handle, boolean tailing);
protected long nativeHandle_;
private boolean isInitialized() {
return nativeHandle_ != 0;
}
}