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 * Provides notification to the caller of SetSnapshotOnNextOperation when 10 * the actual snapshot gets created 11 */ 12 public abstract class AbstractTransactionNotifier 13 extends RocksCallbackObject { 14 AbstractTransactionNotifier()15 protected AbstractTransactionNotifier() { 16 super(); 17 } 18 19 /** 20 * Implement this method to receive notification when a snapshot is 21 * requested via {@link Transaction#setSnapshotOnNextOperation()}. 22 * 23 * @param newSnapshot the snapshot that has been created. 24 */ snapshotCreated(final Snapshot newSnapshot)25 public abstract void snapshotCreated(final Snapshot newSnapshot); 26 27 /** 28 * This is intentionally private as it is the callback hook 29 * from JNI 30 */ snapshotCreated(final long snapshotHandle)31 private void snapshotCreated(final long snapshotHandle) { 32 snapshotCreated(new Snapshot(snapshotHandle)); 33 } 34 35 @Override initializeNative(final long... nativeParameterHandles)36 protected long initializeNative(final long... nativeParameterHandles) { 37 return createNewTransactionNotifier(); 38 } 39 createNewTransactionNotifier()40 private native long createNewTransactionNotifier(); 41 42 /** 43 * Deletes underlying C++ TransactionNotifier pointer. 44 * 45 * Note that this function should be called only after all 46 * Transactions referencing the comparator are closed. 47 * Otherwise an undefined behavior will occur. 48 */ 49 @Override disposeInternal()50 protected void disposeInternal() { 51 disposeInternal(nativeHandle_); 52 } disposeInternal(final long handle)53 protected final native void disposeInternal(final long handle); 54 } 55