cancel
Showing results for 
Search instead for 
Did you mean: 

Is it safe to keep state in Java delegates?

jorell
Champ in-the-making
Champ in-the-making
I have a use case where I need to reaccess an expression when signaling out of a delegate. Since the signal method does not have the ActivityExecution instance to get the values of an expression, I am thinking of setting the values in a member variable and access it when signaling. Something like:

public class MyTaskDelegate extends BaseTaskDelegate {

  private Logger logger = LoggerFactory.getLogger(SymphonyTaskDelegate.class);
  private Expression inVariables;
  private Expression outVariables;
  private String outVariablesStr;

public void execute(ActivityExecution execution) throws Exception {
  /*Do something*/
  outVariablesStr = outVariables..getValue(execution);
}

public void signal(ActivityExecution execution, String signalName, Object signalData)
      throws Exception {
    /*READ outVariablesStr*/
    if (outVariablesStr != null) {
         /*Do Something*/
    }
    leave(execution);
  }
}

Is this doable? Can I rely on the delegate state being saved, even if say, I restart the activiti server after execute and before signal?
3 REPLIES 3

jorell
Champ in-the-making
Champ in-the-making
Actually signal does have access to the ActivityExecution instance, my usecase is to call a different method before signalling. This method needs to access 'outVariablesStr' in the above code.

jbarrez
Star Contributor
Star Contributor
No: java delegates are statesless. That is the reason why we only allow for expressions: the expression *definition* is injected in the delegate, and evaluated at runtime.

If you inject a String into a delegate, it will be widely know to all delegates (because there is only one)

jorell
Champ in-the-making
Champ in-the-making
Got it. Thanks.