IGlobalCache Interface |
Interface that defines a GlobalCache, a thread-safe repository of key value pairs to contain global data and signals to synchronize multi-threaded processing. GlobalCache elements are available throughout all phases of Data Conveyer processing. Element keys are of type string, values can be one of: int, DataTime, decimal, string or object.
GlobalCache elements must be defined using GlobalCacheElements configuration setting. During the process execution, element values can be updated, but no elements can be added/removed.
Signals, unlike elements, do not need to be declared; instead they are simply referred to in RaiseSignal(String), AwaitSignal(String)and AwaitSignalAsync(String) methods.
Caution |
---|
GlobalCache is exposed to concurrent access by multiple threads and therefore updates to its elements (such as TryReplace method) must be performed in a thread-safe manner. Data Conveyer makes no guarantees regarding a particular processing order. As a consequence, user code may need to address possible race conditions, for example by using AwaitCondition(FuncIGlobalCache, Boolean) method. |
Namespace: Mavidian.DataConveyer.Orchestrators
The IGlobalCache type exposes the following members.
Name | Description | |
---|---|---|
Count |
Number of elements held. This value remains constant throughout execution of Data Conveyer process.
| |
Elements |
A collection of all elements held.
| |
Item |
Retrieve the current value for a given key.
|
Name | Description | |
---|---|---|
AwaitCondition |
Wait for a given condition to be satisfied before returning. This method blocks the current thread until the provided function evaluates
to true. Therefore, special care must be taken when defining the function (condition parameter) to avoid a deadlock condition.
| |
AwaitConditionAsync |
Asynchronously wait for a given condition to be satisfied. The returned task will not complete until the provided function evaluates
to true. When called from an asynchronous method, this method allows synchronization of DataConveyer processing without thread blocking.
| |
AwaitSignal |
Wait for a given signal to be raised before returning. This method blocks the current thread until the given signal is raised.
Therefore, special care must be taken to assure that the RaiseSignal(String) method is called on another thread, so that
a deadlock condition is avoided.
| |
AwaitSignalAsync |
Asynchronously wait for a given signal to be raised. The returned task will not complete until the given signal is raised using the
RaiseSignal(String) method. When called from an asynchronous method, this method allows synchronization of DataConveyer processing
without thread blocking.
| |
IncrementValue(String) |
Add 1 to an integer value held in GlobalCache. This method is thread-safe.
| |
IncrementValue(String, Int32) |
Add a given number to an integer value held in GlobalCache. This method is thread-safe.
| |
RaiseSignal |
Raise a signal that another part (thread) of DataConveyer process might be waiting for. Once this method is called, any method held by
either the AwaitSignal(String) or AwaitSignalAsync(String) method will continue execution.
| |
ReplaceValueTIn, TOut |
Replace value for a given key based on a given calculation formula.
| |
TryGet |
Attempt to retrieve the current value for a given key.
| |
TryReplace |
Attempt to replace the value for a given key. This method is thread-safe.
Note that there is no guarantee that any call to TryReplace method will succeed; it will fail (return false) if another thread changed the underlying value (oldValue).
To guarantee a successful replacement, TryGet and TryReplace methods need to be called in a loop until TryReplace returns true.
Alternatively, ReplaceValue method may be called, which executes such loop internally.
|