public Object runWorkflow1(InvocationEntity myInvoker, URI myWorkflowID, URI myServiceID, String myNodeID,
Integer myTimestep) throws XmlException {
assert WORKFLOW_1.equals(myServiceID);
WorkflowNotifier notifier = NotifierFactory.createWorkflowNotifier();
WorkflowTrackingContext context = notifier.createTrackingContext(new Properties(), BROKER_URL, myWorkflowID,
myServiceID, myNodeID, myTimestep);
InvocationContext myInvocation = notifier.workflowInvoked(context, myInvoker,
XmlObject.Factory.parse("<soapHeader/>"),
XmlObject.Factory.parse("<soapBody>input1,input2</soapBody>"), "This is the start of this workflow");
// BEGIN SERVICE1
{
// prepare to invoke service1
InvocationEntity service1 = notifier.createEntity(myServiceID, SERVICE_1, "NODE1", 1);
InvocationContext service1Invocation = notifier.invokingService(context, service1,
XmlObject.Factory.parse("<soapHeader/>"), XmlObject.Factory.parse("<soapBody>input1</soapBody>"),
"This workflow is invoking a service");
Object result = null;
try {
// prepare to invoke service1
result = runService1(service1, service1.getWorkflowID(), service1.getServiceID(),
service1.getWorkflowNodeID(), service1.getWorkflowTimestep());
// If this were an async invocation, we would have finished
// sending request.
// we acknowledge the successful request.
notifier.invokingServiceSucceeded(context, service1Invocation, "Invoked service1 successfully");
} catch (Exception ex) {
// If there had been a problem sending the request on the wire,
// we acknowledge a failed request.
notifier.invokingServiceFailed(context, service1Invocation, ex, "Failed to invoke service1");
}
// At this point, we would have waited for response from service1 if
// it were an async call.
// assume we received response at this point and continue.
if (result instanceof Success) {
notifier.receivedResult(context, service1Invocation, ((Success) result).header,
((Success) result).body, "got success response from service1");
} else if (result instanceof Failure) {
notifier.receivedFault(context, service1Invocation, ((Failure) result).header, ((Failure) result).body,
"got fault response from service1");
}
}
// BEGIN SERVICE2
{
// prepare to invoke service1
InvocationEntity service2 = notifier.createEntity(myServiceID, SERVICE_2, "NODE2", 2);
InvocationContext service1Invocation = notifier.invokingService(context, service2,
XmlObject.Factory.parse("<soapHeader/>"),
XmlObject.Factory.parse("<soapBody>input2,input3</soapBody>"),
"This workflow is invoking another service");
Object result = null;
try {
// prepare to invoke service2
result = runService2(service2, service2.getWorkflowID(), service2.getServiceID(),
service2.getWorkflowNodeID(), service2.getWorkflowTimestep());
// If this were an async invocation, we would have finished
// sending request.
// we acknowledge the successful request.
notifier.invokingServiceSucceeded(context, service1Invocation, "Invoked service2 successfully");
} catch (Exception ex) {
// If there had been a problem sending the request on the wire,
// we acknowledge a failed request.
notifier.invokingServiceFailed(context, service1Invocation, ex, "Failed to invoke service2");
}
// At this point, we would have waited for response from service1 if
// it were an async call.
// assume we received response at this point and continue.
if (result instanceof Success) {
notifier.receivedResult(context, service1Invocation, ((Success) result).header,
((Success) result).body, "got success response from service2");
} else if (result instanceof Failure) {
notifier.receivedFault(context, service1Invocation, ((Failure) result).header, ((Failure) result).body,
"got fault response from service2");
}
}
Object result = null;
notifier.sendingResult(context, myInvocation, "sending result back to the invoker of this workflow");
try {
result = new Success();
notifier.sendingResponseSucceeded(context, myInvocation, "sent result to invoker");
} catch (Exception ex) {
notifier.sendingResponseFailed(context, myInvocation, ex);
}
return result;
}