abstract class QueryWatcher extends TransitionWatcher
TransitionWatcher for blocking queries.
QueryWatchers are waiting for a set of conditions (time,
transitions, etc.) that will resolve the query. Threads can
block on resolution by calling the waitOnResolution method.
Once waitOnResolution than can use subclass specific
methods to obtain the result.
Resolution may involve capturing one or more entries (that
is locking or removing an entry from the space). It is important
that a QueryWatcher never capture an entry after the
watcher enters the resolved state, since that could allow a caller
to believe that the call failed, when it fact it locked or removed
an entry and/or in entries being removed/locked that are never
returned to the client. Put another way, the decision to capture an
entry has to be done atomically with the check that ensures that
the related query is still unresolved.
| Modifier and Type | Field and Description |
|---|---|
private long |
expiration
When this query ends
|
startOrdinal| Constructor and Description |
|---|
QueryWatcher(long expiration,
long timestamp,
long startOrdinal)
Create a new
QueryWatcher. |
| Modifier and Type | Method and Description |
|---|---|
(package private) abstract boolean |
catchUp(EntryTransition transition,
long now)
Process a transition which was posted before the watcher was
placed in
TransitionWatchers object. |
long |
getExpiration()
Get the expiration time of this object.
|
(package private) abstract boolean |
isResolved()
Returns
true if this query has been resolved. |
(package private) void |
removeIfExpired(long now)
This method does nothing.
|
(package private) abstract void |
waitOnResolution()
Block until the query this object represents is resolved.
|
addTemplateHandle, compareTo, isInterested, processQueryWatcher(long expiration,
long timestamp,
long startOrdinal)
QueryWatcher.expiration - the initial expiration time
for this QueryWatcher in
milliseconds since the beginning of the epoch.timestamp - the value that is used
to sort TransitionWatchers.startOrdinal - the highest ordinal associated
with operations that are considered to have occurred
before the operation associated with this watcher.public long getExpiration()
TransitionWatcheraddTemplateHandle is called.
Assumes locking is handled by the caller.getExpiration in class TransitionWatcherabstract boolean catchUp(EntryTransition transition, long now)
TransitionWatchers object. Assumes that
the entry in the transition matches matches the template in the
TemplateHandle associated with this watcher. Does
not assume isInterested has been called.transition - A EntryTransition that
describes the transition and what
entry is transitioning. This method
will assume that transition.getHandle
returns a non-null value.now - An estimate of the current time (not the time
when the event occured).true if the query has been resolved, and
false otherwise. Note, even if this
call returns true, waitOnResolution
must still be called.NullPointerException - if transition is
null.void removeIfExpired(long now)
QueryWatcher
has a thread that blocks until the expiration time is reached
it simpler to do the removal there instead of in the
reaping thread.removeIfExpired in class TransitionWatchernow - An estimate of the current time that must be
less than or equal to the current time.abstract void waitOnResolution()
throws InterruptedException
InterruptedExceptionabstract boolean isResolved()
true if this query has been resolved. If the
calling thread is owns the lock on this object the answer is
definitive. If the lock is not held only a true answer
can be considered definitive.true if the query has been
resolved, false otherwise.Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.