Class LSpace<K,V>
java.lang.Object
org.jpos.space.LSpace<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Implemented Interfaces:
AutoCloseable, Runnable, LocalSpace<K,V>, Space<K, V>, Loggeable
LSpace (Loom-optimized Space) implementation with per-key locking for Virtual Thread efficiency.
This implementation addresses the thundering herd problem in traditional Space implementations
by using per-key ReentrantLock and Condition objects instead of global synchronization.
With Virtual Threads (Project Loom), this prevents thousands of threads from being
unnecessarily woken up when only one is relevant.
Key features:
- Per-key isolation: Each key has its own lock and condition variables
- Targeted wakeups: Only threads waiting on a specific key are signaled
- Virtual Thread optimized: Scales efficiently with thousands of concurrent threads
- Full LocalSpace compatibility: Drop-in replacement with same API and behavior
- JFR instrumentation: All operations emit SpaceEvent for monitoring
- Since:
- 3.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(Object key, SpaceListener listener) add a SpaceListener associated with a given keyvoidaddListener(Object key, SpaceListener listener, long timeout) add a SpaceListener associated with a given key for a given period of time.voidclose()Cancels the periodic GC task so this instance can be garbage-collected.voiddump(PrintStream p, String indent) Dumps a human-readable representation of this object to the print stream.booleanReturns true if any of the given keys are present in the space.booleanReturns true if any of the given keys become available within the timeout.voidgc()Runs a garbage-collection sweep to remove expired space entries.Non-standard method (required for space replication) - use with care.Returns all current keys as a space-separated string.Returns the set of all keys currently present in the space.Take an entry from the space, waiting forever until one exists.Take an entry from the space, waiting a limited amount of time until one exists.In probe takes an entry from the space if one exists, return null otherwise.booleanisEmpty()Returns true if this space contains no entries.voidnotifyListeners(Object key, Object value) Notifies all registered listeners for the given key/value pair.voidNrd (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 (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.voidWrite a new entry into the SpacevoidWrite a new entry into the Space, with an timeout valuevoidWrite a new entry at the head of a queue.voidWrite a new entry at the head of the queue with a timeout valuevoidWrite a single entry at the head of the queue discarding the other entriesvoidWrite a single entry at the head of the queue discarding the other entries, with timeout.Read an entry from the space, waiting forever until one exists.Read an entry from the space, waiting a limited amount of time until one exists.Read probe reads an entry from the space if one exists, return null otherwise.voidremoveListener(Object key, SpaceListener listener) removes a SpaceListener associated with a given keyvoidrun()voidsetEntries(Map entries) Non-standard method (required for space replication) - use with care.intReturns the number of entries queued under the given key.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, 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.
-
Field Details
-
GCDELAY
-
-
Constructor Details
-
LSpace
public LSpace()Default constructor.
-
-
Method Details
-
out
-
out
-
push
-
push
-
put
-
put
Description copied from interface:SpaceWrite a single entry at the head of the queue discarding the other entries, with timeout. -
rdp
-
inp
-
in
-
in
-
rd
-
rd
-
nrd
Description copied from interface:SpaceNrd (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
Description copied from interface:SpaceNrd (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. -
existAny
-
existAny
Description copied from interface:SpaceReturns true if any of the given keys become available within the timeout. -
run
-
gc
Runs a garbage-collection sweep to remove expired space entries. -
size
Description copied from interface:LocalSpaceReturns the number of entries queued under the given key.- Specified by:
sizein interfaceLocalSpace<K,V> - Parameters:
key- the key to query- Returns:
- number of entries in a given key
-
addListener
Description copied from interface:LocalSpaceadd a SpaceListener associated with a given key- Specified by:
addListenerin interfaceLocalSpace<K,V> - Parameters:
key- Entry's keylistener- a SpaceListener
-
addListener
Description copied from interface:LocalSpaceadd a SpaceListener associated with a given key for a given period of time. Warning: not supported by all space implementations.- Specified by:
addListenerin interfaceLocalSpace<K,V> - Parameters:
key- Entry's keylistener- a SpaceListenertimeout- listener registration timeout in millis
-
removeListener
Description copied from interface:LocalSpaceremoves a SpaceListener associated with a given key- Specified by:
removeListenerin interfaceLocalSpace<K,V> - Parameters:
key- Entry's keylistener- the SpaceListener
-
isEmpty
-
getKeySet
Description copied from interface:LocalSpaceReturns the set of all keys currently present in the space.- Specified by:
getKeySetin interfaceLocalSpace<K,V> - Returns:
- Set containing all keys in Space
-
getKeysAsString
Returns all current keys as a space-separated string.- Returns:
- space-separated key list
-
dump
-
notifyListeners
Notifies all registered listeners for the given key/value pair.- Parameters:
key- the space keyvalue- the new value
-
getEntries
Non-standard method (required for space replication) - use with care.- Returns:
- snapshot map of all entries
-
setEntries
Non-standard method (required for space replication) - use with care.- Parameters:
entries- the entries map to load into this space
-
close
-