--- /dev/null
+package uk.ac.vamsas.client.simpleclient;\r
+\r
+import org.apache.commons.logging.*;\r
+\r
+import uk.ac.vamsas.client.picking.IMessageHandler;\r
+import uk.ac.vamsas.client.picking.IPickManager;\r
+import uk.ac.vamsas.client.picking.Message;\r
+import uk.ac.vamsas.client.picking.SocketManager;\r
+/**\r
+ * Blocking message handler\r
+ * @author\r
+ *\r
+ */\r
+public class SimplePickManager implements IPickManager {\r
+ private Log log = LogFactory.getLog(SimplePickManager.class);\r
+ \r
+ SocketManager manager=null;\r
+ SimplePickManager(SocketManager manager) {\r
+ this.manager=manager;\r
+ final SimplePickManager me=this;\r
+ /**\r
+ * add a handler that calls the SimplePickManager message handler\r
+ */\r
+ manager.registerMessageHandler(new IMessageHandler() {\r
+ public void handleMessage(Message message) {\r
+ me.handleMessage(message);\r
+ }\r
+ });\r
+ \r
+ }\r
+ /**\r
+ * when false, messages are queued in a FIFO until thread can restart.\r
+ */\r
+ private boolean passThru=true;\r
+ /**\r
+ * the client apps message handler\r
+ */\r
+ IMessageHandler pickHandler=null;\r
+ public void registerMessageHandler(IMessageHandler handler) {\r
+ pickHandler=handler; \r
+ \r
+ }\r
+\r
+ public void sendMessage(Message message) {\r
+ manager.sendMessage(message);\r
+ }\r
+ /**\r
+ * pass message onto the Apps handler, or wait until\r
+ * passThru is true before passing message on.\r
+ * @param message\r
+ */\r
+ protected void handleMessage(Message message) {\r
+ while (!passThru) {\r
+ try {\r
+ Thread.sleep(5);\r
+ } catch (InterruptedException e) {};\r
+ }\r
+ if (passThru)\r
+ pickHandler.handleMessage(message);\r
+ }\r
+\r
+ /**\r
+ * @return true if messages are being passed to handlers\r
+ */\r
+ public boolean isPassThru() {\r
+ return passThru;\r
+ }\r
+\r
+ /**\r
+ * @param true to pass messages on to handlers, false to hold messages in queue\r
+ */\r
+ public void setPassThru(boolean passThru) {\r
+ this.passThru = passThru;\r
+ }\r
+ public void haltPickManager() {\r
+ // TODO: FIX haltPickManager to cleanly end after SimpleClient.finalize() is called\r
+ manager.haltManager();\r
+ \r
+ }\r
+}\r