FileDocCategorySizeDatePackage
EventListenerProxy.javaAPI DocGlassfish v2 API5587Fri May 04 22:25:44 BST 2007com.sun.enterprise.management.agent

EventListenerProxy

public class EventListenerProxy extends UnicastRemoteObject implements RemoteEventListener
The EventListenerProxy recieves notifications from RemoteListenerConnectors registered on the server managed objects and forwards them to the corresponding local listeners
author
Hans Hrasna

Fields Summary
private Hashtable
listenerTable
private Hashtable
handbackTable
private static String
proxyAddress
private static EventListenerProxy
eventProxy
private static int
portnum
private static String
rmiName
private static boolean
debug
Constructors Summary
public EventListenerProxy()

        String hostName;
        rmiName = "RemoteEventListener" + hashCode() + System.currentTimeMillis();
        try {
            hostName = java.net.InetAddress.getLocalHost().getHostAddress();
        } catch (java.net.UnknownHostException e) {
            hostName = "localhost";
            System.out.println(e);
        }
        proxyAddress = "//"+ hostName + ":" + portnum + "/" + rmiName;
    
Methods Summary
public voidaddListener(java.lang.String id, javax.management.NotificationListener l, java.lang.Object handback)

        if (debug) System.out.println("EventListenerProxy.addListener()");
        listenerTable.put(id, l);
        handbackTable.put(id, handback);
    
public static com.sun.enterprise.management.agent.EventListenerProxygetEventListenerProxy()


        
		if(eventProxy == null) {
            try {
                eventProxy = new EventListenerProxy();
            	Naming.rebind(proxyAddress, eventProxy);
                if(debug) System.out.println(rmiName + " bound to existing registry at port " + portnum );

            } catch (RemoteException re) {
                if(debug) System.out.println("Naming.rebind("+ proxyAddress +", eventProxy): " + re);
                try {
                    eventProxy = new EventListenerProxy();
                    Registry r = LocateRegistry.createRegistry(portnum);
                    r.bind(rmiName, eventProxy);
                    if(debug) System.out.println(rmiName + " bound to newly created registry at port " + portnum );
                } catch(Exception e) {
                    eventProxy = null;
                    if(debug) e.printStackTrace();
                }
            } catch (Exception e) {
                if(debug) e.printStackTrace();
            }
        }
        return eventProxy;
    
public java.lang.StringgetProxyAddress()

        return proxyAddress;
    
public voidhandleNotification(javax.management.Notification n, java.lang.Object h)

        if (debug) System.out.println("EventListenerProxy:handleNotification(" + n + ")");
        NotificationListener listener = (NotificationListener)listenerTable.get((String)h);
        if (listener != null) {
            Object handback = handbackTable.get((String)h);
            listener.handleNotification(n,handback);
        } else {
            System.out.println("EventListenerProxy: listener id " + h + " not found");
        }
    
public voidremoveListener(java.lang.String id)

        if(listenerTable.remove(id) == null) {
            throw new ListenerNotFoundException();
        } else {
            handbackTable.remove(id);
        }