From ae73be36a711c290fb25c4112a8e01d75bc74abe Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 12 Jan 2007 15:26:43 +0000 Subject: [PATCH] wrapper for conditionally passing picks onto the client application git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@333 be28352e-c001-0410-b1a7-c7978e42abec --- .../client/simpleclient/SimplePickManager.java | 80 ++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java diff --git a/src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java b/src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java new file mode 100644 index 0000000..7b33f48 --- /dev/null +++ b/src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java @@ -0,0 +1,80 @@ +package uk.ac.vamsas.client.simpleclient; + +import org.apache.commons.logging.*; + +import uk.ac.vamsas.client.picking.IMessageHandler; +import uk.ac.vamsas.client.picking.IPickManager; +import uk.ac.vamsas.client.picking.Message; +import uk.ac.vamsas.client.picking.SocketManager; +/** + * Blocking message handler + * @author + * + */ +public class SimplePickManager implements IPickManager { + private Log log = LogFactory.getLog(SimplePickManager.class); + + SocketManager manager=null; + SimplePickManager(SocketManager manager) { + this.manager=manager; + final SimplePickManager me=this; + /** + * add a handler that calls the SimplePickManager message handler + */ + manager.registerMessageHandler(new IMessageHandler() { + public void handleMessage(Message message) { + me.handleMessage(message); + } + }); + + } + /** + * when false, messages are queued in a FIFO until thread can restart. + */ + private boolean passThru=true; + /** + * the client apps message handler + */ + IMessageHandler pickHandler=null; + public void registerMessageHandler(IMessageHandler handler) { + pickHandler=handler; + + } + + public void sendMessage(Message message) { + manager.sendMessage(message); + } + /** + * pass message onto the Apps handler, or wait until + * passThru is true before passing message on. + * @param message + */ + protected void handleMessage(Message message) { + while (!passThru) { + try { + Thread.sleep(5); + } catch (InterruptedException e) {}; + } + if (passThru) + pickHandler.handleMessage(message); + } + + /** + * @return true if messages are being passed to handlers + */ + public boolean isPassThru() { + return passThru; + } + + /** + * @param true to pass messages on to handlers, false to hold messages in queue + */ + public void setPassThru(boolean passThru) { + this.passThru = passThru; + } + public void haltPickManager() { + // TODO: FIX haltPickManager to cleanly end after SimpleClient.finalize() is called + manager.haltManager(); + + } +} -- 1.7.10.2