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 * Base class for WAL Filters. 10 */ 11 public abstract class AbstractWalFilter 12 extends RocksCallbackObject implements WalFilter { 13 14 @Override initializeNative(final long... nativeParameterHandles)15 protected long initializeNative(final long... nativeParameterHandles) { 16 return createNewWalFilter(); 17 } 18 19 /** 20 * Called from JNI, proxy for 21 * {@link WalFilter#logRecordFound(long, String, WriteBatch, WriteBatch)}. 22 * 23 * @param logNumber the log handle. 24 * @param logFileName the log file name 25 * @param batchHandle the native handle of a WriteBatch (which we do not own) 26 * @param newBatchHandle the native handle of a 27 * new WriteBatch (which we do not own) 28 * 29 * @return short (2 bytes) where the first byte is the 30 * {@link WalFilter.LogRecordFoundResult#walProcessingOption} 31 * {@link WalFilter.LogRecordFoundResult#batchChanged}. 32 */ logRecordFoundProxy(final long logNumber, final String logFileName, final long batchHandle, final long newBatchHandle)33 private short logRecordFoundProxy(final long logNumber, 34 final String logFileName, final long batchHandle, 35 final long newBatchHandle) { 36 final LogRecordFoundResult logRecordFoundResult = logRecordFound( 37 logNumber, logFileName, new WriteBatch(batchHandle), 38 new WriteBatch(newBatchHandle)); 39 return logRecordFoundResultToShort(logRecordFoundResult); 40 } 41 logRecordFoundResultToShort( final LogRecordFoundResult logRecordFoundResult)42 private static short logRecordFoundResultToShort( 43 final LogRecordFoundResult logRecordFoundResult) { 44 short result = (short)(logRecordFoundResult.walProcessingOption.getValue() << 8); 45 return (short)(result | (logRecordFoundResult.batchChanged ? 1 : 0)); 46 } 47 createNewWalFilter()48 private native long createNewWalFilter(); 49 } 50