Package org.exoplatform.agenda.util
Class DecideContext
java.lang.Object
org.exoplatform.agenda.util.DecideContext
The state of the decide step running on the current thread: the event rows
it locked, the events it read or wrote, and the side effects it queued for
after its transaction.
While a context is open, the event cache is neither read nor filled: a row read inside the transaction is only recorded, and evicted once the transaction ends. Broadcasts and notification dispatches are queued, and run only once the transaction has committed, so that no listener and no other thread sees the state of a transaction that is not committed yet.
Only the outermost decide step opens a context. The steps it reaches join
it, and the outermost step closes it in a finally: request and
listener threads are pooled.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddLockedEvent(long eventId) Notes that the decide step locked an event row.voidclose()Removes this context from the current thread.static DecideContextcurrent()voiddropEffectsFrom(int mark) Drops the side effects queued from a mark on: those of a nested step that failed.intbooleanisLocked(long eventId) static DecideContextopen()Opens a context on the current thread.static booleanQueues a side effect, a broadcast or a notification dispatch, for after the transaction of the decide step running on the current thread.static <S> booleanqueueMerged(Object key, S share, Consumer<List<S>> effect) Queues one share of a side effect for after the transaction of the decide step running on the current thread.static voidrecordEvent(long eventId) Records an event read or written by the decide step running on the current thread, if any, so that its cache entry is evicted once the step's transaction ends.
-
Method Details
-
open
Opens a context on the current thread.- Returns:
- the opened context
- Throws:
IllegalStateException- when a context is already open on the thread
-
current
- Returns:
- the context open on the current thread, or null
-
recordEvent
public static void recordEvent(long eventId) Records an event read or written by the decide step running on the current thread, if any, so that its cache entry is evicted once the step's transaction ends.- Parameters:
eventId- event technical identifier
-
queue
Queues a side effect, a broadcast or a notification dispatch, for after the transaction of the decide step running on the current thread.- Parameters:
effect- the side effect- Returns:
- true when it was queued, false when no decide step runs on the thread, in which case the caller runs it itself
-
queueMerged
Queues one share of a side effect for after the transaction of the decide step running on the current thread. The shares queued under equal keys make one effect: it runs once, where the first of them was queued, on all of them in the order they were queued. A share dropped with the nested step that queued it takes no part in it.- Type Parameters:
S- the type of the shares- Parameters:
key- what the shares are aboutshare- this shareeffect- the effect of all the shares queued under the key- Returns:
- true when it was queued, false when no decide step runs on the thread, in which case the caller runs the effect of its share itself
-
close
public void close()Removes this context from the current thread. -
addLockedEvent
public void addLockedEvent(long eventId) Notes that the decide step locked an event row.- Parameters:
eventId- event technical identifier
-
isLocked
public boolean isLocked(long eventId) - Parameters:
eventId- event technical identifier- Returns:
- true when the outermost decide step locked that event row
-
getEventIds
- Returns:
- the events read or written, whose cache entries are evicted once the transaction ends
-
getEffects
- Returns:
- the queued side effects, in the order they were queued
-
getEffectCount
public int getEffectCount()- Returns:
- the number of side effects queued so far, the mark a nested step takes at its entry
-
dropEffectsFrom
public void dropEffectsFrom(int mark) Drops the side effects queued from a mark on: those of a nested step that failed. The events it recorded stay, to be evicted.- Parameters:
mark- the number of side effects queued at the nested step's entry
-