EJB notification message to the client?

Discussions

General J2EE: EJB notification message to the client?

  1. EJB notification message to the client? (2 messages)

    Normally a j2ee application implements the pull model, where the client asks the server for information. The application I am developing does the same, but in some cases the client needs to be notified on an event in the server.

    For example when an EJB changes to a certain state, there should be an alert message going to the client, so the client can show this alert message to the screen. One way to implement this is by letting the client poll the server all the time to see if the state of the EJB has changed. This is not very efficient and nice.

    Is there another way to implement this behaviour?
    My first thought was RMI, but I don’t think an EJB can act as a RMI client that communicates with a RMI server (=the client) that lives outside the container, because RMI uses socket communication, and you can’t use sockets in EJB.

    Does anybody has any idea on how to do this?

    Rene de Jong
  2. Have you tried looking into JMS? You could just put a message in a queue that the client could then pick up later. That way the client wouldn't just need to sit there checking the bean over and over again.

    Mark
  3. I use a pure CORBA for this.
    I create a entity queue where to put IOR

    here is some code:

    **********************
          LocalActiveOperatorHome operatorHome = (LocalActiveOperatorHome)ctx.lookup("java:comp/env/ejb/db/active_operator");
          
          Collection list = operatorHome.findAll();
          Iterator operators = list.iterator();
          
          ORB orb = ORB.init(new String[0], null);
          
          while(operators.hasNext())
          {
            LocalActiveOperator operador = (LocalActiveOperator)operators.next();
            
            String ior = operador.getCallbackIOR();
            
            org.omg.CORBA.Object obj = orb.string_to_object(ior);
            SessionCallback callback = SessionCallbackHelper.narrow(obj);
            
            // trying to notify an operator about the call
            try { callback.incomingCall(callID, abonadoID); }
            catch(Exception ex)
            { // if we got an exception - operator is dead...
              operador.remove();
            }
          }
    ***********************************
        try
        {
          Context ctx = new InitialContext();
          LocalActiveOperatorHome home = (LocalActiveOperatorHome)ctx.lookup("java:comp/env/ejb/db/active_operator");
          
          ORB orb = ORB.init(new String[0], null);
          String ior = orb.object_to_string(callback);
          
          LocalActiveOperator local = home.create(operatorID, ior);
        }
        catch(Exception e)
          { throw new RemoteException(); }
    ************************

    Ratu