Search code examples
javaamazon-web-servicesamazon-swf

SWF: How can I signal the parent workflow from the child workflow?


I'm trying to signal my parent workflow to update its state variable. The parent workflow id is passed to the child workflow's execute method.

@Autowired
private AmazonSimpleWorkflowClient swfClient;
@Autowired
private String swfDomain;

private ParentWorkflowClientExternalFactory clientExternalFactory = new ParentWorkflowClientExternalFactoryImpl(swfClient, swfDomain);

@Override
public Promise<String> childActivityMethod(String parentWorkflowId) {
    ParentWorkflowClientExternal clientExternal = clientExternalFactory.getClient(parentWorkflowId);
    clientExternal.updateState(...);
}

However, this throws a NullPointerException in SWF code (AmazonSimpleWorkflow is null):

["java.lang.NullPointerException",{"cause":null,"stackTrace":[{"methodName":"signalWorkflowExecution","fileName":"GenericWorkflowClientExternalImpl.java","lineNumber":87,"className":"com.amazonaws.services.simpleworkflow.flow.worker.GenericWorkflowClientExternalImpl","nativeMethod":false},{"methodName":"signalWorkflowExecution","fileName":"DynamicWorkflowClientExternalImpl.java","lineNumber":167,"className":"com.amazonaws.services.simpleworkflow.flow.DynamicWorkflowClientExternalImpl","nativeMethod":false},...

When I initialize the ClientExternalFactory without the parameters:

private ParentWorkflowClientExternalFactory clientExternalFactory = new ParentWorkflowClientExternalFactoryImpl();

The exception thrown is: The required property genericClient is null. It could be caused by instantiating the factory through the default constructor instead of the one that takes service and domain arguments.

ParentWorkflow#updateState does this:

private MyWorkflowState state;

// This method has @Signal in the interface.
@Override
public void updateState(MyWorkflowState newState) {
    state = newState;
}

Any advice?


Solution

  • There are two types of clients generated from the workflow interfaces. The internal and external ones. Internal are expected to be used from within a workflow code and external ones to be used outside of a workflow (for example from a web server). You are trying to use an external client inside a workflow which is not supported. Use the internal client (created using ParentWorkflowClientFactory) instead. See Flow Development Guide for more info.