RrdBackend
Keywords: org.jrobin.core.RrdBackend class

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jrobin.core
Class RrdBackend

    java.lang.Object
      org.jrobin.core.RrdBackend

Direct Known Subclasses:
  RrdFileBackend, RrdMemoryBackend

public abstract class RrdBackend
extends java.lang.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:

- `RrdFileBackend`: objects of this class are created from the `RrdFileBackendFactory` class. This was the default backend used in all JRobin releases prior to 1.4.0. It uses java.io.* package and RandomAccessFile class to store RRD data in files on the disk.
- `RrdNioBackend`: objects of this class are created from the `RrdNioBackendFactory` class. The backend uses java.io.* and java.nio.* classes (mapped ByteBuffer) to store RRD data in files on the disk. This backend is fast, very fast, but consumes a lot of memory (borrowed not from the JVM but from the underlying operating system directly). This is the default backend used in JRobin since 1.4.0 release.
- `RrdMemoryBackend`: objects of this class are created from the `RrdMemoryBackendFactory` class. This backend stores all data in memory. Once JVM exits, all data gets lost. The backend is extremely fast and memory hungry.

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

- Create your custom RrdBackend class (RrdCustomBackend, for example) by extending RrdBackend class. You have to implement all abstract methods defined in the base class.
- Create your custom RrdBackendFactory class (RrdCustomBackendFactory, for example) by extending RrdBackendFactory class. You have to implement all abstract methods defined in the base class. Your custom factory class will actually create custom backend objects when necessary.
- Create instance of your custom RrdBackendFactory and register it as a regular factory available to JRobin framework. See javadoc for `RrdBackendFactory` to find out how to do this

Constructor Summary
`protected` | `RrdBackend(java.lang.String path)` Creates backend for a RRD storage with the given path.

Method Summary
`protected void` | `afterCreate()` Method called by the framework immediatelly after RrdDb obejct is created.
`protected void` | `afterFetch()` Method called by the framework immediatelly after RRD fetch operation is completed.
`protected void` | `afterUpdate()` Method called by the framework immediatelly after RRD update operation is completed.
`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 storage.
`abstract long` | `getLength()` Returns the number of RRD bytes in the underlying storage.
`java.lang.String` | `getPath()` Returns path to the storage.
`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.
`void` | `sync()` This method forces all data cached in memory but not yet stored in the persistant storage, to be stored in it.
`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(java.lang.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 java.lang.String getPath()

  Returns path to the storage.

  Returns:
    Storage path

### write

    protected abstract void write(long offset,
                                  byte[] b)
                           throws java.io.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:
    `java.io.IOException` - Thrown in case of I/O error

### read

    protected abstract void read(long offset,
                                 byte[] b)
                          throws java.io.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:
    `java.io.IOException` - Thrown in case of I/O error

### readAll

    public final byte[] readAll()
                         throws java.io.IOException

  Reads all RRD bytes from the underlying storage

  Returns:
    RRD bytes
  Throws:
    `java.io.IOException` - Thrown in case of I/O error

### getLength

    public abstract long getLength()
                            throws java.io.IOException

  Returns the number of RRD bytes in the underlying storage.

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

### setLength

    protected abstract void setLength(long length)
                               throws java.io.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:
    `java.io.IOException` - Thrown in case of I/O error.

### close

    public void close()
               throws java.io.IOException

  Closes the underlying storage. Calls sync() implicitly. In other words, you don't have to call sync() before close() in order to preserve data cached in memory.

  Throws:
    `java.io.IOException` - Thrown in case of I/O error

### beforeUpdate

    protected void beforeUpdate()
                         throws java.io.IOException

  Method called by the framework immediatelly before RRD update operation starts. This method does nothing, but can be overriden in subclasses.

  Throws:
    `java.io.IOException`

### afterUpdate

    protected void afterUpdate()
                        throws java.io.IOException

  Method called by the framework immediatelly after RRD update operation is completed. This method does nothing, but can be overriden in subclasses.

  Throws:
    `java.io.IOException`

### beforeFetch

    protected void beforeFetch()
                        throws java.io.IOException

  Method called by the framework immediatelly before RRD fetch operation starts. This method does nothing, but can be overriden in subclasses.

  Throws:
    `java.io.IOException`

### afterFetch

    protected void afterFetch()
                       throws java.io.IOException

  Method called by the framework immediatelly after RRD fetch operation is completed. This method does nothing, but can be overriden in subclasses.

  Throws:
    `java.io.IOException`

### afterCreate

    protected void afterCreate()
                        throws java.io.IOException

  Method called by the framework immediatelly after RrdDb obejct is created. This method does nothing, but can be overriden in subclasses.

  Throws:
    `java.io.IOException`

### sync

    public void sync()
              throws java.io.IOException

  This method forces all data cached in memory but not yet stored in the persistant storage, to be stored in it. In the base class this method does nothing but subclasses might provide real functionality.

  Throws:
    `java.io.IOException` - Thrown in case of I/O error

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD