[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Wed Mar 17 20:55:51 UTC 2010
gordonp
Wed Mar 17 16:55:51 EDT 2010
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory dev.open-bio.org:/tmp/cvs-serv12571/src/main/org/biomoby/client
Modified Files:
MobyRequest.java MobyRequestEvent.java
Log Message:
Updates to pass sent data around with response (used by Seahawk PbE system)
moby-live/Java/src/main/org/biomoby/client MobyRequest.java,1.44,1.45 MobyRequestEvent.java,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequest.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequest.java 2009/07/15 18:35:30 1.44
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequest.java 2010/03/17 20:55:51 1.45
@@ -373,7 +373,7 @@
// Inform the handler that some data has been added to the response (for incremental display?)
if(handler != null){
- MobyRequestEvent mre = new MobyRequestEvent(finalContents, this, mservice, null, requestId);
+ MobyRequestEvent mre = new MobyRequestEvent(finalContents, this, mservice, inData, null, requestId);
StringWriter xmlWriter = new StringWriter();
MobyDataUtils.toXMLDocument(xmlWriter, finalContents);
@@ -412,10 +412,20 @@
* @return the id that the callback event will return from getID(), allowing a client to distinguish between multiple concurrent invocation callbacks
*/
public synchronized int invokeService(MobyRequestEventHandler handler){
- int id = autoID++;
+ final int id = autoID++;
- Thread t = new InvocationThread(this, inputData, handler, id); // see internal class definition below
- t.start();
+ try{
+ Thread t = new InvocationThread(this, inputData, handler, id); // see internal class definition below
+ t.start();
+ } catch(final Exception e){
+ // Launching callback in new Thread avoids possible deadlocks caused by handler
+ // calling invokeService() again as a retry
+ final MobyRequestEventHandler h = handler;
+ final MobyContentInstance i = inputData;
+ final MobyService s = getService();
+ final MobyRequest t = this;
+ (new Thread(){public void run(){h.processEvent(new MobyRequestEvent(i, t, s, null, e, id));}}).start();
+ }
return id;
}
@@ -424,24 +434,29 @@
// the handler specified in the invocation.
class InvocationThread extends Thread {
MobyContentInstance data;
+ ByteArrayOutputStream dataXML;
MobyService mservice;
MobyRequest mobyRequest;
MobyRequestEventHandler handler;
int requestId;
- InvocationThread(MobyRequest mr, MobyContentInstance inData, MobyRequestEventHandler h, int id){
+ InvocationThread(MobyRequest mr, MobyContentInstance inData, MobyRequestEventHandler h, int id) throws Exception{
data = inData;
mobyRequest = mr;
mservice = mobyRequest.getService();
handler = h;
requestId = id;
+ dataXML = new ByteArrayOutputStream();
+ MobyDataUtils.toXMLDocument(dataXML, data);
+
// Name the thread after the service being run, mostly for ease of debugging
setName(mservice.getName()+requestId);
}
public void run() {
- MobyRequestEvent requestEvent = new MobyRequestEvent(data, mobyRequest, mservice, null, requestId);
+
+ MobyRequestEvent requestEvent = new MobyRequestEvent(data, mobyRequest, mservice, data, null, requestId);
// Tell the handler we're starting the request, with the given data
handler.start(requestEvent);
@@ -452,13 +467,14 @@
content = mobyRequest.invokeService(data, contentsXML, handler, requestId); //RPC call...
}
catch(Exception e){
- responseEvent = new MobyRequestEvent(content, mobyRequest, mservice, e, requestId);
+ responseEvent = new MobyRequestEvent(content, mobyRequest, mservice, data, e, requestId);
}
catch(Error err){
- responseEvent = new MobyRequestEvent(content, mobyRequest, mservice, err, requestId);
+ responseEvent = new MobyRequestEvent(content, mobyRequest, mservice, data, err, requestId);
}
+
if(responseEvent == null){
- responseEvent = new MobyRequestEvent(content, mobyRequest, mservice, null, requestId);
+ responseEvent = new MobyRequestEvent(content, mobyRequest, mservice, data, null, requestId);
}
// We've got the raw XML laying around, so why not provide it unmolested to the callback?
responseEvent.setContentsXML(contentsXML.toString());
@@ -480,37 +496,6 @@
}
/**
- * This method retrieves from Moby Central a copy of the WSDL document for the service
- * (or uses an internally cached copy from a previous invocation), and sets the variables for the
- * SOAP call appropriately so you can consequently call performSOAPRequest.
- */
-//PG protected Call getServiceFromWSDL() throws MobyException, NoSuccessException{
-// String wsdl = null;
-
-// // Since this is how we retrieve a service from Central, use the same values as the key to the hash
-// String wsdlCacheKey = mobyService.getName() + "@" + mobyService.getAuthority();
-
-// // This is the same call as last time, so we don't need to change the setup
-// if(wsdlCacheKey.equals(lastWsdlCacheKey)){
-// return setCallFromWSDL((String) wsdlCache.get(wsdlCacheKey));
-// }
-// // We haven't encountered this service yet
-// else if(!wsdlCache.containsKey(wsdlCacheKey)){
-// wsdl = mobyCentral.getServiceWSDL(mobyService.getName(), mobyService.getAuthority());
-// wsdlCache.put(wsdlCacheKey, wsdl);
-// }
-// // We've dealt with this one before
-// else{
-// wsdl = (String) wsdlCache.get(wsdlCacheKey);
-// }
-
-// lastWsdlCacheKey = wsdlCacheKey; // Keep track of the last invocation
-
- // Get ready to do SOAP
-//PG return setCallFromWSDL(null);
-// }
-
- /**
* Creates the SOAP Call that will be invoked later. This should be based on the WSDL document
* and parameter information from the MobyService, but these are currently not up to snuff.
*/
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequestEvent.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequestEvent.java 2007/06/08 14:04:27 1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequestEvent.java 2010/03/17 20:55:51 1.6
@@ -18,17 +18,19 @@
protected int eventID;
protected MobyContentInstance contents;
protected MobyRequest originatingMobyRequest;
+ protected MobyContentInstance originatingMobyRequestInputData;
protected String dataPayloadXML;
protected MobyService service;
protected Throwable exception;
private static int nextEventID = 0;
- public MobyRequestEvent(MobyContentInstance mci, MobyRequest requestSource, MobyService serv, Throwable e, int id){
+ public MobyRequestEvent(MobyContentInstance mci, MobyRequest requestSource, MobyService serv, MobyContentInstance serviceInput, Throwable e, int id){
consumed = false;
done = false;
- contents = mci;
+ contents = mci;
originatingMobyRequest = requestSource;
+ originatingMobyRequestInputData = serviceInput;
exception = e;
eventID = id;
service = serv;
@@ -42,6 +44,24 @@
}
/**
+ * This method should be used instead of getSource().getInput() because the MobyRequest object may have multiple
+ * concurrent threads using it, meaning that the inputXML is not necessarily what it was when the service was
+ * invoked.
+ *
+ * @return if a Moby client waiting for a service response, this data is the payload given as input to the service
+ */
+ public MobyContentInstance getSourceInput(){
+ return originatingMobyRequestInputData;
+ }
+
+ /**
+ * @param inputXML the Moby XML sent to the service this event is refering to.
+ */
+ public void setSourceInput(MobyContentInstance inputPayload){
+ originatingMobyRequestInputData = inputPayload;
+ }
+
+ /**
* @return the contents of the MOBY request or response (depending on whether MobyRequest is acting as a client or server)
*/
public MobyContentInstance getContent(){
More information about the MOBY-guts
mailing list