Class JDBMSpace<K,V>

java.lang.Object
java.util.TimerTask
org.jpos.space.JDBMSpace<K,V>
All Implemented Interfaces:
AutoCloseable, Runnable, PersistentSpace, Space<K,V>

public class JDBMSpace<K,V> extends TimerTask implements Space<K,V>, PersistentSpace
JDBM based persistent space implementation
Since:
1.4.7
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
     
    static final long
     
    protected jdbm.htree.HTree
     
    protected String
     
    protected jdbm.RecordManager
     
    protected static final jdbm.helper.Serializer
     
    protected static final Map<String,Space>
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    JDBMSpace(String name, String filename)
    protected constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    close this space - use with care
    void
    force commit
    boolean
    existAny(Object[] keys)
     
    boolean
    existAny(Object[] keys, long timeout)
     
    void
    gc()
    garbage collector.
     
    static JDBMSpace
     
    static JDBMSpace
    creates a named JDBMSpace (filename used for storage is the same as the given name)
    static JDBMSpace
    getSpace(String name, String filename)
    creates a named JDBMSpace
    in(Object key)
    Take an entry from the space, waiting forever until one exists.
    in(Object key, long timeout)
    Take an entry from the space, waiting forever until one exists.
    inp(Object key)
    In probe takes an entry from the space if one exists, return null otherwise.
    void
    nrd(Object key)
    Nrd (not read) waits forever until Key is not present in space.
    Resolution for expiring entries is implementation dependant, but a minimum one-second is suggested.
    nrd(Object key, long timeout)
    Nrd (not read) waits up to timeout until Key is not present in space.
    Resolution for expiring entries is implementation dependant, but a minimum one-second is suggested.
    void
    out(K key, V value)
    Write a new entry into the Space
    void
    out(K key, V value, long timeout)
    Write a new entry into the Space The entry will timeout after the specified period
    void
    push(Object key, Object value, long timeout)
    Write a new entry into the Space at the head of a queue The entry will timeout after the specified period
    void
    push(K key, V value)
    Write a new entry at the head of a queue.
    void
    put(K key, V value)
    Write a single entry at the head of the queue discarding the other entries
    void
    put(K key, V value, long timeout)
    Write a single entry at the head of the queue discarding the other entries, with timeout.
    rd(Object key)
    Read an entry from the space, waiting forever until one exists.
    rd(Object key, long timeout)
    Read an entry from the space, waiting a limited amount of time until one exists.
    rdp(Object key)
    Read probe reads an entry from the space if one exists, return null otherwise.
    void
    force rollback
    void
    run()
     
    void
    setAutoCommit(boolean b)
    Use with utmost care and at your own risk.
    long
    size(Object key)
     

    Methods inherited from class TimerTask

    cancel, scheduledExecutionTime

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • JDBMSpace

      protected JDBMSpace(String name, String filename)
      protected constructor.
      Parameters:
      name - Space Name
      filename - underlying JDBM filename
  • Method Details

    • getSpace

      public static JDBMSpace getSpace()
      Returns:
      reference to default JDBMSpace
    • getSpace

      public static JDBMSpace getSpace(String name)
      creates a named JDBMSpace (filename used for storage is the same as the given name)
      Parameters:
      name - the Space name
      Returns:
      reference to named JDBMSpace
    • getSpace

      public static JDBMSpace getSpace(String name, String filename)
      creates a named JDBMSpace
      Parameters:
      name - the Space name
      filename - the storage file name
      Returns:
      reference to named JDBMSpace
    • setAutoCommit

      public void setAutoCommit(boolean b)
      Use with utmost care and at your own risk. If you are to perform several operations on the space you should synchronize on the space, i.e:
        synchronized (sp) {
          sp.setAutoCommit (false);
          sp.out (..., ...)
          sp.out (..., ...)
          ...
          ...
          sp.inp (...);
          sp.commit ();    // or sp.rollback ();
          sp.setAutoCommit (true);
        }
      
      Parameters:
      b - true or false
    • commit

      public void commit()
      force commit
    • rollback

      public void rollback()
      force rollback
    • close

      public void close()
      close this space - use with care
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Space<K,V>
    • out

      public void out(K key, V value)
      Write a new entry into the Space
      Specified by:
      out in interface Space<K,V>
      Parameters:
      key - Entry's key
      value - Object value
    • out

      public void out(K key, V value, long timeout)
      Write a new entry into the Space The entry will timeout after the specified period
      Specified by:
      out in interface Space<K,V>
      Parameters:
      key - Entry's key
      value - Object value
      timeout - entry timeout in millis
    • push

      public void push(K key, V value)
      Description copied from interface: Space
      Write a new entry at the head of a queue.
      Specified by:
      push in interface Space<K,V>
      Parameters:
      key - Entry's key
      value - Object value
    • push

      public void push(Object key, Object value, long timeout)
      Write a new entry into the Space at the head of a queue The entry will timeout after the specified period
      Specified by:
      push in interface Space<K,V>
      Parameters:
      key - Entry's key
      value - Object value
      timeout - entry timeout in millis
    • rdp

      public V rdp(Object key)
      Read probe reads an entry from the space if one exists, return null otherwise.
      Specified by:
      rdp in interface Space<K,V>
      Parameters:
      key - Entry's key
      Returns:
      value or null
    • inp

      public V inp(Object key)
      In probe takes an entry from the space if one exists, return null otherwise.
      Specified by:
      inp in interface Space<K,V>
      Parameters:
      key - Entry's key
      Returns:
      value or null
    • in

      public V in(Object key)
      Description copied from interface: Space
      Take an entry from the space, waiting forever until one exists.
      Specified by:
      in in interface Space<K,V>
      Parameters:
      key - Entry's key
      Returns:
      value
    • in

      public V in(Object key, long timeout)
      Take an entry from the space, waiting forever until one exists.
      Specified by:
      in in interface Space<K,V>
      Parameters:
      key - Entry's key
      timeout - millis to wait
      Returns:
      value
    • rd

      public V rd(Object key)
      Read an entry from the space, waiting forever until one exists.
      Specified by:
      rd in interface Space<K,V>
      Parameters:
      key - Entry's key
      Returns:
      value
    • rd

      public V rd(Object key, long timeout)
      Read an entry from the space, waiting a limited amount of time until one exists.
      Specified by:
      rd in interface Space<K,V>
      Parameters:
      key - Entry's key
      timeout - millis to wait
      Returns:
      value or null
    • nrd

      public void nrd(Object key)
      Description copied from interface: Space
      Nrd (not read) waits forever until Key is not present in space.
      Resolution for expiring entries is implementation dependant, but a minimum one-second is suggested.
      Specified by:
      nrd in interface Space<K,V>
      Parameters:
      key - Entry's key
    • nrd

      public V nrd(Object key, long timeout)
      Description copied from interface: Space
      Nrd (not read) waits up to timeout until Key is not present in space.
      Resolution for expiring entries is implementation dependant, but a minimum one-second is suggested.
      Specified by:
      nrd in interface Space<K,V>
      Parameters:
      key - Entry's key
      timeout - millis to wait
      Returns:
      value or null
    • size

      public long size(Object key)
      Parameters:
      key - the Key
      Returns:
      aproximately queue size
    • existAny

      public boolean existAny(Object[] keys)
      Specified by:
      existAny in interface Space<K,V>
      Parameters:
      keys - array of keys to check
      Returns:
      true if one or more keys are available in the space
    • existAny

      public boolean existAny(Object[] keys, long timeout)
      Specified by:
      existAny in interface Space<K,V>
      Parameters:
      keys - array of keys to check
      timeout - to wait for any of the entries to become available in millis
      Returns:
      true if one or more keys are available in the space
    • put

      public void put(K key, V value, long timeout)
      Description copied from interface: Space
      Write a single entry at the head of the queue discarding the other entries, with timeout.
      Specified by:
      put in interface Space<K,V>
      Parameters:
      key - Entry's key
      value - Object value
      timeout - timeout value in millis
    • put

      public void put(K key, V value)
      Description copied from interface: Space
      Write a single entry at the head of the queue discarding the other entries
      Specified by:
      put in interface Space<K,V>
      Parameters:
      key - Entry's key
      value - Object value
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Specified by:
      run in class TimerTask
    • gc

      public void gc()
      garbage collector. removes expired entries
    • getKeys

      public String getKeys()