1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. 2 // This source code is licensed under both the GPLv2 (found in the 3 // COPYING file in the root directory) and Apache 2.0 License 4 // (found in the LICENSE.Apache file in the root directory). 5 6 package org.rocksdb; 7 8 /** 9 * RocksCallbackObject is similar to {@link RocksObject} but varies 10 * in its construction as it is designed for Java objects which have functions 11 * which are called from C++ via JNI. 12 * 13 * RocksCallbackObject is the base-class any RocksDB classes that acts as a 14 * callback from some underlying underlying native C++ {@code rocksdb} object. 15 * 16 * The use of {@code RocksObject} should always be preferred over 17 * {@link RocksCallbackObject} if callbacks are not required. 18 */ 19 public abstract class RocksCallbackObject extends 20 AbstractImmutableNativeReference { 21 22 protected final long nativeHandle_; 23 RocksCallbackObject(final long... nativeParameterHandles)24 protected RocksCallbackObject(final long... nativeParameterHandles) { 25 super(true); 26 this.nativeHandle_ = initializeNative(nativeParameterHandles); 27 } 28 29 /** 30 * Construct the Native C++ object which will callback 31 * to our object methods 32 * 33 * @param nativeParameterHandles An array of native handles for any parameter 34 * objects that are needed during construction 35 * 36 * @return The native handle of the C++ object which will callback to us 37 */ initializeNative( final long... nativeParameterHandles)38 protected abstract long initializeNative( 39 final long... nativeParameterHandles); 40 41 /** 42 * Deletes underlying C++ native callback object pointer 43 */ 44 @Override disposeInternal()45 protected void disposeInternal() { 46 disposeInternal(nativeHandle_); 47 } 48 disposeInternal(final long handle)49 private native void disposeInternal(final long handle); 50 } 51