org.apache.jackrabbit.rmi.observation
Class ClientEventPoll

java.lang.Object
  extended by java.lang.Thread
      extended by org.apache.jackrabbit.rmi.observation.ClientEventPoll
All Implemented Interfaces:
Runnable

public class ClientEventPoll
extends Thread

The ClientEventPoll class is the registry for client-side event listeners on behalf of the ClientObservationManager class. In addition this class extends the java.lang.Thread class able to be run in a separate thread to constantly poll the server-side observation manager for new events.

Notes:

  1. Only one instance of this class should be instantiated for each instance of a RemoteObservationManager class.
  2. EventListeners registered with this class must properly implement the Object.hashCode() and Object.equals() contracts for them to be handled correctly by this class.

See Also:
run()

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ClientEventPoll(RemoteObservationManager remote, Session session)
          Creates an instance of this class talking to the given RemoteObservationManager.
 
Method Summary
 long addListener(EventListener listener)
          Registers the given local listener with this instance and returns the unique identifier assigned to it.
 EventListener[] getListeners()
          Returns an array of the registered event listeners.
 long removeListener(EventListener listener)
          Unregisters the given local listener from this instance and returns the unique identifier assigned to it.
 void run()
          Checks for remote events and dispatches them to the locally registered event listeners.
 void terminate()
          Indicates to the run() method, that asking for events should be terminated.
 
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
 

Constructor Detail

ClientEventPoll

public ClientEventPoll(RemoteObservationManager remote,
                       Session session)
                throws NullPointerException
Creates an instance of this class talking to the given RemoteObservationManager.

Parameters:
remote - The remote observation manager which is asked for new events. This must not be null.
session - The Session which is asked whether it is alive by the run() method. This must not be null.
Throws:
NullPointerException - if remote or session is null.
Method Detail

addListener

public long addListener(EventListener listener)
Registers the given local listener with this instance and returns the unique identifier assigned to it.

Parameters:
listener - The EventListener to register.
Returns:
The unique identifier assigned to the newly registered event listener.

removeListener

public long removeListener(EventListener listener)
Unregisters the given local listener from this instance and returns the unique identifier assigned to it.

Parameters:
listener - The EventListener to unregister.
Returns:
The unique identifier assigned to the unregistered event listener or -1 if the listener was not registered.

getListeners

public EventListener[] getListeners()
Returns an array of the registered event listeners.

Returns:
registered event listeners

terminate

public void terminate()
Indicates to the run() method, that asking for events should be terminated.

See Also:
run()

run

public void run()
Checks for remote events and dispatches them to the locally registered event listeners. This is how this method works:
  1. Continue with next step if terminate() has not been called yet and the session is still alive.
  2. Call the RemoteObservationManager.getNextEvent(long) method waiting for a specified time (5 seconds).
  3. If no event was received in the specified time go back to step #1.
  4. Extract the unique listener identifier from the remote event and find it in the list of locally registered event listeners. Go back to step #1 if no such listener exists.
  5. Convert the remote event list to an EventIterator and call the EventListener.onEvent() method.
  6. Go back to step #1.

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


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.