X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Frbvi%2Fchimera%2FChimeraListener.java;h=2882cb5ec3318794eda08041a81e805b00362270;hb=09e3cf7d0e936a9b69fc8f6c7315195694c5127e;hp=8b48cd2a7682989d0800744ebc03752e3b43720c;hpb=f2f654875a6eb5f4e90b2c5c545bfed3a70f2b5f;p=jalview.git
diff --git a/src/jalview/ext/rbvi/chimera/ChimeraListener.java b/src/jalview/ext/rbvi/chimera/ChimeraListener.java
index 8b48cd2..2882cb5 100644
--- a/src/jalview/ext/rbvi/chimera/ChimeraListener.java
+++ b/src/jalview/ext/rbvi/chimera/ChimeraListener.java
@@ -6,7 +6,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jalview.httpserver.AbstractRequestHandler;
-import jalview.httpserver.HttpServer;
import jalview.structure.SelectionSource;
/**
@@ -17,8 +16,12 @@ import jalview.structure.SelectionSource;
*
Start the Chimera process
* Start the REST service on Chimera, get the port number it is listening on
*
- * Start the ChimeraListener, get the port number it is listening on
+ * 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
+ * Multiple linked Chimera instances will each have a separate listener (but
+ * share one Http server)
*
*
* @author gmcarstairs
@@ -28,6 +31,21 @@ 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";
+
+ /*
* A static counter so each listener can be associated with a distinct context
* root (/chimera0,1,2,3...). This is needed so we can fetch selections from
* multiple Chimera instances without confusion.
@@ -35,9 +53,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
@@ -49,13 +67,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.
*
@@ -68,18 +81,8 @@ public class ChimeraListener extends AbstractRequestHandler implements
{
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();
}
/**
@@ -90,34 +93,37 @@ public class ChimeraListener extends AbstractRequestHandler implements
HttpServletResponse response)
{
// dumpRequest(request);
- String message = request.getParameter("chimeraNotification");
- if ("selection changed".equals(message))
+ String message = request.getParameter(CHIMERA_NOTIFICATION);
+ if (SELECTION_CHANGED.equals(message))
{
this.chimeraBinding.highlightChimeraSelection();
}
+ else if (message != null && message.startsWith(MODEL_CHANGED))
+ {
+ processModelChanged(message.substring(MODEL_CHANGED.length()));
+ }
else
{
System.err.println("Unexpected chimeraNotification: " + message);
- // do it anyway for now!
- this.chimeraBinding.highlightChimeraSelection();
}
}
/**
- * Deregister this listener and close it down
+ * Handler a ModelChanged notification from Chimera
*
- * @throws Exception
+ * @param substring
*/
- public void shutdown()
+ protected void processModelChanged(String message)
{
- try
- {
- HttpServer.getInstance().removeHandler(this);
- stop();
- } catch (Exception e)
- {
- System.err.println("Error stopping chimera listener: "
- + e.getMessage());
- }
+ // System.out.println(message + " (not implemented in Jalview)");
+ }
+
+ /**
+ * Returns a display name for this service
+ */
+ @Override
+ public String getName()
+ {
+ return "ChimeraListener";
}
}