cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to call methods of a Stateless EJB?

mskaesz
Champ in-the-making
Champ in-the-making
Hey guys,

I found four ways to call a method of a Stateless EJB. Which one do you recommend?

My environment: Activiti5.beta1; EJB3; JBoss AS 5.

1.) In the first listing I have an EJB which is already injected via JBoss AS. I'm setting the EJB as variable when the process is started.





@EJB(name="ejb/friends")
private FriendsServiceRemote friendsServiceRemote;



ProcessEngineImpl engine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();

Map<String, Object> variables = new HashMap<String, Object>();
variables.put("friendsServiceRemote", friendsServiceRemote);
             
engine.getRuntimeService().startProcessInstanceByKey("helloWorld", variables);


In the process I call the EJB the following way:


<serviceTask id="javaService" name="javaService" activiti:method-expr="#{friendsServiceRemote.doSomething}" />

doSomething is a method of my EJB. This solution works without any problems. What's happening behind the scenes? Is it a good idea to set the whole EJB as variable?

2.) The second way is to implement ActivityBehavior and to extend BpmnActivityBehavior (like it's described in the user manual).


@Stateless
public class FriendsService extends BpmnActivityBehavior implements FriendsServiceRemote, ActivityBehavior {

     public void execute(ActivityExecution execution) throws Exception {
          System.out.println("huhu");
          performDefaultOutgoingBehavior(execution);
     }
}


In the process I call the EJB the following way:


<serviceTask id="javaService" name="javaService" activiti:class="de.backend.services.friends.impl.FriendsService" />

Works, but I have to implement and extend the Activiti stuff and I can't invoke different methods of the same EJB.

3.) The third one is to call my EJB from a Spring bean. Actually, I have no clue about Spring and so I haven't tested it… I had the idea because of the new chapter(Spring Integration) in the user manual. What exactly does "Integration" mean? Is their a "special" way how Activiti handles the Spring beans? Is it possible to inject EJBs like Spring beans and to use them the same way like you use the Spring beans?

4.) Last but not least the WebServiceTask. I can make all my methods available as Web Services and call them in the WebServiceTask. I hope I can try it out in the next release! What do you think about that?

Thanks in advance.

Cheers,
Marc
15 REPLIES 15

falko_menge
Champ in-the-making
Champ in-the-making
As Bernd said, the most important requirement would be access to the current activity. In case you still hesitate to expose the object graph of the parsed process definition for introspection, we should at least provide its name and ID.

jbarrez
Star Contributor
Star Contributor
Which are available on the ActivityExecution (getActivity()).

What would you do with it in a regular service task invocation?
I still don't see the use case for exposing the current activity in the JavaDelegation.

falko_menge
Champ in-the-making
Champ in-the-making
Does it hurt us so badly, if we just expose a String with id of the current activity through something like getCurrentActivityId(), so that the ActivityBehavior interface can "be avoided as much as possible."?

tombaeyens
Champ in-the-making
Champ in-the-making
The JavaDelegation has as a main purpose to hide as much methods as possible so that users are encouraged to use the stable methods only.
There's always use cases to add more methods of ActivityExecution or ExecutionEntity.  The more we add the less stable methods we'll expose.
So in conclusion, we want to limit the constraints we put on ourselves after 5.0. So I don't think it's good to add it.  I don't see the problem with the cast or just implementing an ActivityBehavior instead.

ryu
Champ in-the-making
Champ in-the-making
hi jbarrez, falko.menge, and tombaeyens,

Would you please explain me the downside of the following way to call EJB method (just another thought):

1. define a class A, which has method m1() invoking a stateless EJB.
2. instance an object from the class A and given it as a process variable a.
3. using expression call a.m1() in process

Is it really bad and why?

Waiting for your answer
Thank you very very much

jbarrez
Star Contributor
Star Contributor
Nope, if I read it correctly there is nothing bad about that.