From ac9fee0c47d0e616d5ba16ad6ded2354e3fe1a5d Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 15 Mar 2007 14:48:20 +0000 Subject: [PATCH] Messages are thrown away when passThru is false (rather than receiver thread sleeping). Better shutdown behaviour (thread references are nulled) git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@361 be28352e-c001-0410-b1a7-c7978e42abec --- .../client/simpleclient/SimplePickManager.java | 25 ++++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java b/src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java index 376662c..5f92d37 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java +++ b/src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java @@ -33,6 +33,10 @@ public class SimplePickManager implements IPickManager { */ private boolean passThru=true; /** + * internal flag - set to true to sleep until passThru is true before passing on a message + */ + private boolean qUEUE=false; + /** * the client apps message handler */ IMessageHandler pickHandler=null; @@ -42,7 +46,9 @@ public class SimplePickManager implements IPickManager { } public synchronized void sendMessage(Message message) { - manager.sendMessage(message); + // throw away messages whilst we block + if (passThru && manager!=null) + manager.sendMessage(message); } /** * pass message onto the Apps handler, or wait until @@ -50,12 +56,15 @@ public class SimplePickManager implements IPickManager { * @param message */ protected synchronized void handleMessage(Message message) { - while (!passThru) { + if (qUEUE) { + while (!passThru && manager!=null) { + log.debug("Not passing through."); try { Thread.sleep(5); } catch (InterruptedException e) {}; + } } - if (passThru) + if (passThru && manager!=null) pickHandler.handleMessage(message); } @@ -72,8 +81,14 @@ public class SimplePickManager implements IPickManager { public void setPassThru(boolean passThru) { this.passThru = passThru; } - + /** + * shutdown the pickmanager and remove all references to it + */ public void shutdown() { - manager.shutdown(); + passThru=false; + manager.registerMessageHandler(null); + SocketManager dying = manager; + manager=null; + dying.shutdown(); } } -- 1.7.10.2