*/
public void run() {
while (running && session.isLive()) {
try {
// ask for an event waiting at most POLL_TIMEOUT milliseconds
RemoteEventCollection remoteEvent = remote.getNextEvent(POLL_TIMEOUT);
// poll time out, check running and ask again
if (remoteEvent == null) {
continue;
}
// extract the listener id from the remote event and find
// the locally registered event listener
Long id = new Long(remoteEvent.getListenerId());
EventListener listener = (EventListener) listenerMap.get(id);
// if the listener is not registered (anymore), the event is
// silently ignored, running is checked and the server asked again
if (listener == null) {
continue;
}
// otherwise convert the remote events into an EventIterator
// and the listener is called
RemoteEventCollection.RemoteEvent[] remoteEvents = remoteEvent.getEvents();
EventIterator events = toEvents(remoteEvents);
try {
listener.onEvent(events);
} catch (Exception e) {
log.error("Unexpected failure of Listener " + listener, e);