4 modified files
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/MonitoringApplication.java 2014-06-14 17:36:50 UTC (rev 712)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/gui/MonitoringApplication.java 2014-06-16 13:04:31 UTC (rev 713)
@@ -146,6 +146,8 @@
private JobControlManager jobManager;
private LCSimEventBuilder eventBuilder;
private EventProcessingThread eventProcessingThread;
+
+ private Thread sessionThread;
// Job timing.
private Timer timer;
@@ -1139,6 +1141,10 @@
// Start the event processing thread.
eventProcessingThread.start();
+ // Start thread which will trigger disconnect if event processing thread finishes.
+ sessionThread = new SessionThread();
+ sessionThread.start();
+
// Start the session timer.
startSessionTimer();
@@ -1608,44 +1614,79 @@
* Stop the session by stopping the event processing thread, ending the job,
* and disconnecting from the ET system.
*/
- private void stopSession() {
+ // FIXME: Needs to be synchronized?
+ private synchronized void stopSession() {
- Runnable runnable = new Runnable() {
+ //Runnable runnable = new Runnable() {
+ //public void run() {
- public void run() {
+ logger.log(Level.INFO, "Stopping session.");
- logger.log(Level.INFO, "Stopping session.");
+ // Request event processing to stop.
+ // TODO: I think this check should be replaced with ...
+ // eventProcessingThread.isAlive()
+ if (!eventProcessing.isDone()) {
+
+ //System.out.println("interrupting session thread");
+
+ // Interrupt the session thread because if processing is still happening,
+ // then we didn't get here through that thread.
+ sessionThread.interrupt();
+
+ //System.out.println("finishing event processing");
- // Request event processing to stop.
- eventProcessing.finish();
+ // Request processing to stop.
+ eventProcessing.finish();
+ }
- // Wait for the event processing thread to finish.
- try {
- logger.log(Level.FINER, "Waiting for event processing to finish before disconnecting.");
- eventProcessingThread.join();
- logger.log(Level.FINER, "Event processing finished.");
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ // Wait for the event processing thread to finish.
+ try {
+ //logger.log(Level.FINER, "Waiting for event processing to finish before disconnecting.");
+ //System.out.println("Waiting for event processing to finish before disconnecting.");
+ eventProcessingThread.join();
+ //System.out.println("Event processing finished.");
+ //logger.log(Level.FINER, "Event processing finished.");
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
- // Reset event processing objects.
- eventProcessing = null;
- eventProcessingThread = null;
+ // Reset event processing objects.
+ eventProcessing = null;
+ eventProcessingThread = null;
- // Perform various end of job cleanup.
- endJob();
+ // Perform various end of job cleanup.
+ endJob();
- // Disconnect from the ET server.
- disconnect();
+ // Disconnect from the ET server.
+ //System.out.println("disconnecting from ET ...");
+ disconnect();
+ //System.out.println("done disconnecting");
- // Stop the session timer.
- stopSessionTimer();
-
- logger.log(Level.INFO, "Session done.");
- }
- };
+ // Stop the session timer.
+ stopSessionTimer();
- Thread thread = new Thread(runnable);
- thread.start();
+ sessionThread = null;
+
+ logger.log(Level.INFO, "Session done.");
+ //}
+ //};
+
+ //Thread thread = new Thread(runnable);
+ //thread.start();
+
}
+
+ /**
+ * Thread to automatically trigger a disconnect when the event processing chain finishes.
+ */
+ class SessionThread extends Thread {
+ public void run() {
+ try {
+ eventProcessingThread.join();
+ actionListener.actionPerformed(new ActionEvent(Thread.currentThread(), 0, MonitoringCommands.DISCONNECT));
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
}
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EventProcessingChain.java 2014-06-14 17:36:50 UTC (rev 712)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/EventProcessingChain.java 2014-06-16 13:04:31 UTC (rev 713)
@@ -10,6 +10,8 @@
import java.util.Collection;
import java.util.List;
+import org.freehep.record.loop.AbstractLoopListener;
+import org.freehep.record.loop.LoopEvent;
import org.freehep.record.loop.RecordLoop.Command;
import org.freehep.record.source.NoSuchRecordException;
import org.freehep.record.source.RecordSource;
@@ -48,7 +50,7 @@
*
* @author Jeremy McCormick <[log in to unmask]>
*/
-public class EventProcessingChain {
+public class EventProcessingChain extends AbstractLoopListener {
/**
* Type of source for events.
@@ -99,6 +101,8 @@
public void configure() {
+ compositeLoop.addLoopListener(this);
+
if (recordSource == null)
throw new RuntimeException("No record source was set.");
@@ -126,7 +130,7 @@
compositeLoop.addProcessingSteps(processingSteps);
compositeLoop.registerRecordLoop(etLoop);
compositeLoop.registerRecordLoop(evioLoop);
- compositeLoop.registerRecordLoop(lcsimLoop);
+ compositeLoop.registerRecordLoop(lcsimLoop);
}
void setSourceType(SourceType sourceType) {
@@ -239,10 +243,29 @@
this.paused = false;
}
+ public void suspend(LoopEvent loopEvent) {
+ System.out.println(this.getClass().getSimpleName() + ".suspend");
+ System.out.println("Error occurred ...");
+ if (loopEvent.getException() != null)
+ loopEvent.getException().printStackTrace();
+ this.isDone = true;
+ }
+
+ // TODO: EventProcessingChain should be registered as an AbstractLoopListener on the composite loop.
+ // This way it can catch processing errors and set the done state.
public void loop() {
while (!isDone) {
+ System.out.println("not done...");
if (!paused) {
+ //System.out.println("doing compositeLoop.execute ...");
compositeLoop.execute(Command.GO, false);
+ //System.out.println("done with compositeLoop.execute");
+ //System.out.println("Errors ...");
+ //if (compositeLoop.getProgress().getException() != null) {
+ // System.out.println(compositeLoop.getProgress().getException().getMessage());
+ //} else {
+ // System.out.println("none");
+ //}
}
}
}
@@ -258,6 +281,7 @@
}
public void next() {
+ // TODO: Add check here for correct loop state.
compositeLoop.execute(Command.GO_N, 1L, true);
}
@@ -282,6 +306,7 @@
* Load the next <tt>EtEvent</tt>.
*/
public void execute() throws IOException, NoSuchRecordException {
+
// Load the next EtEvent.
etLoop.execute(NEXT);
@@ -290,7 +315,8 @@
// Failed to read an EtEvent from the ET server.
if (nextEtEvent == null)
- throw new NoSuchRecordException("No current EtEvent is available.");
+ //throw new NoSuchRecordException("No current EtEvent is available.");
+ throw new IOException("No current EtEvent is available.");
getCompositeRecord().setEtEvent(nextEtEvent);
}
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite/CompositeRecordLoopAdapter.java 2014-06-14 17:36:50 UTC (rev 712)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite/CompositeRecordLoopAdapter.java 2014-06-16 13:04:31 UTC (rev 713)
@@ -14,11 +14,13 @@
List<RecordLoop> registeredLoops = new ArrayList<RecordLoop>();
- public void finish(LoopEvent event) {
+ public void finish(LoopEvent loopEvent) {
System.out.println("CompositeRecordLoopAdapter.finish");
for (RecordLoop loop : registeredLoops) {
loop.execute(Command.STOP);
}
+ if (loopEvent.getException() != null)
+ loopEvent.getException().printStackTrace();
}
void registerRecordLoop(RecordLoop loop) {
@@ -32,6 +34,13 @@
}
}
*/
+
+ // NOTE: IOExceptions from loop processing show up here!!!
+ public void suspend(LoopEvent loopEvent) {
+ System.out.println("CompositeRecordLoopAdapter.suspend");
+ if (loopEvent.getException() != null)
+ loopEvent.getException().printStackTrace();
+ }
@Override
public void recordSupplied(RecordEvent record) {
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite/CompositeRecordSource.java 2014-06-14 17:36:50 UTC (rev 712)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/record/composite/CompositeRecordSource.java 2014-06-16 13:04:31 UTC (rev 713)
@@ -18,16 +18,15 @@
currentRecord = new CompositeRecord();
// Execute sub-processing that will alter the CompositeRecord.
- // FIXME: Should this happen here???
for (EventProcessingStep step : this.processingSteps) {
- try {
- step.execute();
- } catch (Exception e) {
- System.out.println("Exception " + e.getClass().getCanonicalName() + " caught from " + step.getClass().getCanonicalName() + ".");
- System.out.println(e.getMessage());
- currentRecord = null;
- throw e;
- }
+ //try {
+ step.execute();
+ //} catch (Exception e) {
+ // System.out.println("Exception " + e.getClass().getCanonicalName() + " caught from " + step.getClass().getCanonicalName() + ".");
+ // System.out.println(e.getMessage());
+ // currentRecord = null;
+ // throw e;
+ //}
}
}
SVNspam 0.1