class OperationJournal extends Thread
Third to make sure that transitions occur between the time a query
starts its initial search and the time it adds its watcher to the
TransitionWatchers
object do not get missed. This
last goal is accomplished by queries calling
newTransitionIterator
before initial search, doing the
initial search, adding their watcher to the
TransitionWatchers
object and then calling
watcherRegistered
on the
TransitionIterator
and then feeding their watcher the
chain of transitions yielded by the
TransitionIterator
. (skipping any transitions with
entries that don't match).
Each operation that is recored in the journal is assigned an ordinal. Operations with higher ordinals must be considered to have taken place after operations with lower ordinals.
Modifier and Type | Class and Description |
---|---|
private class |
OperationJournal.CaughtUpMarker
JournalNode payload value used for
caught up markers. |
private class |
OperationJournal.JournalNode
The nodes of our Journal
|
(package private) class |
OperationJournal.TransitionIterator
An iterator that will yield (in the order they were posted) all the
EntryTransition s added after the iterator was
created and processed before watcherRegistered was
called. |
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
private boolean |
dead
If
true stop thread |
private long |
lastOrdinalUsed
The last ordinal value used
|
private OperationJournal.JournalNode |
lastProcessed
The
JournalNode we are currently processing or if
none are in process the last one we processed. |
private static Logger |
logger
Logger for logging exceptions
|
private OperationJournal.JournalNode |
tail
The current tail of the transitions list.
|
private TransitionWatchers |
watchers
The object to ask about who is interested in a transition
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
OperationJournal(TransitionWatchers watchers)
Create a new
OperationJournal . |
Modifier and Type | Method and Description |
---|---|
(package private) long |
currentOrdinal()
Return the ordinal of the last operation posted.
|
private OperationJournal.JournalNode |
lastProcessed(OperationJournal.JournalNode noEarlierThan)
Return the node currently being processed, or
if no entry is currently being processed the
last one that was processed.
|
(package private) void |
markCaughtUp(IfExistsWatcher watcher)
Schedules a job that will call the
caughtUp method
on the passed IfExistsWatcher after the last
posted EntryTransition is processed. |
(package private) OperationJournal.TransitionIterator |
newTransitionIterator()
Return an iterator that can latter be used to
get all the
EntryTransition s added after
this point that have been processed. |
private void |
post(OperationJournal.JournalNode node)
Post a
JournalNode |
(package private) void |
recordTransition(EntryTransition transition)
Records an operation on an entry.
|
void |
run()
Loop pulling transitions off the queue and
process them by getting the set of interested watchers
from the
TransitionWatchers object associated
with this object and then calling process on each
of the watchers. |
(package private) void |
terminate()
Terminate queue processing.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
private final TransitionWatchers watchers
private OperationJournal.JournalNode tail
private OperationJournal.JournalNode lastProcessed
JournalNode
we are currently processing or if
none are in process the last one we processed.private boolean dead
true
stop threadprivate long lastOrdinalUsed
private static final Logger logger
OperationJournal(TransitionWatchers watchers)
OperationJournal
.watchers
- Set of watchers that need
to be asked if they are interested in the transitions.NullPointerException
- if watchers is null
.void recordTransition(EntryTransition transition)
contents
(including any subsidiary
objects such as the appropriate EntryHandle
).transition
- an object describing the visibility
transition of an entry.NullPointerException
- if transition
is
null
.void markCaughtUp(IfExistsWatcher watcher)
caughtUp
method
on the passed IfExistsWatcher
after the last
posted EntryTransition
is processed.watcher
- The watcher to notify when it is caught up.NullPointerException
- if watcher
is
null
.long currentOrdinal()
private void post(OperationJournal.JournalNode node)
JournalNode
node
- The node to post.OperationJournal.TransitionIterator newTransitionIterator()
EntryTransition
s added after
this point that have been processed.
We synchronize to make sure the initial state of the returned transition has been fetched from main memory.
EntryTransition
s added after
this point that have been processed.private OperationJournal.JournalNode lastProcessed(OperationJournal.JournalNode noEarlierThan)
TransitionWatchers
object
associated with this object before this call was made is
guaranteed to be asked by the journal about any transition posted
after the node returned by this method was posted.noEarlierThan
- The returned JournalNode
is guaranteed to have not been posted before
noEarlierThan
. If the last
node processes was posted before
noEarlierThan
, then
noEarlierThan
will be returned.void terminate()
public void run()
TransitionWatchers
object associated
with this object and then calling process on each
of the watchers.Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.