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  * RocksObject is an implementation of {@link AbstractNativeReference} which
10  * has an immutable and therefore thread-safe reference to the underlying
11  * native C++ RocksDB object.
12  * <p>
13  * RocksObject is the base-class of almost all RocksDB classes that have a
14  * pointer to some underlying native C++ {@code rocksdb} object.</p>
15  * <p>
16  * The use of {@code RocksObject} should always be preferred over
17  * {@link RocksMutableObject}.</p>
18  */
19 public abstract class RocksObject extends AbstractImmutableNativeReference {
20 
21   /**
22    * An immutable reference to the value of the C++ pointer pointing to some
23    * underlying native RocksDB C++ object.
24    */
25   protected final long nativeHandle_;
26 
RocksObject(final long nativeHandle)27   protected RocksObject(final long nativeHandle) {
28     super(true);
29     this.nativeHandle_ = nativeHandle;
30   }
31 
32   /**
33    * Deletes underlying C++ object pointer.
34    */
35   @Override
disposeInternal()36   protected void disposeInternal() {
37     disposeInternal(nativeHandle_);
38   }
39 
disposeInternal(final long handle)40   protected abstract void disposeInternal(final long handle);
41 }
42