4 modified files
java/trunk/record-util/src/main/java/org/hps/record/composite
--- java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoop.java 2014-08-30 01:19:10 UTC (rev 931)
+++ java/trunk/record-util/src/main/java/org/hps/record/composite/CompositeLoop.java 2014-08-30 01:48:16 UTC (rev 932)
@@ -5,17 +5,7 @@
import org.freehep.record.source.RecordSource;
import org.hps.record.EndRunException;
import org.hps.record.MaxRecordsException;
-import org.jlab.coda.et.exception.EtBusyException;
-import org.jlab.coda.et.exception.EtClosedException;
-import org.jlab.coda.et.exception.EtDeadException;
-import org.jlab.coda.et.exception.EtEmptyException;
-import org.jlab.coda.et.exception.EtException;
-import org.jlab.coda.et.exception.EtExistsException;
-import org.jlab.coda.et.exception.EtReadException;
-import org.jlab.coda.et.exception.EtTimeoutException;
-import org.jlab.coda.et.exception.EtTooManyException;
-import org.jlab.coda.et.exception.EtWakeUpException;
-import org.jlab.coda.et.exception.EtWriteException;
+import org.hps.record.et.EtSource.EtSourceException;
/**
* Implementation of a composite record loop for processing
@@ -64,30 +54,32 @@
* only non-fatal record processing exceptions are ignored.
*/
protected void handleClientError(Throwable x) {
- // Print full error traceback.
- x.printStackTrace();
// Is the error ignorable?
if (isIgnorable(x)) {
- // We can return.
+ // Ignore the error!
return;
}
+ // Set the exception on the super class.
+ this._exception = x;
+
// Stop the event processing.
this.execute(Command.STOP);
done = true;
}
protected void handleSourceError(Throwable x) {
-
- // Print full error traceback.
- x.printStackTrace();
-
+
// Is the error ignorable?
if (isIgnorable(x)) {
+ // Ignore the error!
return;
}
+ // Set the exception on the super class.
+ this._exception = x;
+
// Stop the event processing.
this.execute(Command.STOP);
done = true;
@@ -95,60 +87,46 @@
private boolean isIgnorable(Throwable x) {
- // EndRunExceptions are never ignored.
- if (x.getCause() instanceof EndRunException)
- return false;
+ // Should the loop try to recover from the error if possible?
+ if (!stopOnErrors) {
- // MaxRecordsExceptions are never ignored.
- if (x.getCause() instanceof MaxRecordsException)
- return false;
+ // EndRunExceptions are never ignored.
+ if (x.getCause() instanceof EndRunException)
+ return false;
- // ET system errors are always considered fatal.
- if (isEtError((Exception) x.getCause()))
- return false;
+ // MaxRecordsExceptions are never ignored.
+ if (x.getCause() instanceof MaxRecordsException)
+ return false;
- // Should the loop try to recover from the error?
- if (!stopOnErrors) {
- // Is the cause of the error ignorable?
- if (!(x.getCause() instanceof IllegalStateException)
- && !(x.getCause() instanceof NoSuchRecordException))
- // Ignore the error.
- return true;
- }
+ // ET system errors are always considered fatal.
+ if (x.getCause() instanceof EtSourceException)
+ return false;
- // Error is not ignorable.
- return false;
- }
-
- /**
- * True if the Exception is from the ET system.
- * @param e The Exception that was thrown.
- * @return True if the Exception is from the ET system.
- */
- private boolean isEtError(Exception e) {
- // Get the actual cause e.g. from
- // RecordProcessingException -> IOException -> EtException
- // which originates from EtRecordSource.
- Throwable t = e.getCause().getCause();
- if ((t instanceof EtBusyException) ||
- (t instanceof EtClosedException) ||
- (t instanceof EtDeadException) ||
- (t instanceof EtEmptyException) ||
- (t instanceof EtException) ||
- (t instanceof EtExistsException) ||
- (t instanceof EtReadException) ||
- (t instanceof EtTimeoutException) ||
- (t instanceof EtTooManyException) ||
- (t instanceof EtWakeUpException) ||
- (t instanceof EtWriteException)) {
+ // The NoSuchRecordException indicates a RecordSource
+ // was exhausted so processing needs to end.
+ if (x.getCause() instanceof NoSuchRecordException)
+ return false;
+
+ // When this occurs on of the loops is probably messed up,
+ // so it is not considered recoverable.
+ if (x.getCause() instanceof IllegalStateException)
+ return false;
+
+ // Ignore the error.
return true;
- } else {
+
+ } else {
+ // Error is not ignored.
return false;
- }
+ }
}
-
+
public boolean isDone() {
return done;
}
+
+ public Throwable getLastError() {
+ return _exception;
+ }
}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/et
--- java/trunk/record-util/src/main/java/org/hps/record/et/EtSource.java 2014-08-30 01:19:10 UTC (rev 931)
+++ java/trunk/record-util/src/main/java/org/hps/record/et/EtSource.java 2014-08-30 01:48:16 UTC (rev 932)
@@ -94,7 +94,13 @@
EtEvent[] mevs = connection.readEtEvents();
eventQueue.addAll(Arrays.asList(mevs));
} catch (Exception e) {
- throw new IOException("Error while reading ET events.", e);
+ throw new EtSourceException("Error while reading ET events.", e);
}
}
+
+ public static class EtSourceException extends IOException {
+ public EtSourceException(String message, Exception cause) {
+ super(message, cause);
+ }
+ }
}
\ No newline at end of file
java/trunk/record-util/src/main/java/org/hps/record/evio
--- java/trunk/record-util/src/main/java/org/hps/record/evio/EvioAdapter.java 2014-08-30 01:19:10 UTC (rev 931)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/EvioAdapter.java 2014-08-30 01:48:16 UTC (rev 932)
@@ -8,6 +8,7 @@
import org.freehep.record.loop.RecordEvent;
import org.freehep.record.loop.RecordListener;
import org.hps.evio.EventConstants;
+import org.hps.record.RecordProcessingException;
import org.jlab.coda.jevio.EvioEvent;
/**
@@ -55,12 +56,8 @@
@Override
public void suspend(LoopEvent event) {
- System.out.println("EvioAdapter.suspend");
- if (event.getException() != null) {
- for (EvioProcessor processor : processors) {
- processor.endJob();
- }
- }
+ if (event.getException() != null)
+ throw new RecordProcessingException("EVIO error.", event.getException());
}
private void processEvent(EvioEvent event) {
java/trunk/record-util/src/main/java/org/hps/record/processing
--- java/trunk/record-util/src/main/java/org/hps/record/processing/ProcessingChain.java 2014-08-30 01:19:10 UTC (rev 931)
+++ java/trunk/record-util/src/main/java/org/hps/record/processing/ProcessingChain.java 2014-08-30 01:48:16 UTC (rev 932)
@@ -3,8 +3,6 @@
import java.io.File;
import java.io.IOException;
-import org.freehep.record.loop.AbstractLoopListener;
-import org.freehep.record.loop.LoopEvent;
import org.freehep.record.loop.RecordLoop.Command;
import org.hps.record.composite.CompositeLoop;
import org.hps.record.composite.CompositeProcessor;
@@ -31,10 +29,8 @@
* can be registered with the three different loops for processing the different
* record types, in order to plot, update a GUI component, or analyze the events.
*/
-public class ProcessingChain extends AbstractLoopListener {
+public class ProcessingChain {
- protected int totalEventsProcessed;
- protected Throwable lastError;
protected boolean paused;
protected int maxRecords = -1;
@@ -52,10 +48,7 @@
}
private void configure(ProcessingConfiguration configuration) {
-
- // Add this class as a loop listener.
- compositeLoop.addLoopListener(this);
-
+
// Was there no RecordSource provided explicitly?
if (configuration.recordSource == null) {
// Using an ET server connection?
@@ -180,19 +173,8 @@
public void resume() {
this.paused = false;
}
-
+
/**
- * Suspend event processing e.g. when pausing.
- * @param loopEvent The loop event.
- */
- public void suspend(LoopEvent loopEvent) {
- if (loopEvent.getException() != null) {
- loopEvent.getException().printStackTrace();
- lastError = (Exception) loopEvent.getException();
- }
- }
-
- /**
* Loop over events until processing ends for some reason.
*/
public void run() {
@@ -200,39 +182,32 @@
while (true) {
// Is the processing unpaused?
if (!paused) {
- try {
- // Put the RecordLoop into looping mode and process records until Exception occurs
- // or processing finishes.
- compositeLoop.execute(Command.GO, true);
- } catch (Exception exception) {
- // Handle exceptions, which might really just be control flow like end or run, etc.
- setLastError(exception);
- }
+ // Loop until done or error occurs.
+ compositeLoop.execute(Command.GO, true);
+ if (compositeLoop.getLastError() != null)
+ System.out.println("loop error: " + compositeLoop.getLastError().getMessage());
if (compositeLoop.isDone()) {
+ // Break from processing loop.
break;
}
}
+ // FIXME: Should this thread sleep for a bit here?
}
}
+ /**
+ * Stop the event processing by halting the loop.
+ */
public void stop() {
compositeLoop.execute(Command.STOP);
}
-
+
/**
- * Set the last error that occurred during processing.
- * @param error The last error that occurred.
- */
- void setLastError(Throwable error) {
- this.lastError = error;
- }
-
- /**
* Get the last error that occurred.
* @return The last error that occurred.
*/
public Throwable getLastError() {
- return lastError;
+ return compositeLoop.getLastError();
}
/**
@@ -248,13 +223,5 @@
*/
public void next() {
compositeLoop.execute(Command.GO_N, 1L, true);
- }
-
- /**
- * Get the total number of events processed.
- * @return The number of events processed.
- */
- public int getTotalEventsProcessed() {
- return this.totalEventsProcessed;
- }
+ }
}
\ No newline at end of file
SVNspam 0.1