org.jrobin.core
Class RrdNioBackend

java.lang.Object
  extended by org.jrobin.core.RrdBackend
      extended by org.jrobin.core.RrdFileBackend
          extended by org.jrobin.core.RrdNioBackend

public class RrdNioBackend
extends RrdFileBackend

JRobin backend which is used to store RRD data to ordinary disk files by using fast java.nio.* package. This is the default backend engine since JRobin 1.4.0.


Field Summary
static boolean SHOULD_GC
          Defines System.gc() usage policy for this backend.
 
Fields inherited from class org.jrobin.core.RrdFileBackend
channel, file, fileLock
 
Constructor Summary
protected RrdNioBackend(String path, boolean readOnly, int lockMode, int syncMode, int syncPeriod)
           
 
Method Summary
protected  void afterFetch()
          Method called by the framework immediatelly after RRD fetch operation finishes.
protected  void afterUpdate()
          Method called by the framework immediatelly after RRD update operation finishes.
protected  void beforeFetch()
          Method called by the framework immediatelly before RRD fetch operation starts.
protected  void beforeUpdate()
          Method called by the framework immediatelly before RRD update operation starts.
 void close()
          Closes the underlying RRD file.
protected  void read(long offset, byte[] b)
          Reads a number of bytes from the RRD file on the disk
protected  void setLength(long newLength)
          Sets length of the underlying RRD file.
 void sync()
          This method forces all data cached in memory but not yet stored in the file, to be stored in it.
protected  void write(long offset, byte[] b)
          Writes bytes to the underlying RRD file on the disk
 
Methods inherited from class org.jrobin.core.RrdFileBackend
finalize, getCanonicalPath, getCanonicalPath, getLength
 
Methods inherited from class org.jrobin.core.RrdBackend
afterCreate, getPath, readAll
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHOULD_GC

public static final boolean SHOULD_GC
Defines System.gc() usage policy for this backend.

NIO backend uses potentially large in-memory buffer to cache file data. The buffer remains 'active' (by prohibiting file re-creation with the smaller file size) as long as it is not garbage-collected. By forcing System.gc() call where appropriate, this backend will free in-memory buffers sooner and file re-creation won't fail.

The constant is set to true initially and currently there is no API to change it during runtime. Garbage collection will be forced only in some special circumstances. It should not affect the speed of your application significantly.

See Also:
Constant Field Values
Constructor Detail

RrdNioBackend

protected RrdNioBackend(String path,
                        boolean readOnly,
                        int lockMode,
                        int syncMode,
                        int syncPeriod)
                 throws IOException
Throws:
IOException
Method Detail

setLength

protected void setLength(long newLength)
                  throws IOException
Sets length of the underlying RRD file. This method is called only once, immediately after a new RRD file gets created.

Overrides:
setLength in class RrdFileBackend
Parameters:
newLength - Length of the RRD file
Throws:
IOException - Thrown in case of I/O error.

write

protected void write(long offset,
                     byte[] b)
Writes bytes to the underlying RRD file on the disk

Overrides:
write in class RrdFileBackend
Parameters:
offset - Starting file offset
b - Bytes to be written.

read

protected void read(long offset,
                    byte[] b)
Reads a number of bytes from the RRD file on the disk

Overrides:
read in class RrdFileBackend
Parameters:
offset - Starting file offset
b - Buffer which receives bytes read from the file.

close

public void close()
           throws IOException
Closes the underlying RRD file.

Overrides:
close in class RrdFileBackend
Throws:
IOException - Thrown in case of I/O error

sync

public void sync()
This method forces all data cached in memory but not yet stored in the file, to be stored in it. RrdNioBackend uses (a lot of) memory to cache I/O data. This method is automatically invoked when the close() method is called. In other words, you don't have to call sync() before you call close().

Overrides:
sync in class RrdBackend

beforeUpdate

protected void beforeUpdate()
Method called by the framework immediatelly before RRD update operation starts. This method will synchronize in-memory cache with the disk content if synchronization mode is set to RrdNioBackendFactory.SYNC_BEFOREUPDATE. Otherwise it does nothing.

Overrides:
beforeUpdate in class RrdBackend

afterUpdate

protected void afterUpdate()
Method called by the framework immediatelly after RRD update operation finishes. This method will synchronize in-memory cache with the disk content if synchronization mode is set to RrdNioBackendFactory.SYNC_AFTERUPDATE. Otherwise it does nothing.

Overrides:
afterUpdate in class RrdBackend

beforeFetch

protected void beforeFetch()
Method called by the framework immediatelly before RRD fetch operation starts. This method will synchronize in-memory cache with the disk content if synchronization mode is set to RrdNioBackendFactory.SYNC_BEFOREFETCH. Otherwise it does nothing.

Overrides:
beforeFetch in class RrdBackend

afterFetch

protected void afterFetch()
Method called by the framework immediatelly after RRD fetch operation finishes. This method will synchronize in-memory cache with the disk content if synchronization mode is set to RrdNioBackendFactory.SYNC_AFTERFETCH. Otherwise it does nothing.

Overrides:
afterFetch in class RrdBackend