X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fuk%2Fac%2Fvamsas%2Fclient%2Fsimpleclient%2FSimplePickManager.java;h=3865a8dfcf5d1ec4f15c743559906694ea8a89a0;hb=1eea4b639911330e7cd65e17c5421cc584f0d22e;hp=5f92d37f694a2d09b341091a9bcb5685341aac7a;hpb=ac9fee0c47d0e616d5ba16ad6ded2354e3fe1a5d;p=vamsas.git diff --git a/src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java b/src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java index 5f92d37..3865a8d 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java +++ b/src/uk/ac/vamsas/client/simpleclient/SimplePickManager.java @@ -1,3 +1,24 @@ +/* + * This file is part of the Vamsas Client version 0.2. + * Copyright 2010 by Jim Procter, Iain Milne, Pierre Marguerite, + * Andrew Waterhouse and Dominik Lindner. + * + * Earlier versions have also been incorporated into Jalview version 2.4 + * since 2008, and TOPALi version 2 since 2007. + * + * The Vamsas Client is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Vamsas Client is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the Vamsas Client. If not, see . + */ package uk.ac.vamsas.client.simpleclient; import org.apache.commons.logging.*; @@ -6,18 +27,21 @@ 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; + + SocketManager manager = null; + SimplePickManager(SocketManager manager) { - this.manager=manager; - final SimplePickManager me=this; + this.manager = manager; + final SimplePickManager me = this; /** * add a handler that calls the SimplePickManager message handler */ @@ -26,45 +50,54 @@ public class SimplePickManager implements IPickManager { me.handleMessage(message); } }); - + } + /** * when false, messages are queued in a FIFO until thread can restart. */ - private boolean passThru=true; + private boolean passThru = true; + /** - * internal flag - set to true to sleep until passThru is true before passing on a message + * internal flag - set to true to sleep until passThru is true before passing + * on a message */ - private boolean qUEUE=false; + private boolean qUEUE = false; + /** * the client apps message handler */ - IMessageHandler pickHandler=null; + IMessageHandler pickHandler = null; + public void registerMessageHandler(IMessageHandler handler) { - pickHandler=handler; - + pickHandler = handler; + } public synchronized void sendMessage(Message message) { // throw away messages whilst we block - if (passThru && manager!=null) + if (passThru && manager != null) manager.sendMessage(message); } + /** - * pass message onto the Apps handler, or wait until - * passThru is true before passing message on. + * pass message onto the Apps handler, or wait until passThru is true before + * passing message on. + * * @param message */ protected synchronized void handleMessage(Message message) { if (qUEUE) { - while (!passThru && manager!=null) { - log.debug("Not passing through."); - try { - Thread.sleep(5); - } catch (InterruptedException e) {}; - } + while (!passThru && manager != null) { + log.debug("Not passing through."); + try { + Thread.sleep(5); + } catch (InterruptedException e) { + } + ; + } } - if (passThru && manager!=null) + if (passThru && manager != null) pickHandler.handleMessage(message); } @@ -76,19 +109,21 @@ public class SimplePickManager implements IPickManager { } /** - * @param true to pass messages on to handlers, false to hold messages in queue + * @param true to pass messages on to handlers, false to hold messages in + * queue */ public void setPassThru(boolean passThru) { this.passThru = passThru; } + /** * shutdown the pickmanager and remove all references to it */ public void shutdown() { - passThru=false; + passThru = false; manager.registerMessageHandler(null); SocketManager dying = manager; - manager=null; - dying.shutdown(); + manager = null; + dying.shutdown(); } }