public class ClientEventPoll extends Thread
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:
RemoteObservationManager
class.
EventListener
s registered with this class must properly
implement the Object.hashCode()
and Object.equals()
contracts for them to be handled correctly by this class.
run()
Thread.State, Thread.UncaughtExceptionHandler
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
ClientEventPoll(RemoteObservationManager remote,
Session session)
Creates an instance of this class talking to the given
RemoteObservationManager . |
Modifier and Type | Method and Description |
---|---|
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. |
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
public ClientEventPoll(RemoteObservationManager remote, Session session) throws NullPointerException
RemoteObservationManager
.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
.NullPointerException
- if remote
or session
is null
.public long addListener(EventListener listener)
listener
- The EventListener
to register.public long removeListener(EventListener listener)
listener
- The EventListener
to unregister.-1
if the listener was not registered.public EventListener[] getListeners()
public void terminate()
run()
method, that asking for events should
be terminated.run()
public void run()
terminate()
has not been called
yet and the session is still alive.
RemoteObservationManager.getNextEvent(long)
method
waiting for a specified time (5 seconds).
EventIterator
and
call the EventListener.onEvent()
method.
Copyright © 2004–2021 The Apache Software Foundation. All rights reserved.