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  * FlushOptions to be passed to flush operations of
10  * {@link org.rocksdb.RocksDB}.
11  */
12 public class FlushOptions extends RocksObject {
13   static {
RocksDB.loadLibrary()14     RocksDB.loadLibrary();
15   }
16 
17   /**
18    * Construct a new instance of FlushOptions.
19    */
FlushOptions()20   public FlushOptions(){
21     super(newFlushOptions());
22   }
23 
24   /**
25    * Set if the flush operation shall block until it terminates.
26    *
27    * @param waitForFlush boolean value indicating if the flush
28    *     operations waits for termination of the flush process.
29    *
30    * @return instance of current FlushOptions.
31    */
setWaitForFlush(final boolean waitForFlush)32   public FlushOptions setWaitForFlush(final boolean waitForFlush) {
33     assert(isOwningHandle());
34     setWaitForFlush(nativeHandle_, waitForFlush);
35     return this;
36   }
37 
38   /**
39    * Wait for flush to finished.
40    *
41    * @return boolean value indicating if the flush operation
42    *     waits for termination of the flush process.
43    */
waitForFlush()44   public boolean waitForFlush() {
45     assert(isOwningHandle());
46     return waitForFlush(nativeHandle_);
47   }
48 
49   /**
50    * Set to true so that flush would proceeds immediately even it it means
51    * writes will stall for the duration of the flush.
52    *
53    * Set to false so that the operation will wait until it's possible to do
54    * the flush without causing stall or until required flush is performed by
55    * someone else (foreground call or background thread).
56    *
57    * Default: false
58    *
59    * @param allowWriteStall true to allow writes to stall for flush, false
60    *     otherwise.
61    *
62    * @return instance of current FlushOptions.
63    */
setAllowWriteStall(final boolean allowWriteStall)64   public FlushOptions setAllowWriteStall(final boolean allowWriteStall) {
65     assert(isOwningHandle());
66     setAllowWriteStall(nativeHandle_, allowWriteStall);
67     return this;
68   }
69 
70   /**
71    * Returns true if writes are allowed to stall for flushes to complete, false
72    * otherwise.
73    *
74    * @return true if writes are allowed to stall for flushes
75    */
allowWriteStall()76   public boolean allowWriteStall() {
77     assert(isOwningHandle());
78     return allowWriteStall(nativeHandle_);
79   }
80 
newFlushOptions()81   private native static long newFlushOptions();
disposeInternal(final long handle)82   @Override protected final native void disposeInternal(final long handle);
83 
setWaitForFlush(final long handle, final boolean wait)84   private native void setWaitForFlush(final long handle,
85       final boolean wait);
waitForFlush(final long handle)86   private native boolean waitForFlush(final long handle);
setAllowWriteStall(final long handle, final boolean allowWriteStall)87   private native void setAllowWriteStall(final long handle,
88       final boolean allowWriteStall);
allowWriteStall(final long handle)89   private native boolean allowWriteStall(final long handle);
90 }
91