Create And Call Expression language to call Java method

461 views
Skip to first unread message

subhaj...@gmail.com

unread,
May 19, 2015, 1:23:04 AM5/19/15
to camunda-...@googlegroups.com
Hello,

I am using camunda 7.1, in service task we can define regular expression to call java method as,
<bpmn2:serviceTask id="ServiceTask_1" camunda:expression="#{camundaServiceExecutionController.requesterProcessTicketRequest()}" name="Process ticket request">
<bpmn2:incoming>SequenceFlow_8</bpmn2:incoming>
<bpmn2:incoming>SequenceFlow_9</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_16</bpmn2:outgoing>
</bpmn2:serviceTask>

where camundaServiceExecutionController is a CDI manage bean.

But my problem is I want to create a regular expression and call this expression pragmatically from a Task Listener, as we have a Task Listener, when this Listener is called then we create a Timer and bound this Timer a specific time, when this timer is created & called then we need to call a java method by using this expression pragmatically.
Example code is,
public class CordinatorAssignmentListener implements TaskListener{


@Inject
private RuntimeService runtimeService;
@Inject
private BusinessProcess businessProcess;

public CordinatorAssignmentListener() {
// TODO Auto-generated constructor stub
}

@Override
public void notify(DelegateTask delegateTask) {
// TODO Auto-generated method stub



String timerRegExp="6000"

CoordinatorSearchTimer coordinatorTask= new CoordinatorSearchTimer();
coordinatorTask.setTaskId(delegateTask.getId());

TimerTask task =coordinatorTask;

Timer timer = new Timer();
timer.schedule(task, Long.valueOf(timerRegExp));



}
}

where CoordinatorSearchTimer is -
import java.util.TimerTask;
public class CoordinatorSearchTimer extends TimerTask {

private String taskId;


@EJB
private UserRoleMappingDAO userRoleMappingDAO;

@Inject
private RuntimeService runtimeService;

private BusinessProcess businessProcess;


@Override
public void run() {
;

Expression exp = Context.getProcessEngineConfiguration().getExpressionManager().createExpression("#{camundaServiceExecutionController.testTimer()}");


}


}

In this method I want to call a java method using expression , How can I create and execute this expression ?
Another problem in this methid I want to use my CDI bean , but unfortunately I am not able to use this bean, because this method is call from separate thread, for that reason I am getting null into this bean.

So please help me how to create a expression and execute it so that i can call cdi managed bean method and also Injecting Bean into this method.

r.brae...@gmail.com

unread,
May 19, 2015, 3:06:09 AM5/19/15
to camunda-...@googlegroups.com, subhaj...@gmail.com
Hello,

what exactly do you try to achieve with your TimerTask?
Depending on what you try you could use a non-interrupting timer event[1] and pass it the intervall. The timer event could call a service task, which could directly call "camundaServiceExecutionController.testTimer()".

<bpmn2:serviceTask id="Task_1" camunda:expression="#{camundaServiceExecutionController.requesterProcessTicketRequest()}" name="ServieTask1"/>
<bpmn2:boundaryEvent id="BoundaryEvent_1" name="" attachedToRef="Task_1">
<bpmn2:extensionElements>
<fox:failedJobRetryTimeCycle>PT6000S</fox:failedJobRetryTimeCycle>
</bpmn2:extensionElements>
<bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
<bpmn2:timerEventDefinition id="_TimerEventDefinition_2"/>
</bpmn2:boundaryEvent>
<bpmn2:sequenceFlow id="SequenceFlow_1" name="" sourceRef="BoundaryEvent_1" targetRef="ServiceTask_1"/>
<bpmn2:serviceTask id="ServiceTask_1" camunda:expression="camundaServiceExecutionController.testTimer()" name="Timer">
<bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
</bpmn2:serviceTask>

Alternatively, you could inject the "camundaServiceExecutionController" into your CoordinatorSearchTimerm. Then you could get rid of the long call chain and be safe that you only call existing methods on it.

public class CoordinatorSearchTimer extends TimerTask {

private String taskId;


@EJB
private UserRoleMappingDAO userRoleMappingDAO;

@Inject
private RuntimeService runtimeService;

private BusinessProcess businessProcess;

@Inject
private CamundaServiceExecutionController controller

@Override
public void run() {


controller.testTimer();


}


}

The fields of your CoordinatorSearchTimer are null because you created the object with "new" and therefore it is not managed by CDI. To change this you have to have the timer injected into your listener so that the BeanManager handles the instantiation.

Cheers,
Ronny

[1]http://docs.camunda.org/7.2/api-references/bpmn20/#events-timer-events
Reply all
Reply to author
Forward
0 new messages