Class Context

java.lang.Object
org.jpos.transaction.Context
All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Pausable, Loggeable

public class Context extends Object implements Externalizable, Loggeable, Cloneable, Pausable
See Also:
  • Constructor Details

  • Method Details

    • put

      public void put(Object key, Object value)
      puts an Object in the transient Map
    • put

      public void put(Object key, Object value, boolean persist)
      puts an Object in the transient Map
    • persist

      public void persist(Object key)
      Persists a transient entry
      Parameters:
      key - the key
    • evict

      public void evict(Object key)
      Evicts a persistent entry
      Parameters:
      key - the key
    • get

      public <T> T get(Object key)
      Get object instance from transaction context.
      Type Parameters:
      T - desired type of object instance
      Parameters:
      key - the key of object instance
      Returns:
      object instance if exist in context or null otherwise
    • hasKey

      public boolean hasKey(Object key)
      Check if key present
      Parameters:
      key - the key
      Returns:
      true if present
    • hasKeys

      public boolean hasKeys(Object... keys)
      Determines whether the specified keys are all present in the map. This method accepts a variable number of key arguments and supports both Object[] and String keys. When the key is a String, it can contain multiple keys separated by a '|' character, and the method will return true if any of those keys is present in the map. The method does not support nested arrays of keys.
      Parameters:
      keys - A variable-length array of keys to check for in the map. These keys can be of any Object type or String containing multiple keys separated by '|'.
      Returns:
      true if all specified keys (or any of the '|' separated keys within a String key) are present in the map, false otherwise.
    • keysNotPresent

      public String keysNotPresent(Object... keys)
      Returns a comma-separated string of keys that are not present in the map. This method accepts a variable number of key arguments and supports both Object[] and String keys. When the key is a String, it can contain multiple keys separated by a '|' character, and the method will return the keys not present in the map. The method does not support nested arrays of keys.
      Parameters:
      keys - A variable-length array of keys to check for their absence in the map. These keys can be of any Object type or String containing multiple keys separated by '|'.
      Returns:
      A comma-separated string of keys that are not present in the map. If all the specified keys (or any of the '|' separated keys within a String key) are present in the map, an empty string is returned.
    • hasPersistedKey

      public boolean hasPersistedKey(Object key)
      Check key exists present persisted map
      Parameters:
      key - the key
      Returns:
      true if present
    • move

      public <T> T move(Object from, Object to)
      Move entry to new key name
      Parameters:
      from - key
      to - key
      Returns:
      the entry's value (could be null if 'from' key not present)
    • get

      public <T> T get(Object key, T defValue)
      Get object instance from transaction context.
      Type Parameters:
      T - desired type of object instance
      Parameters:
      key - the key of object instance
      defValue - default value returned if there is no value in context
      Returns:
      object instance if exist in context or defValue otherwise
    • remove

      public <T> T remove(Object key)
      Transient remove
    • getString

      public String getString(Object key)
    • getString

      public String getString(Object key, String defValue)
    • dump

      public void dump(PrintStream p, String indent)
      Specified by:
      dump in interface Loggeable
    • get

      public <T> T get(Object key, long timeout)
      persistent get with timeout
      Parameters:
      key - the key
      timeout - timeout
      Returns:
      object (null on timeout)
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

    • clone

      public Context clone()
      Creates a copy of the current Context object.

      This method clones the Context object, creating new synchronized map containers that are independent of the original. However, the keys and values themselves are not cloned - both Context instances will share references to the same key/value objects. Structural changes (add/remove operations) to one Context's maps will not affect the other, but modifications to mutable key/value objects will be visible in both Contexts.

      The cloned Context preserves the thread-safety characteristics through Collections.synchronizedMap wrappers.

      Overrides:
      clone in class Object
      Returns:
      a copy of the current Context object with independent map containers
      Throws:
      AssertionError - if cloning is not supported, which should not happen
    • clone

      public Context clone(Object... keys)
      Creates a clone of the current Context instance, including only the specified keys. This method accepts a variable number of key arguments and supports both Object[] and String keys. When the key is a String, it can contain multiple keys separated by a '|' character. The method does not support nested arrays of keys.
      Parameters:
      keys - A variable-length array of keys to include in the cloned context. These keys can be of any Object type or String containing multiple keys separated by '|'.
      Returns:
      A cloned Context instance containing only the specified keys and their associated values from the original context. If none of the specified keys are present in the original context, an empty Context instance is returned.
    • merge

      public void merge(Context c)
      Merges the entries from the provided Context object into the current Context.

      This method iterates over the entries in the given Context object 'c' and adds or updates the entries in the current Context. If an entry already exists in the current Context, its value will be updated. If an entry is marked as persisted in the given Context object, it will also be marked as persisted in the current Context.

      Parameters:
      c - the Context object whose entries should be merged into the current Context
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getMap

      public Map<Object,Object> getMap()
      Returns:
      transient map
    • getMapClone

    • dumpMap

      protected void dumpMap(PrintStream p, String indent)
    • dumpEntry

      protected void dumpEntry(PrintStream p, String indent, Map.Entry<Object,Object> entry)
    • getLogEvent

      return a LogEvent used to store trace information about this transaction. If there's no LogEvent there, it creates one.
      Returns:
      LogEvent
    • getProfiler

      return (or creates) a Profiler object
      Returns:
      Profiler object
    • getResult

      public Result getResult()
      return (or creates) a Resultr object
      Returns:
      Profiler object
    • log

      public void log(Object msg)
      adds a trace message
      Parameters:
      msg - trace information
    • checkPoint

      public void checkPoint(String detail)
      add a checkpoint to the profiler
    • isTrace

      public boolean isTrace()
    • setTrace

      public void setTrace(boolean trace)
    • pause

      public Future<Integer> pause()
      Specified by:
      pause in interface Pausable
    • resume

      public void resume(int result)
      Specified by:
      resume in interface Pausable
    • reset

      public void reset()
      Specified by:
      reset in interface Pausable
    • getTimeout

      public long getTimeout()
      Specified by:
      getTimeout in interface Pausable
    • setTimeout

      public void setTimeout(long timeout)
      Specified by:
      setTimeout in interface Pausable