Hi Rui,

I currently use listeners in an application that I am working on.
I am using Jonas in a distributed reservation system.  In this system
reservations can be made by many remote clients and the current set of
reservations can be viewed by an "administration" application.  The
administration application registers a listener with the system via a
session bean and is notified whenever a client makes a reservation.

The trick is to make the listener objects Remote objects.  Here is some
sample code to illustrate...

First define your listeneing interface...

public interface ReservationServiceListener extends EventListener, Remote {
    public void reservationCreated(ReservationServiceEvent e)
        throws RemoteException;
}

Then define a Remote implementation of this interface that acts as a proxy
for a local listener...

public class RemoteReservationServiceListener
extends UnicastRemoteObject
implements ReservationServiceListener
{
    public RemoteReservationServiceListener(ReservationServiceListener
localListener)
    throws RemoteException
    {
        m_listener= localListener;
    }

    public void reservationCreated(ReservationServiceEvent e)
    throws RemoteException
    {
        m_listener.reservationCreated(e);
    }
}

Now, here's how a client registers a listener with the server...

sessionBean.addListener(
    new RemoteReservationServiceListener(
        new ReservationServiceListener() {
            public void reservationCreated(ReservationServiceEvent e)
            throws RemoteException
            {
                ...handle callback here...
            }
        }
    )
);


I know this is a pretty lengthy explanation.  Read up on Java RMI for more
information.

Also, check out JMS (Java Messaging Service) or Distributed Infobus.
Messaging services like these are another way to handle callbacks.  They
allow messages to be sent among the parts of a distributed application.
These service are generally more robust than the example I just gave but
have more learning overhead.


ted stockwell
----- Original Message -----
From: Rui Gil <[EMAIL PROTECTED]>
To: 'JOnAS Users' <[EMAIL PROTECTED]>
Sent: Monday, November 15, 1999 9:06 AM
Subject: Callback ?


>
> Hi !
>
> I'm kind of new to EJB and I was wonder
> ist it possible to have a callback model
> with the EJB architecture ?
>
> I mean to have clients that can register
> listeners to session beans ?
>
> Thanx
>
> Rui Gil

Reply via email to