diff --git a/ch.psi.imagej.zeromq/pom.xml b/ch.psi.imagej.zeromq/pom.xml index 4274405..aa47210 100644 --- a/ch.psi.imagej.zeromq/pom.xml +++ b/ch.psi.imagej.zeromq/pom.xml @@ -3,7 +3,7 @@ 4.0.0 ch.psi.zmq ch.psi.zmq.imagej - 0.1.0 + 0.1.1 diff --git a/ch.psi.imagej.zeromq/src/main/java/ch/psi/zmq/imagej/ZeroMQViewer.java b/ch.psi.imagej.zeromq/src/main/java/ch/psi/zmq/imagej/ZeroMQViewer.java index 3de682b..cd90d35 100644 --- a/ch.psi.imagej.zeromq/src/main/java/ch/psi/zmq/imagej/ZeroMQViewer.java +++ b/ch.psi.imagej.zeromq/src/main/java/ch/psi/zmq/imagej/ZeroMQViewer.java @@ -35,6 +35,8 @@ public class ZeroMQViewer implements PlugIn { private static final Logger logger = Logger.getLogger(ZeroMQViewer.class.getName()); + private static final int HIGH_WATER_MARK = 10; + private ImagePlus img; private boolean flipX = false; @@ -96,6 +98,9 @@ public class ZeroMQViewer implements PlugIn { while (isPluginRunning) { semaphore.acquire(); + if(!isPluginRunning){ // if plugin was terminated while waiting for the semaphore exit loop + break; + } collect=true; hinfo.setVisible(true); try{ @@ -107,8 +112,7 @@ public class ZeroMQViewer implements PlugIn { int port = Integer.parseInt(textPort.getText()); String method = (String) comboBoxMethod.getSelectedItem(); - - context = ZMQ.context(1); + context = ZMQ.context(); if(method.equals("PULL")){ socket = context.socket(ZMQ.PULL); } @@ -120,6 +124,7 @@ public class ZeroMQViewer implements PlugIn { logger.severe("Method not supported"); collect=false; } + socket.setHWM(HIGH_WATER_MARK); socket.connect("tcp://"+hostname+":"+port); logger.info("Connected to: tcp://"+hostname+":"+port); @@ -152,7 +157,9 @@ public class ZeroMQViewer implements PlugIn { timer.stop(); - img.close(); + if(img!=null){ + img.close(); + } frame.setVisible(false); IJ.showStatus("Exiting ZeroMQ Viewer"); @@ -403,6 +410,7 @@ public class ZeroMQViewer implements PlugIn { public class FrameExitListener extends WindowAdapter { public void windowClosing(WindowEvent event) { isPluginRunning = false; + semaphore.release(); // release the wait semaphore in case the plugin is stucked in there. } } }