Discussions

EJB programming & troubleshooting: when to call Local and Remote Ejb Dynamically

  1. HI,
      Iam having to EJB's one is of Local and the other is Remote.I have to dynamically know and call Local and Remote.How to call them dynamically from a session Bean.

    Please help me out.

    Regards
    Samy
  2. I don’t really understand why you wanted to call your EJB from a session bean remotely. The whole idea of having local components is to avoid the overhead of remote call and network traffic.

    I think you should not make any remote calls to access Entity beans from a session bean because they both have same container and jvm.

    You should not publish any Entity bean interface remotely. All the calls have to come thru Session Facades.

    -arun
  3. Thanks arun,
              But i have a specific condition in my project that I have to call local interface and also remote interface which is in another JVM in a single call.
    How to solve this situation.

    Regards
    Samy
  4. I dont think (or rather i dont know) how to achive that ...

    But probably ... you could try something on this line.

    Your session bean can take an Action interface ...

    For example :-
    public storeEmpoyeeDetails(EmpDetailsDO, Action localORRemote) //Action is an interface type
    {
        localORRemote.getInitialContext();
    }

    And when you call this storeEmpoyeeDetails(), and you wanted to make a Remote call in there than a local call then your argument would be like this...

    storeEmpoyeeDetails(EmpDetailsDO object, RemoteAction remoteAction);
    ---
    RemoteAction - is remote specific impl for Action.

    RemoteAction.java :-
    public context getInitialContext()
    {
      * create jndi properties
      * get context using that property object.
      return new InitialContext(properties);
    }

    On other hand if you are looking for Local components. the have LocalAction

    LocalAction.java :-
    public context getInitialContext()
    {
      return new InitialContext();
    }

    Will this throw any light at all ?

    This looks ok but imagine a situation where you wanted to make both (local and remote) in single Sesion Bean call ......

    -arun