Class SharedContext
- All Implemented Interfaces:
Context,ResettableContext,SafeCloseable,AutoCloseable
ResettableContext used as a holder for other ResettableContexts that may be shared across
components.
This serves as a place to cache re-usable computations or resources, but must be reset() for every step
of an operation (usually a chunk of ordered keys).
For example, ReadOnlyRedirectedColumnSources that share the same
RedirectionIndex cache a chunk of redirections for the most recent chunk
of ordered keys they have been handed.
It's important that "nested" usage follows the convention of creating a new instance and passing that instance to context creation methods. Said nested instance should be (or be attached to) an entry in the parent context, and reset/closed when said entry is. It should always be safe to skip nested SharedContext creation if all sources that may be using a given instance will be passed the same ordered keys.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstractSharedContext.Keyimplementation for use when a simple Object reference coupled with sub-class identity can determine equality for sharing purposes.static interfaceSharedContext.Key<VALUE_TYPE extends ResettableContext>Key marker interface. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close implementation which invokesSafeCloseable.close()on all values registered viagetOrCreate(Key, Supplier), and then forgets all registered values.final <V extends ResettableContext,K extends SharedContext.Key<V>>
VgetOrCreate(K key, Supplier<V> valueFactory) Get or create theResettableContextvalue for aSharedContext.Keykey.static SharedContextConstruct a new, empty shared context.voidreset()Reset implementation which invokesResettableContext.reset()on all values registered viagetOrCreate(Key, Supplier).
-
Constructor Details
-
SharedContext
protected SharedContext()
-
-
Method Details
-
getOrCreate
public final <V extends ResettableContext,K extends SharedContext.Key<V>> V getOrCreate(K key, @NotNull Supplier<V> valueFactory) Get or create theResettableContextvalue for aSharedContext.Keykey. If the value is computed, the result value will be associated with thekeyuntil theSharedContextisclose()ed.- Parameters:
key- The keyvalueFactory- The value factory, to be invoked ifkeyis not found within thisSharedContext- Returns:
- The value associated with
key, possibly newly-created
-
reset
@OverridingMethodsMustInvokeSuper public void reset()Reset implementation which invokes
ResettableContext.reset()on all values registered viagetOrCreate(Key, Supplier).Sub-classes should be sure to call
super.reset().- Specified by:
resetin interfaceResettableContext
-
close
@OverridingMethodsMustInvokeSuper public void close()Close implementation which invokes
SafeCloseable.close()on all values registered viagetOrCreate(Key, Supplier), and then forgets all registered values.Sub-classes should be sure to call
super.close().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceContext- Specified by:
closein interfaceSafeCloseable
-