coherence.processor
Processors
- class coherence.processor.Processors
The Processors class provides a set of static methods for creating standard Coherence
coherence.processor.EntryProcessor
’s.- static conditional_put(filter: Filter, value: V, return_value: bool = False) EntryProcessor[V]
Construct a
coherence.processor.ConditionalPut
that updates an entry with a new value if and only if thecoherence.filter.Filter
applied to the entry evaluates to True.- param filter:
the
coherence.filter.Filter
to evaluate an entry- param value:
a value to update an entry with
- param return_value:
specifies whether the processor should return the current value in case it has not been updated
- return:
a processor that updates an entry with a new value if and only if the filter applied to the entry evaluates to True.
- static conditional_put_all(filter: Filter, values: dict[K, V]) EntryProcessor[V]
Construct a
coherence.processor.ConditionalRemove
processor that updates an entry with a new value if and only if thecoherence.filter.Filter
applied to the entry evaluates to True. The new value is extracted from the specified map based on the entry’s key.- Parameters:
filter – the
coherence.filter.Filter
to evaluate all supplied entriesvalues – a dict of values to update entries with
- Returns:
a processor that updates one or more entries with the provided values if and only if the filter applied to the entry evaluates to True
- static conditional_remove(filter: Filter, return_value: bool = False) EntryProcessor[V]
Constructs a
coherence.processor.ConditionalRemove
processor that removes ancoherence.client.NamedMap
entry if and only if thecoherence.filter.Filter
applied to the entry evaluates to True.This processor may optionally return the current value as a result of the invocation if it has not been removed (the
coherence.filter.Filter
evaluated to False).- Parameters:
filter – the
coherence.filter.Filter
to evaluate an entryreturn_value – specifies whether the processor should return the current value if it has not been removed
- static extract(extractor: ValueExtractor[T, E] | str | None = None) EntryProcessor[E]
Construct an
coherence.processor.ExtractorProcessor
using the givencoherence.extractor.ValueExtractor
or string expression to extract a value from an object cached within acoherence.client.NamedMap
.For clustered caches using the
coherence.processor.ExtractorProcessor
could significantly reduce the amount of network traffic.- Parameters:
extractor – the
coherence.extractor.ValueExtractor
or string expression to use by this processor or the name of the method to invoke via java reflection. If None, ancoherence.extractor.IdentityExtractor
will be used.
- static increment(name_or_manipulator: ValueManipulator[T, E] | str, increment: int | float | Decimal, post_increment: bool = False) EntryProcessor[int | float | Decimal]
Construct an
coherence.processor.NumberIncrementor
processor that will increment a property value by a specified amount, returning either the old or the new value as specified.- Parameters:
name_or_manipulator – the
coherence.extractor.ValueManipulator
or string expressionincrement – the numeric value representing the magnitude and sign of the increment
post_increment – pass True to return the value as it was before it was incremented, or pass False to return the value as it is after it is incremented
- Returns:
- static invoke_accessor(method_name: str, *args: Any) EntryProcessor[R]
- Constructs a
coherence.processor.MethodInvocationProcessor
that invokes the specified method on a value of a cache entry.
- Parameters:
method_name – the name of the method to invoke
args – the method arguments
- Returns:
a
coherence.processor.MethodInvocationProcessor
that invokes the specified method on a value of a cache entry and optionally updates the entry with a modified value
- Constructs a
- static invoke_mutator(method_name: str, *args: Any) EntryProcessor[R]
Constructs a
coherence.processor.MethodInvocationProcessor
that invokes the specified method on a value of a cache entry updating the entry with a modified value.- Parameters:
method_name – the name of the method to invoke
args – the method arguments
- Returns:
a
coherence.processor.MethodInvocationProcessor
that invokes the specified method on a value of a cache entry and optionally updates the entry with a modified value
- static multiply(name_or_manipulator: ValueManipulator[T, E] | str, multiplier: int | float | Decimal, post_multiplication: bool = False) EntryProcessor[int | float | Decimal]
Construct an NumberMultiplier processor that will multiply a property value by a specified factor, returning either the old or the new value as specified.
- Parameters:
name_or_manipulator – the ValueManipulator or the property name
multiplier – the Number representing the magnitude and sign of the multiplier
post_multiplication – pass True to return the value as it was before it was multiplied, or pass False to return the value as it is after it is multiplied
- static nop() EntryProcessor[bool]
Construct an
coherence.processor.EntryProcessor
that does nothing and returns True as a result of execution :return: ancoherence.processor.EntryProcessor
that does nothing and returns True as a result of execution
- static preload() EntryProcessor[None]
coherence.processor.PreloadRequest
is a simplecoherence.processor.EntryProcessor
that performs a get call. No results are reported back to the caller.The
coherence.processor.PreloadRequest
process provides a means to “preload” an entry or a collection of entries into the cache using the cache loader without incurring the cost of sending the value(s) over the network. If the corresponding entry (or entries) already exists in the cache, or if the cache does not have a loader, then invoking thiscoherence.processor.PreloadRequest
has no effect. :return:
- static script(name: str, language: str, *args: Any) EntryProcessor[Any]
Create a
coherence.processor.ScriptProcessor
that wraps a script written in the specified language and identified by the specified name. The specified args will be passed during execution of the script.- Parameters:
name – the name of the
coherence.processor.EntryProcessor
that needs to be executedlanguage – the language the script is written. Currently, only js (for JavaScript) is supported
args – the arguments to be passed to the
coherence.processor.EntryProcessor
- static touch() EntryProcessor[None]
Creates an
coherence.processor.EntryProcessor
that touches an entry (if present) in order to trigger interceptor re-evaluation and possibly increment expiry time. :return:
- static update(updater_or_property_name: ValueUpdater[V, bool] | str, value: V) EntryProcessor[bool]
Construct an
coherence.processor.UpdaterProcessor
based on the specified ValueUpdater.While it’s possible to update a value via standard Map API, using the updater allows for clustered caches using the UpdaterProcessor allows avoiding explicit concurrency control and could significantly reduce the amount of network traffic.
- Parameters:
updater_or_property_name – a ValueUpdater object or the method name; passing null will simpy replace the entry’s value with the specified one instead of updating it
value – the value to update the target entry with
- static versioned_put(value: V, allow_insert: bool = False, return_current: bool = False) EntryProcessor[V]
Construct a
coherence.processor.VersionedPut
that updates an entry with a new value if and only if the version of the new value matches to the version of the current entry’s value. This processor optionally returns the current value as a result of the invocation if it has not been updated (the versions did not match).- Parameters:
value – a value to update an entry with
allow_insert – specifies whether an insert should be allowed (no currently existing value)
return_current – specifies whether the processor should return the current value in case it has not been updated
- static versioned_put_all(values: dict[K, V], allow_insert: bool = False, return_current: bool = False) EntryProcessor[V]
Construct a
coherence.processor.VersionedPut
processor that updates an entry with a new value if and only if the version of the new value matches to the version of the current entry’s value (which must exist). This processor optionally returns a map of entries that have not been updated (the versions did not match).- Parameters:
values – a dict of values to update entries with
allow_insert – specifies whether an insert should be allowed (no currently existing value)
return_current – specifies whether the processor should return the current value in case it has not been updated
EntryProcessor
- class coherence.processor.EntryProcessor
Bases:
ABC
,Generic
[R
]An invocable agent that operates against the entries within a NamedMap
- __init__() None
Constructs a new EntryProcessor
- and_then(processor: EntryProcessor[Any]) EntryProcessor[Any]
Returns a
coherence.processor.CompositeProcessor
comprised of this and the provided processor.- Parameters:
processor – the next processor
- Returns:
a
coherence.processor.CompositeProcessor
comprised of this and the provided processor
- when(filter: Filter) EntryProcessor[R]
Returns a
coherence.processor.ConditionalProcessor
comprised of this processor and the provided filter.The specified entry processor gets invoked if and only if the filter applied to the entry evaluates to true; otherwise the result of the invocation will return None.
- Parameters:
filter – the filter :return: Returns a
coherence.processor.ConditionalProcessor
comprised of this processor and the provided filter.
ExtractorProcessor
- class coherence.processor.ExtractorProcessor(value_extractor: ValueExtractor[V, R] | str)
Bases:
EntryProcessor
[R
]ExtractorProcessor is an
coherence.processor.EntryProcessor
implementation that extracts a value from an object cached within a NamedMap.- Example:
A common usage pattern is:
>>> cache.invoke(aPerson,ExtractorProcessor("age"))
For clustered caches using the ExtractorProcessor could significantly reduce the amount of network traffic.
- __init__(value_extractor: ValueExtractor[V, R] | str)
Construct an ExtractorProcessor using the given extractor or method name.
- Parameters:
value_extractor – the
coherence.extractor.ValueExtractor
or string expression to use by this filter or the name of the method to invoke via java reflection
CompositeProcessor
- class coherence.processor.CompositeProcessor(*processors: Any)
Bases:
EntryProcessor
[R
]CompositeProcessor represents a collection of entry processors that are invoked sequentially against the same MapEntry.
- __init__(*processors: Any)
Construct a CompositeProcessor for the specified array of individual entry processors.
The result of the CompositeProcessor execution is an array of results returned by the individual EntryProcessor invocations.
- Parameters:
processors – the entry processor array
- and_then(processor: EntryProcessor[Any]) CompositeProcessor[R]
Returns a
coherence.processor.CompositeProcessor
comprised of this and the provided processor.- Parameters:
processor – the next processor
- Returns:
a
coherence.processor.CompositeProcessor
comprised of this and the provided processor
- when(filter: Filter) EntryProcessor[R]
Returns a
coherence.processor.ConditionalProcessor
comprised of this processor and the provided filter.The specified entry processor gets invoked if and only if the filter applied to the entry evaluates to true; otherwise the result of the invocation will return None.
- Parameters:
filter – the filter :return: Returns a
coherence.processor.ConditionalProcessor
comprised of this processor and the provided filter.
ConditionalProcessor
- class coherence.processor.ConditionalProcessor(filter: Filter, processor: EntryProcessor[V])
Bases:
EntryProcessor
[V
]ConditionalProcessor represents a processor that is invoked conditionally based on the result of an entry evaluation. A ConditionalProcessor is returned from the when() function, which takes a filter as its argument.
- __init__(filter: Filter, processor: EntryProcessor[V])
Construct a ConditionalProcessor for the specified filter and the processor.
The specified entry processor gets invoked if and only if the filter applied to the cache entry evaluates to true; otherwise the result of the invocation will return null.
- Parameters:
filter – the filter
processor – the entry processor
NullProcessor
- class coherence.processor.NullProcessor
Bases:
EntryProcessor
[bool
]Put entry processor.
An implementation of an EntryProcessor that does nothing and returns true as a result of execution.
- __init__() None
Construct a Null EntryProcessor.
PropertyProcessor
- class coherence.processor.PropertyProcessor(manipulator: ValueManipulator[T, E] | str, use_is: bool = False)
Bases:
EntryProcessor
[R
]PropertyProcessor is a base class for EntryProcessor implementations that depend on a ValueManipulator.
- __init__(manipulator: ValueManipulator[T, E] | str, use_is: bool = False)
Construct a PropertyProcessor for the specified property name.
This constructor assumes that the corresponding property getter will have a name of (“get” + sName) and the corresponding property setter’s name will be (“set” + sName).
- Parameters:
manipulator – the manipulator or property name
use_is – prefix with is
PropertyManipulator
- class coherence.processor.PropertyManipulator(property_name: str, use_is: bool = False)
Bases:
ValueManipulator
[V
,R
]PropertyManipulator is a reflection based ValueManipulator implementation based on the JavaBean property name conventions.
- __init__(property_name: str, use_is: bool = False)
Construct a PropertyManipulator for the specified property name.
This constructor assumes that the corresponding property getter will have a name of either (“get” + sName) or (“is” + sName) and the corresponding property setter’s name will be (“set” + sName).
- Parameters:
property_name – a property name
use_is – if true, the getter method will be prefixed with “is” rather than “get”
- get_extractor() ValueExtractor[V, R]
Retrieve the underlying ValueExtractor reference.
- Return type:
the ValueExtractor
- get_updator() ValueUpdater[V, R]
Retrieve the underlying ValueUpdater reference.
- Return type:
the ValueUpdater
NumberMultiplier
- class coherence.processor.NumberMultiplier(name_or_manipulator: ValueManipulator[T, E] | str, multiplier: int | float | Decimal, post_multiplication: bool = False)
Bases:
PropertyProcessor
[Union
[int
,float
,Decimal
]]NumberMultiplier entry processor.
- __init__(name_or_manipulator: ValueManipulator[T, E] | str, multiplier: int | float | Decimal, post_multiplication: bool = False)
Construct an NumberMultiplier processor that will multiply a property value by a specified factor, returning either the old or the new value as specified.
- Parameters:
name_or_manipulator – the ValueManipulator or the property name
multiplier – the Number representing the magnitude and sign of the multiplier
post_multiplication – pass true to return the value as it was before it was multiplied, or pass false to return the value as it is after it is multiplied
NumberIncrementor
- class coherence.processor.NumberIncrementor(name_or_manipulator: ValueManipulator[T, E] | str, increment: int | float | Decimal, post_increment: bool = False)
Bases:
PropertyProcessor
[Union
[int
,float
,Decimal
]]The
coherence.processor.NumberIncrementor
coherence.processor.EntryProcessor
is used to increment a property value of a numeric type.- __init__(name_or_manipulator: ValueManipulator[T, E] | str, increment: int | float | Decimal, post_increment: bool = False)
Construct an
coherence.processor.NumberIncrementor
processor that will increment a property value by a specified amount, returning either the old or the new value as specified.- Parameters:
name_or_manipulator – the
coherence.extractor.ValueManipulator
or string expressionincrement – the numeric value representing the magnitude and sign of the increment
post_increment – pass True to return the value as it was before it was incremented, or pass False to return the value as it is after it is incremented
ConditionalPut
- class coherence.processor.ConditionalPut(filter: Filter, value: V, return_value: bool = True)
Bases:
EntryProcessor
[V
]coherence.processor.ConditionalPut
is ancoherence.processor.EntryProcessor
that performs an update operation for an entry that satisfies the specified condition.While the
coherence.processor.ConditionalPut
processing could be implemented via direct key-basedcoherence.client.NamedMap
operations, it is more efficient and enforces concurrency control without explicit locking.Obviously, using more specific, fine-tuned filters (rather than ones based on the
coherence.extractor.IdentityExtractor
) may provide additional flexibility and efficiency allowing the put operation to be performed conditionally on values of specific attributes (or even calculations) instead of the entire object.- __init__(filter: Filter, value: V, return_value: bool = True)
Construct a
coherence.processor.ConditionalPut
that updates an entry with a new value if and only if the filter applied to the entry evaluates to True.- Parameters:
filter – the
coherence.filter.Filter
to evaluate an entryvalue – a value to update an entry with
return_value – specifies whether the processor should return the current value in case it has not been updated
ConditionalPutAll
- class coherence.processor.ConditionalPutAll(filter: Filter, the_map: dict[K, V])
Bases:
EntryProcessor
[V
]ConditionalPutAll is an EntryProcessor that performs an update operation for multiple entries that satisfy the specified condition.
This allows for concurrent insertion/update of values within the cache.
- Example:
For example a concurrent replaceAll(map) could be implemented as:
>>> filter = PresentFilter.INSTANCE >>> cache.invokeAll(map.keys(), ConditionalPutAll(filter, map))
or putAllIfAbsent could be done by inverting the filter:
>>> filter = NotFilter(PresentFilter())
Obviously, using more specific, fine-tuned filters may provide additional flexibility and efficiency allowing the multi-put operations to be performed conditionally on values of specific attributes (or even calculations) instead of a simple existence check.
- __init__(filter: Filter, the_map: dict[K, V])
Construct a ConditionalPutAll processor that updates an entry with a new value if and only if the filter applied to the entry evaluates to True. The new value is extracted from the specified map based on the entry’s key.
- Parameters:
filter – the filter to evaluate all supplied entries
the_map – a dict of values to update entries with
ConditionalRemove
- class coherence.processor.ConditionalRemove(filter: Filter, return_value: bool = False)
Bases:
EntryProcessor
[V
]ConditionalRemove is an EntryProcessor that performs n remove operation if the specified condition is satisfied.
While the ConditionalRemove processing could be implemented via direct key-based NamedMap operations, it is more efficient and enforces concurrency control without explicit locking.
- __init__(filter: Filter, return_value: bool = False)
Construct a
coherence.processor.ConditionalRemove
processor that removes ancoherence.client.NamedMap
entry if and only if the filter applied to the entry evaluates to True.This processor may optionally return the current value as a result of the invocation if it has not been removed (the
coherence.filter.Filter
evaluated to False).- Parameters:
filter – the filter to evaluate an entry
return_value – specifies whether the processor should return the current value if it has not been removed
MethodInvocationProcessor
- class coherence.processor.MethodInvocationProcessor(method_name: str, mutator: bool, *args: Any)
Bases:
EntryProcessor
[R
]An
coherence.processor.EntryProcessor
that invokes the specified method on a value of a cache entry and optionally updates the entry with a modified value.- __init__(method_name: str, mutator: bool, *args: Any)
Construct
coherence.processor.MethodInvoctionProcessor
instance.- Parameters:
method_name – the name of the method to invoke
mutator – the flag specifying whether the method mutates the state of a target object, which implies that the entry value should be updated after method invocation
args – the method arguments
TouchProcessor
- class coherence.processor.TouchProcessor
Bases:
EntryProcessor
[None
]Touches an entry (if present) in order to trigger interceptor re-evaluation and possibly increment expiry time.
- __init__() None
Construct a TouchProcessor
ScriptProcessor
- class coherence.processor.ScriptProcessor(name: str, language: str, *args: Any)
Bases:
EntryProcessor
[Any
]ScriptProcessor wraps a script written in one of the languages supported by Graal VM.
- __init__(name: str, language: str, *args: Any)
Create a
coherence.processor.ScriptProcessor
that wraps a script written in the specified language and identified by the specified name. The specified args will be passed during execution of the script.- Parameters:
name – the name of the
coherence.processor.EntryProcessor
that needs to be executedlanguage – the language the script is written. Currently, only js (for JavaScript) is supported
args – the arguments to be passed to the
coherence.processor.EntryProcessor
PreloadRequest
- class coherence.processor.PreloadRequest
Bases:
EntryProcessor
[None
]PreloadRequest is a simple
coherence.processor.EntryProcessor
that performs a get call. No results are reported back to the caller.The
coherence.processor.PreloadRequest
process provides a means to “preload” an entry or a collection of entries into the cache using the cache loader without incurring the cost of sending the value(s) over the network. If the corresponding entry (or entries) already exists in the cache, or if the cache does not have a loader, then invoking thiscoherence.processor.EntryProcessor
has no effect.- __init__() None
Construct a PreloadRequest EntryProcessor.
UpdaterProcessor
- class coherence.processor.UpdaterProcessor(updater_or_property_name: ValueUpdater[V, bool] | str, value: V)
Bases:
EntryProcessor
[bool
]UpdaterProcessor is an
coherence.processor.EntryProcessor
implementations that updates an attribute of an object cached in an InvocableMap.While it’s possible to update a value via standard Map API, using the updater allows for clustered caches using the UpdaterProcessor allows avoiding explicit concurrency control and could significantly reduce the amount of network traffic.
- __init__(updater_or_property_name: ValueUpdater[V, bool] | str, value: V)
Construct an UpdaterProcessor based on the specified ValueUpdater.
- Parameters:
updater_or_property_name – a ValueUpdater object or the method name; passing null will simpy replace the entry’s value with the specified one instead of updating it
value – the value to update the target entry with
VersionedPut
- class coherence.processor.VersionedPut(value: V, allow_insert: bool = False, return_current: bool = False)
Bases:
EntryProcessor
[V
]VersionedPut is an
coherence.processor.EntryProcessor
that assumes that entry values are versioned (see Coherence Versionable interface for details) and performs an update/insert operation if and only if the version of the specified value matches the version of the corresponding value. VersionedPutAll will increment the version indicator before each value is updated.- __init__(value: V, allow_insert: bool = False, return_current: bool = False)
Construct a VersionedPut that updates an entry with a new value if and only if the version of the new value matches to the version of the current entry’s value. This processor optionally returns the current value as a result of the invocation if it has not been updated (the versions did not match).
- Parameters:
value – a value to update an entry with
allow_insert – specifies whether an insert should be allowed (no currently existing value)
return_current – specifies whether the processor should return the current value in case it has not been updated
VersionedPutAll
- class coherence.processor.VersionedPutAll(values: dict[K, V], allow_insert: bool = False, return_current: bool = False)
Bases:
EntryProcessor
[V
]VersionedPutAll is an
coherence.processor.EntryProcessor
that assumes that entry values are versioned ( see Coherence Versionable interface for details) and performs an update/insert operation only for entries whose versions match to versions of the corresponding current values. In case of the match, the VersionedPutAll will increment the version indicator before each value is updated.- __init__(values: dict[K, V], allow_insert: bool = False, return_current: bool = False)
Construct a VersionedPutAll processor that updates an entry with a new value if and only if the version of the new value matches to the version of the current entry’s value (which must exist). This processor optionally returns a map of entries that have not been updated (the versions did not match).
- Parameters:
values – a dict of values to update entries with
allow_insert – specifies whether an insert should be allowed (no currently existing value)
return_current – specifies whether the processor should return the current value in case it has not been updated