Class Context
- All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Pausable, Loggeable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckPoint(String detail) Adds a checkpoint to the context profiler.clone()Creates a copy of the current Context object.Creates a clone of the current Context instance, including only the specified keys.voiddump(PrintStream p, String indent) Dumps a human-readable representation of this object to the print stream.protected voidDumps a single map entry to the output stream.protected voiddumpMap(PrintStream p, String indent) Dumps all map entries to the output stream.booleanvoidEvicts a persistent entry<T> TGet object instance from transaction context.<T> TRetrieves a persistent value by key, waiting up totimeoutmilliseconds.<T> TGet object instance from transaction context.return a LogEvent used to store trace information about this transaction.getMap()Returns the transient map, creating it lazily.Returns a snapshot copy of the transient map.return (or creates) a Profiler objectreturn (or creates) a Resultr objectReturns the value as a String, converting it if necessary.Returns the value as a String, or a default if not found.longReturns the configured pause timeout.inthashCode()booleanCheck if key presentbooleanDetermines whether the specified keys are all present in the map.booleanhasPersistedKey(Object key) Check key exists present persisted mapbooleanisTrace()Returns whether tracing is enabled for this context.keysNotPresent(Object... keys) Returns a comma-separated string of keys that are not present in the map.voidAdds a trace message to the context log event.voidMerges the entries from the provided Context object into the current Context.<T> TMove entry to new key name Moves the value from one key to another.pause()Pauses execution and returns aFuturethat resolves to the resume result.voidPersists a transient entryvoidPuts an Object in the transient Map.voidPuts an Object in the transient or persistent Map.void<T> TRemoves the value associated with the given key from both transient and persistent maps.voidreset()Resets the pause state so this object can be reused.voidresume(int result) Resumes a paused execution with the given result code.voidsetTimeout(long timeout) Sets the maximum pause duration.voidsetTrace(boolean trace) Enables or disables tracing for this context.voidMethods inherited from class Object
finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Loggeable
dumpModifier and TypeMethodDescriptiondefault voiddump(PrintStream p, String indent, LogRenderer.Type type) Dumps a representation of this object using the specified renderer type.
-
Constructor Details
-
Context
public Context()Default constructor.
-
-
Method Details
-
put
-
put
-
persist
-
evict
-
get
-
hasKey
-
hasKeys
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
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
Check key exists present persisted map- Parameters:
key- the key- Returns:
- true if present
-
move
-
get
Get object instance from transaction context.- Type Parameters:
T- desired type of object instance- Parameters:
key- the key of object instancedefValue- default value returned if there is no value in context- Returns:
- object instance if exist in context or
defValueotherwise
-
remove
-
getString
-
getString
-
dump
-
get
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
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.synchronizedMapwrappers.- Overrides:
clonein classObject- Returns:
- a copy of the current Context object with independent map containers
- Throws:
AssertionError- if cloning is not supported, which should not happen
-
clone
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
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
-
hashCode
-
getMap
-
getMapClone
Returns a snapshot copy of the transient map.- Returns:
- a new map containing all current transient entries
-
dumpMap
Dumps all map entries to the output stream.- Parameters:
p- output streamindent- indentation prefix
-
dumpEntry
-
getLogEvent
return a LogEvent used to store trace information about this transaction. If there's no LogEvent there, it creates one.- Returns:
- LogEvent
-
getProfiler
-
getResult
-
log
-
checkPoint
Adds a checkpoint to the context profiler.- Parameters:
detail- descriptive label for this checkpoint
-
isTrace
Returns whether tracing is enabled for this context.- Returns:
- true if tracing is active
-
setTrace
Enables or disables tracing for this context.- Parameters:
trace- true to enable tracing
-
pause
-
resume
-
reset
-
getTimeout
Description copied from interface:PausableReturns the configured pause timeout.- Specified by:
getTimeoutin interfacePausable- Returns:
- timeout in milliseconds
-
setTimeout
Description copied from interface:PausableSets the maximum pause duration.- Specified by:
setTimeoutin interfacePausable- Parameters:
timeout- timeout in milliseconds
-