com.sun.jini.outrigger
Class OperationJournal

java.lang.Object
  extended by java.lang.Thread
      extended by com.sun.jini.outrigger.OperationJournal
All Implemented Interfaces:
Runnable

 class OperationJournal
extends Thread

Maintain a journal of operations on entries (writes, takes, and resolution of locks) and a thread that will process the journal. This journal is kept for three reasons. One is so events can be generated asynchronously from the writes and transaction commits that cause them. Second so blocked queries can be alerted to changes that will allow them to be resolved.

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.


Nested Class Summary
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 EntryTransitions added after the iterator was created and processed before watcherRegistered was called.
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
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
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
OperationJournal(TransitionWatchers watchers)
          Create a new OperationJournal.
 
Method Summary
(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 EntryTransitions 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.
 
Methods inherited from class java.lang.Thread
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
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

watchers

private final TransitionWatchers watchers
The object to ask about who is interested in a transition


tail

private OperationJournal.JournalNode tail
The current tail of the transitions list.


lastProcessed

private OperationJournal.JournalNode lastProcessed
The JournalNode we are currently processing or if none are in process the last one we processed.


dead

private boolean dead
If true stop thread


lastOrdinalUsed

private long lastOrdinalUsed
The last ordinal value used


logger

private static final Logger logger
Logger for logging exceptions

Constructor Detail

OperationJournal

OperationJournal(TransitionWatchers watchers)
Create a new OperationJournal.

Parameters:
watchers - Set of watchers that need to be asked if they are interested in the transitions.
Throws:
NullPointerException - if watchers is null.
Method Detail

recordTransition

void recordTransition(EntryTransition transition)
Records an operation on an entry. This method should be called after the transition has been made visible in contents (including any subsidiary objects such as the appropriate EntryHandle).

Parameters:
transition - an object describing the visibility transition of an entry.
Throws:
NullPointerException - if transition is null.

markCaughtUp

void markCaughtUp(IfExistsWatcher watcher)
Schedules a job that will call the caughtUp method on the passed IfExistsWatcher after the last posted EntryTransition is processed.

Parameters:
watcher - The watcher to notify when it is caught up.
Throws:
NullPointerException - if watcher is null.

currentOrdinal

long currentOrdinal()
Return the ordinal of the last operation posted. Any operations with a higher ordinal should be considered to have taken place after this point in time.

Returns:
the ordinal of the last operation posted.

post

private void post(OperationJournal.JournalNode node)
Post a JournalNode

Parameters:
node - The node to post.

newTransitionIterator

OperationJournal.TransitionIterator newTransitionIterator()
Return an iterator that can latter be used to get all the EntryTransitions 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.

Returns:
An iterator that can latter be used to get all the EntryTransitions added after this point that have been processed.

lastProcessed

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. A watcher that was added to the 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.

Parameters:
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.
Returns:
The last node that has been at least partially processed.

terminate

void terminate()
Terminate queue processing.


run

public 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.

Specified by:
run in interface Runnable
Overrides:
run in class Thread


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.