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