null
otherwise.
+ */
+ public MonitorInitializationException popPendingException() {
+ return pendingException.getAndSet(null);
+ }
}
protected boolean HARDWARE_FAULT=false;
protected final static boolean debug = false;
@@ -180,10 +204,14 @@ public RXTXPort( String name ) throws PortInUseException
monThread.setName("RXTXPortMonitor("+name+")");
monThread.start();
try {
- this.monitorThreadReady.await();
+ this.monitorThreadInitCompleted.await();
} catch (InterruptedException e) {
z.reportln("Interrupted while waiting for the monitor thread to start!");
}
+ MonitorInitializationException exception = monThread.popPendingException();
+ if (exception != null) {
+ throw exception;
+ }
this.monitorThreadState.writeLock().unlock();
// } catch ( PortInUseException e ){}
timeout = -1; /* default disabled timeout */
@@ -692,11 +720,16 @@ protected native int readTerminatedArray( byte b[], int off, int len, byte t[] )
private final Lock monitorThreadStateWriteLock = this.monitorThreadState.writeLock();
/**
- * Signalled by JNI code from inside {@link #eventLoop()} when the event
- * loop has finished initialization of the native data structures and is
- * ready to service events.
+ * Signalled by JNI code from inside {@link #eventLoop()} when the event + * loop has finished initialization of the native data structures.
+ * + *This either means that initialization was successful (and the + * event loop is ready to service events) or an exception occurred + * during initialization. + * In the latter case, {@link MonitorThread#pendingException} contains + * a non-null value.
*/ - private final Condition monitorThreadReady = this.monitorThreadState.writeLock().newCondition(); + private final Condition monitorThreadInitCompleted = this.monitorThreadState.writeLock().newCondition(); /** Process SerialPortEvents */ native void eventLoop(); @@ -911,10 +944,14 @@ public void addEventListener( monThread.setName("RXTXPortMonitor("+name+")"); monThread.start(); try { - this.monitorThreadReady.await(); + this.monitorThreadInitCompleted.await(); } catch (InterruptedException e) { z.reportln("Interrupted while waiting for the monitor thread to start!"); } + MonitorInitializationException exception = monThread.popPendingException(); + if (exception != null) { + throw exception; + } this.monitorThreadState.writeLock().unlock(); } if (debug) diff --git a/src/main/resources/com/neuronrobotics/nrjavaserial/build.properties b/src/main/resources/com/neuronrobotics/nrjavaserial/build.properties index 819b3ec7..f016b72e 100644 --- a/src/main/resources/com/neuronrobotics/nrjavaserial/build.properties +++ b/src/main/resources/com/neuronrobotics/nrjavaserial/build.properties @@ -1,2 +1,2 @@ app.name = nrjavaserial -app.version = 5.2.1+dbsystel2 +app.version = 5.2.1+dbsystel3