}
public void run() {
log.entering(getClass().getName(), "run");
JGDI jgdi = null;
try {
setState(State.STARTING);
jgdi = JGDIFactory.newInstance(url);
log.log(Level.FINER, "calling initNative({0})", regId);
evcIndex = initNative(jgdi, regId);
log.log(Level.FINER, "calling registerNative({0})", evcIndex);
int id = registerNative(evcIndex);
log.log(Level.FINER, "event client registered (id={0})", id);
lock.lock();
try {
this.evcId = id;
} finally {
lock.unlock();
}
setState(State.RUNNING);
boolean gotShutdownEvent = false;
List<Event> eventList = new ArrayList<Event>();
while (true) {
if (Thread.currentThread().isInterrupted()) {
log.log(Level.FINE, "event loop has been interrupted");
break;
}
if (gotShutdownEvent) {
break;
}
doCommit(evcIndex);
log.log(Level.FINER, "calling native method fillEvents for event client {0}", evcId);
fillEvents(evcIndex, eventList);
if (log.isLoggable(Level.FINER)) {
log.log(Level.FINE, "got {0} events from qmaster for event client {1}",
new Object[]{eventList.size(), evcId});
}
if (Thread.currentThread().isInterrupted()) {
log.log(Level.FINE, "event loop has been interrupted");
break;
}
for (Event event : eventList) {
try {
fireEventOccured(event);
if (event instanceof QmasterGoesDownEvent || event instanceof ShutdownEvent) {
if (gotShutdownEvent == false) {
log.log(Level.FINE, "got shutdown event");
gotShutdownEvent = true;
}
}
} catch (Exception e) {
log.log(Level.WARNING, "error in fire event", e);
}
}
eventList.clear();
}
} catch (JGDIException ex) {
error(ex);
} catch (Throwable ex) {
error(new JGDIException(ex, "Unknown error in event loop"));
} finally {
setState(State.STOPPING);
if (evcIndex >= 0) {
try {
closeNative(evcIndex);
} catch (Exception ex) {
// Ignore
} finally {
evcIndex = -1;
}
}
if (jgdi != null) {
try {
jgdi.close();
} catch (Exception ex) {
// Igore
}
}
setState(State.STOPPED);