X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fext%2Frbvi%2Fchimera%2FChimeraListener.java;h=40b0ff0b2c86bcb4682e8c7008c8e695dc2c88f3;hb=e2ca25dc2cebc1603445864c1bcf41bb13fc2d61;hp=2479a1b2d08a49b19aef799793e21cfc259728a8;hpb=ab97cf4af61bd67f20676c686601522d0ba0875d;p=jalview.git
diff --git a/src/jalview/ext/rbvi/chimera/ChimeraListener.java b/src/jalview/ext/rbvi/chimera/ChimeraListener.java
index 2479a1b..40b0ff0 100644
--- a/src/jalview/ext/rbvi/chimera/ChimeraListener.java
+++ b/src/jalview/ext/rbvi/chimera/ChimeraListener.java
@@ -1,14 +1,33 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.ext.rbvi.chimera;
+import jalview.httpserver.AbstractRequestHandler;
+import jalview.structure.SelectionSource;
+
import java.net.BindException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import jalview.httpserver.AbstractRequestHandler;
-import jalview.httpserver.HttpServer;
-import jalview.structure.SelectionSource;
-
/**
* This is a simple Http handler that can listen for selections in Chimera.
*
@@ -20,7 +39,8 @@ import jalview.structure.SelectionSource;
* Start the ChimeraListener, get the URL it is listening on
* The first listener started will start the singleton HttpServer
* Send a 'listen' command to Chimera with the URL of the listener
- * When Jalview's Chimera window is closed, shut down the ChimeraListener
+ * When Jalview's Chimera window is closed, shut down the
+ * ChimeraListener
* Multiple linked Chimera instances will each have a separate listener (but
* share one Http server)
*
@@ -28,13 +48,22 @@ import jalview.structure.SelectionSource;
* @author gmcarstairs
*
*/
-public class ChimeraListener extends AbstractRequestHandler implements
- SelectionSource
+public class ChimeraListener extends AbstractRequestHandler
+ implements SelectionSource
{
+ /*
+ * Chimera notification parameter name
+ */
private static final String CHIMERA_NOTIFICATION = "chimeraNotification";
+ /*
+ * Chimera model changed notifications start with this
+ */
private static final String MODEL_CHANGED = "ModelChanged: ";
+ /*
+ * Chimera selection changed notification message
+ */
private static final String SELECTION_CHANGED = "SelectionChanged: selection changed\n";
/*
@@ -45,9 +74,9 @@ public class ChimeraListener extends AbstractRequestHandler implements
private static int chimeraId = 0;
/*
- * Path below context root that identifies this handler
+ * Prefix for path below context root (myChimeraId is appended)
*/
- private static final String LISTENER_PATH = "chimera";
+ private static final String PATH_PREFIX = "chimera";
/*
* Value of chimeraId (0, 1, 2...) for this instance
@@ -59,13 +88,8 @@ public class ChimeraListener extends AbstractRequestHandler implements
*/
private JalviewChimeraBinding chimeraBinding;
- /*
- * The URI of this listener
- */
- private String uri;
-
/**
- * Constructor that also registers this as an Http request handler on path
+ * Constructor that registers this as an Http request handler on path
* /chimeraN, where N is incremented for each instance. Call getUri to get the
* resulting URI for this handler.
*
@@ -73,23 +97,12 @@ public class ChimeraListener extends AbstractRequestHandler implements
* @throws BindException
* if no free port can be assigned
*/
- public ChimeraListener(JalviewChimeraBinding binding)
- throws BindException
+ public ChimeraListener(JalviewChimeraBinding binding) throws BindException
{
myChimeraId = chimeraId++;
this.chimeraBinding = binding;
- final String path = LISTENER_PATH + myChimeraId;
- this.uri = HttpServer.getInstance().registerHandler(path, this);
- }
-
- /**
- * Returns the URI on which we are listening
- *
- * @return
- */
- public String getUri()
- {
- return this.uri;
+ setPath(PATH_PREFIX + myChimeraId);
+ registerHandler();
}
/**
@@ -101,45 +114,44 @@ public class ChimeraListener extends AbstractRequestHandler implements
{
// dumpRequest(request);
String message = request.getParameter(CHIMERA_NOTIFICATION);
- if (SELECTION_CHANGED.equals(message))
- {
- this.chimeraBinding.highlightChimeraSelection();
- }
- else if (message != null && message.startsWith(MODEL_CHANGED))
+ if (message == null)
{
- processModelChanged(message.substring(MODEL_CHANGED.length()));
+ message = request.getParameter("chimerax_notification");
}
- else
+ if (message != null)
{
- System.err.println("Unexpected chimeraNotification: " + message);
+ if (message.startsWith("SelectionChanged"))
+ {
+ this.chimeraBinding.highlightChimeraSelection();
+ }
+ else if (message.startsWith(MODEL_CHANGED))
+ {
+ System.err.println(message);
+ processModelChanged(message.substring(MODEL_CHANGED.length()));
+ }
+ else
+ {
+ System.err.println("Unexpected chimeraNotification: " + message);
+ }
}
}
/**
- * Handler a ModelChanged notification from Chimera
+ * Handle a ModelChanged notification from Chimera
*
* @param substring
*/
protected void processModelChanged(String message)
{
- System.out.println(message + " (not implemented in Jalview)");
+ // System.out.println(message + " (not implemented in Jalview)");
}
/**
- * Deregister this listener and close it down
- *
- * @throws Exception
+ * Returns a display name for this service
*/
- public void shutdown()
+ @Override
+ public String getName()
{
- try
- {
- HttpServer.getInstance().removeHandler(this);
- stop();
- } catch (Exception e)
- {
- System.err.println("Error stopping chimera listener: "
- + e.getMessage());
- }
+ return "ChimeraListener";
}
}