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

ListenerRegistry

public class ListenerRegistry extends Object implements ListenerRegistration
ListenerRegistry provides an implementation of ListenerRegistration This implementation creates instances of RemoteListenerConnectors which are registered on the MEJB on behalf of the local listener.
author
Hans Hrasna

Fields Summary
private Hashtable
listenerConnectors
private String
OMG_ORB_INIT_PORT_PROPERTY
private String
serverAddress
private Management
server
private boolean
debug
Constructors Summary
public ListenerRegistry(String ip)



       
        serverAddress = ip;
    
Methods Summary
public voidaddNotificationListener(javax.management.ObjectName name, javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
Add a listener to a registered managed object.

param
name The name of the managed object on which the listener should be added.
param
listener The listener object which will handle the notifications emitted by the registered managed object.
param
filter The filter object. If filter is null, no filtering will be performed before handling notifications.
param
handback The context to be sent to the listener when a notification is emitted.
exception
InstanceNotFoundException The managed object name provided does not match any of the registered managed objects.

        String proxyAddress = EventListenerProxy.getEventListenerProxy().getProxyAddress();
        try {
            if(debug)System.out.println("ListenerRegistry:addNotificationListener(" + listener + ") to " + name);
            RemoteListenerConnector connector = new RemoteListenerConnector(proxyAddress);
            getMEJBUtility().addNotificationListener(name, connector, filter, connector.getId());
            EventListenerProxy.getEventListenerProxy().addListener(connector.getId(), listener, handback);
        	listenerConnectors.put(listener, connector);
        } catch (javax.management.InstanceNotFoundException inf) {
            throw new java.rmi.RemoteException(inf.getMessage(), inf);
        }
    
ManagementgetMEJB()

        if(server == null) {
            try {
                Context ic = new InitialContext();
                String ejbName = System.getProperty("mejb.name","ejb/mgmt/MEJB");
                java.lang.Object objref = ic.lookup(ejbName);
                ManagementHome home = (ManagementHome)PortableRemoteObject.narrow(objref, ManagementHome.class);
                server = (Management)home.create();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        /*if (server == null) {
            try {
            	Context ic = new InitialContext();
        		String mejbJNDIName = System.getProperty("mejb.name","ejb/mgmt/MEJB");
                String initialPort = System.getProperty(OMG_ORB_INIT_PORT_PROPERTY);
        		if (initialPort == null)
            		initialPort = String.valueOf(ORBManager.getORBInitialPort());
       			String corbaName = "corbaname:iiop:" + serverAddress + ":" + initialPort + "#" + mejbJNDIName;
        		java.lang.Object objref = ic.lookup(corbaName);
        		ManagementHome home = (ManagementHome)PortableRemoteObject.narrow(objref, ManagementHome.class);
        		server = (MEJB)home.create();
                if (debug) System.out.println("ListenerRegistry connected to: " + corbaName);
        	} catch (RemoteException re) {
            	throw re;
        	} catch (Exception e) {
            	throw new RemoteException(e.getMessage(), e);
        	}
        }*/
        return server;
    
MEJBUtilitygetMEJBUtility()

                                                               
        return MEJBUtility.getMEJBUtility();
    
public voidremoveNotificationListener(javax.management.ObjectName name, javax.management.NotificationListener listener)
Remove a listener from a registered managed object.

param
name The name of the managed object on which the listener should be removed.
param
listener The listener object which will handle the notifications emitted by the registered managed object. This method will remove all the information related to this listener.
exception
InstanceNotFoundException The managed object name provided does not match any of the registered managed objects.
exception
ListenerNotFoundException The listener is not registered in the managed object.

        EventListenerProxy proxy = EventListenerProxy.getEventListenerProxy();
        try {
            if(debug) {
                System.out.println("removeNotificationListener: " + listener);
            	System.out.println("listenerProxy = " + listenerConnectors.get(((RemoteListenerConnector)listener).getId()));
            }
            RemoteListenerConnector connector = ((RemoteListenerConnector)listenerConnectors.get(listener));
        	getMEJBUtility().removeNotificationListener(name, connector);
            proxy.removeListener(connector.getId());
            listenerConnectors.remove(listener);
        } catch (javax.management.InstanceNotFoundException inf) {
            throw new java.rmi.RemoteException(inf.getMessage(), inf);
        } catch (javax.management.ListenerNotFoundException lnf) {
            throw new java.rmi.RemoteException(lnf.getMessage(), lnf);
        }