Class JESpace<K,V>

java.lang.Object
org.jpos.util.Log
org.jpos.space.JESpace<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
AutoCloseable, Runnable, LocalSpace<K,V>, PersistentSpace, Space<K,V>, Loggeable, LogSource

public class JESpace<K,V> extends Log implements LocalSpace<K,V>, PersistentSpace, Loggeable, Runnable
BerkeleyDB Jave Edition based persistent space implementation
Since:
1.6.5
  • Field Details

  • Constructor Details

    • JESpace

      public JESpace(String name, String params) throws SpaceError
      Constructs a JESpace with the given name and path/parameter string.
      Parameters:
      name - the space name (also used as the entity store name)
      params - comma-separated parameters; first element is the directory path
      Throws:
      SpaceError - if the BerkeleyDB environment or store cannot be opened
  • Method Details

    • out

      public void out(K key, V value)
      Description copied from interface: Space
      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)
      Description copied from interface: Space
      Write a new entry into the Space, with an timeout value
      Specified by:
      out in interface Space<K,V>
      Parameters:
      key - Entry's key
      value - Object value
      timeout - timeout value in millis
    • push

      public void push(K key, V value, long timeout)
      Description copied from interface: Space
      Write a new entry at the head of the queue with a timeout value
      Specified by:
      push in interface Space<K,V>
      Parameters:
      key - Entry's key
      value - Object value
      timeout - timeout value 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
    • rdp

      public V rdp(Object key)
      Description copied from interface: Space
      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
    • 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)
      Description copied from interface: Space
      Take an entry from the space, waiting a limited amount of time until one exists.
      Specified by:
      in in interface Space<K,V>
      Parameters:
      key - Entry's key
      timeout - millis to wait
      Returns:
      value or null
    • rd

      public V rd(Object key)
      Description copied from interface: Space
      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)
      Description copied from interface: Space
      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
    • inp

      public V inp(Object key)
      Description copied from interface: Space
      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
    • existAny

      public boolean existAny(Object[] keys)
      Description copied from interface: Space
      Returns true if any of the given keys are present in the space.
      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)
      Description copied from interface: Space
      Returns true if any of the given keys become available within the 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)
      Removes all existing entries for the key then writes a single entry (head-of-queue replacement).
      Specified by:
      put in interface Space<K,V>
      Parameters:
      key - the entry key
      value - the new value
    • gc

      public void gc() throws com.sleepycat.je.DatabaseException
      Runs a garbage-collection pass removing expired entries from the BDB JE store.
      Throws:
      com.sleepycat.je.DatabaseException - on BDB error
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • close

      public void close() throws com.sleepycat.je.DatabaseException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Space<K,V>
      Throws:
      com.sleepycat.je.DatabaseException
    • getSpace

      public static JESpace getSpace(String name, String path)
      Returns (or creates) the named JESpace stored at the given path.
      Parameters:
      name - space name
      path - filesystem path for BDB JE environment
      Returns:
      the JESpace instance
    • getSpace

      public static JESpace getSpace(String name)
      Returns (or creates) the named JESpace using the name as the storage path.
      Parameters:
      name - space name and storage path
      Returns:
      the JESpace instance
    • addListener

      public void addListener(Object key, SpaceListener listener)
      Description copied from interface: LocalSpace
      add a SpaceListener associated with a given key
      Specified by:
      addListener in interface LocalSpace<K,V>
      Parameters:
      key - Entry's key
      listener - a SpaceListener
    • addListener

      public void addListener(Object key, SpaceListener listener, long timeout)
      Description copied from interface: LocalSpace
      add a SpaceListener associated with a given key for a given period of time. Warning: not supported by all space implementations.
      Specified by:
      addListener in interface LocalSpace<K,V>
      Parameters:
      key - Entry's key
      listener - a SpaceListener
      timeout - listener registration timeout in millis
    • removeListener

      public void removeListener(Object key, SpaceListener listener)
      Description copied from interface: LocalSpace
      removes a SpaceListener associated with a given key
      Specified by:
      removeListener in interface LocalSpace<K,V>
      Parameters:
      key - Entry's key
      listener - the SpaceListener
    • getKeySet

      public Set getKeySet()
      Description copied from interface: LocalSpace
      Returns the set of all keys currently present in the space.
      Specified by:
      getKeySet in interface LocalSpace<K,V>
      Returns:
      Set containing all keys in Space
    • size

      public int size(Object key)
      Description copied from interface: LocalSpace
      Returns the number of entries queued under the given key.
      Specified by:
      size in interface LocalSpace<K,V>
      Parameters:
      key - the key to query
      Returns:
      number of entries in a given key
    • dump

      public void dump(PrintStream p, String indent)
      Description copied from interface: Loggeable
      Dumps a human-readable representation of this object to the print stream.
      Specified by:
      dump in interface Loggeable
      Parameters:
      p - the output stream
      indent - indentation prefix