org.jrobin.core
Class RrdBackend

java.lang.Object
  extended by org.jrobin.core.RrdBackend
Direct Known Subclasses:
RrdFileBackend, RrdMemoryBackend

public abstract class RrdBackend
extends Object

Base implementation class for all backend classes. Each Round Robin Database object (RrdDb object) is backed with a single RrdBackend object which performs actual I/O operations on the underlying storage. JRobin supports three different bakcends out of the box:

To create your own backend in order to provide some custom type of RRD storage, you should do the following:


Constructor Summary
protected RrdBackend(String path)
          Creates backend for a RRD storage with the given path.
 
Method Summary
 void close()
          Closes the underlying backend.
abstract  long getLength()
          Returns the number of RRD bytes in the underlying storage.
 String getPath()
          Returns path to the storage.
protected  boolean isCachingAllowed()
          This method suggests the caching policy to the JRobin frontend (high-level) classes.
protected abstract  void read(long offset, byte[] b)
          Reads an array of bytes from the underlying storage starting from the given storage offset.
 byte[] readAll()
          Reads all RRD bytes from the underlying storage
protected abstract  void setLength(long length)
          Sets the number of bytes in the underlying RRD storage.
protected abstract  void write(long offset, byte[] b)
          Writes an array of bytes to the underlying storage starting from the given storage offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RrdBackend

protected RrdBackend(String path)
Creates backend for a RRD storage with the given path.

Parameters:
path - String identifying RRD storage. For files on the disk, this argument should represent file path. Other storage types might interpret this argument differently.
Method Detail

getPath

public String getPath()
Returns path to the storage.

Returns:
Storage path

write

protected abstract void write(long offset,
                              byte[] b)
                       throws IOException
Writes an array of bytes to the underlying storage starting from the given storage offset.

Parameters:
offset - Storage offset.
b - Array of bytes that should be copied to the underlying storage
Throws:
IOException - Thrown in case of I/O error

read

protected abstract void read(long offset,
                             byte[] b)
                      throws IOException
Reads an array of bytes from the underlying storage starting from the given storage offset.

Parameters:
offset - Storage offset.
b - Array which receives bytes from the underlying storage
Throws:
IOException - Thrown in case of I/O error

getLength

public abstract long getLength()
                        throws IOException
Returns the number of RRD bytes in the underlying storage.

Returns:
Number of RRD bytes in the storage.
Throws:
IOException - Thrown in case of I/O error.

setLength

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

Parameters:
length - Length of the underlying RRD storage in bytes.
Throws:
IOException - Thrown in case of I/O error.

close

public void close()
           throws IOException
Closes the underlying backend.

Throws:
IOException - Thrown in case of I/O error

isCachingAllowed

protected boolean isCachingAllowed()
This method suggests the caching policy to the JRobin frontend (high-level) classes. If true is returned, frontent classes will cache frequently used parts of a RRD file in memory to improve performance. If false is returned, high level classes will never cache RRD file sections in memory.

Returns:
true if file caching is enabled, false otherwise. By default, the method returns true but it can be overriden in subclasses.

readAll

public final byte[] readAll()
                     throws IOException
Reads all RRD bytes from the underlying storage

Returns:
RRD bytes
Throws:
IOException - Thrown in case of I/O error


Copyright 2003-2008. All Rights Reserved.