org.jrobin.core
Class RrdSafeFileBackend

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

public class RrdSafeFileBackend
extends RrdFileBackend

JRobin backend which is used to store RRD data to ordinary files on the disk. This backend is SAFE: it locks the underlying RRD file during update/fetch operations, and caches only static parts of a RRD file in memory. Therefore, this backend is safe to be used when RRD files should be shared between several JVMs at the same time. However, this backend is *slow* since it does not use fast java.nio.* package (it's still based on the RandomAccessFile class).


Field Summary
static int LOCK_RETRY_COUNT
          Number of locking retries.
static int LOCK_RETRY_DELAY
          Number of milliseconds between locking retries
 
Fields inherited from class org.jrobin.core.RrdFileBackend
file, fileLock, lockMode, readOnly
 
Constructor Summary
RrdSafeFileBackend(java.lang.String path, boolean readOnly, int lockMode)
          Creates RrdFileBackend object for the given file path, backed by RandomAccessFile object.
 
Method Summary
protected  void afterFetch()
          Unlocks the underlying RRD file just after the RRD fetch operation.
protected  void afterUpdate()
          Unlocks the underlying RRD file just after the RRD update operation.
protected  void beforeClose()
          Releases the file lock before closing the RRD file (if not already released).
protected  void beforeFetch()
          Locks the underlying RRD file just before the next RRD fetch operation.
protected  void beforeUpdate()
          Locks the underlying RRD file just before the next RRD update operation.
protected  boolean isCachingAllowed()
          Defines the caching policy for this backend.
 
Methods inherited from class org.jrobin.core.RrdFileBackend
close, getCanonicalPath, getCanonicalPath, getLength, read, setLength, write
 
Methods inherited from class org.jrobin.core.RrdBackend
afterCreate, getPath, readAll, sync
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCK_RETRY_COUNT

public static final int LOCK_RETRY_COUNT
Number of locking retries. This backend will not give up if the first locking request fails.

See Also:
Constant Field Values

LOCK_RETRY_DELAY

public static final int LOCK_RETRY_DELAY
Number of milliseconds between locking retries

See Also:
Constant Field Values
Constructor Detail

RrdSafeFileBackend

public RrdSafeFileBackend(java.lang.String path,
                          boolean readOnly,
                          int lockMode)
                   throws java.io.IOException
Creates RrdFileBackend object for the given file path, backed by RandomAccessFile object.

Parameters:
path - Path to a file
readOnly - True, if file should be open in a read-only mode. False otherwise
lockMode - Ignored, since this backend implements its own locking mechanism
Throws:
java.io.IOException - Thrown in case of I/O error
Method Detail

isCachingAllowed

protected boolean isCachingAllowed()
Defines the caching policy for this backend.

Overrides:
isCachingAllowed in class RrdBackend
Returns:
false

beforeUpdate

protected void beforeUpdate()
                     throws java.io.IOException
Locks the underlying RRD file just before the next RRD update operation.

Overrides:
beforeUpdate in class RrdBackend
Throws:
java.io.IOException - Thrown if the file lock could not be obtained.

afterUpdate

protected void afterUpdate()
                    throws java.io.IOException
Unlocks the underlying RRD file just after the RRD update operation.

Overrides:
afterUpdate in class RrdBackend
Throws:
java.io.IOException - Thrown if the lock could not be released.

beforeFetch

protected void beforeFetch()
                    throws java.io.IOException
Locks the underlying RRD file just before the next RRD fetch operation.

Overrides:
beforeFetch in class RrdBackend
Throws:
java.io.IOException - Thrown if the file lock could not be obtained.

afterFetch

protected void afterFetch()
                   throws java.io.IOException
Unlocks the underlying RRD file just after the RRD fetch operation.

Overrides:
afterFetch in class RrdBackend
Throws:
java.io.IOException - Thrown if the lock could not be released.

beforeClose

protected void beforeClose()
                    throws java.io.IOException
Releases the file lock before closing the RRD file (if not already released).

Overrides:
beforeClose in class RrdBackend
Throws:
java.io.IOException - Thrown if the lock could not be released.