[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

@@ -16,10 +16,9 @@ package org.rocksdb;
* non-const method, all threads accessing the same Iterator must use
* external synchronization.
*/
public class Iterator {
private long nativeHandle_;
public class Iterator extends RocksObject {
public Iterator(long nativeHandle) {
super();
nativeHandle_ = nativeHandle;
}
@@ -119,22 +118,15 @@ public class Iterator {
/**
* Deletes underlying C++ iterator pointer.
*/
public synchronized void close() {
if(nativeHandle_ != 0) {
close0(nativeHandle_);
@Override public synchronized void dispose() {
if(isInitialized()) {
dispose(nativeHandle_);
nativeHandle_ = 0;
}
}
@Override protected void finalize() {
close();
}
private boolean isInitialized() {
return (nativeHandle_ != 0);
}
private native boolean isValid0(long handle);
private native void close0(long handle);
private native void dispose(long handle);
private native void seekToFirst0(long handle);
private native void seekToLast0(long handle);
private native void next0(long handle);