]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/RocksMutableObject.java
1 // Copyright (c) 2016, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
9 * RocksMutableObject is an implementation of {@link AbstractNativeReference}
10 * whose reference to the underlying native C++ object can change.
12 * <p>The use of {@code RocksMutableObject} should be kept to a minimum, as it
13 * has synchronization overheads and introduces complexity. Instead it is
14 * recommended to use {@link RocksObject} where possible.</p>
16 public abstract class RocksMutableObject
extends AbstractNativeReference
{
19 * An mutable reference to the value of the C++ pointer pointing to some
20 * underlying native RocksDB C++ object.
22 private long nativeHandle_
;
23 private boolean owningHandle_
;
25 protected RocksMutableObject() {
28 protected RocksMutableObject(final long nativeHandle
) {
29 this.nativeHandle_
= nativeHandle
;
30 this.owningHandle_
= true;
34 * Closes the existing handle, and changes the handle to the new handle
36 * @param newNativeHandle The C++ pointer to the new native object
37 * @param owningNativeHandle true if we own the new native object
39 public synchronized void resetNativeHandle(final long newNativeHandle
,
40 final boolean owningNativeHandle
) {
42 setNativeHandle(newNativeHandle
, owningNativeHandle
);
46 * Sets the handle (C++ pointer) of the underlying C++ native object
48 * @param nativeHandle The C++ pointer to the native object
49 * @param owningNativeHandle true if we own the native object
51 public synchronized void setNativeHandle(final long nativeHandle
,
52 final boolean owningNativeHandle
) {
53 this.nativeHandle_
= nativeHandle
;
54 this.owningHandle_
= owningNativeHandle
;
58 protected synchronized boolean isOwningHandle() {
59 return this.owningHandle_
;
63 * Gets the value of the C++ pointer pointing to the underlying
66 * @return the pointer value for the native object
68 protected synchronized long getNativeHandle() {
69 assert (this.nativeHandle_
!= 0);
70 return this.nativeHandle_
;
74 public synchronized final void close() {
75 if (isOwningHandle()) {
77 this.owningHandle_
= false;
78 this.nativeHandle_
= 0;
82 protected void disposeInternal() {
83 disposeInternal(nativeHandle_
);
86 protected abstract void disposeInternal(final long handle
);