KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > agent > ListenerRegistry


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.management.agent;
25
26 import java.util.Hashtable JavaDoc;
27 import java.rmi.RemoteException JavaDoc;
28 import javax.rmi.PortableRemoteObject JavaDoc;
29 import javax.naming.Context JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31
32 import javax.management.j2ee.*;
33 import javax.management.*;
34
35 //import com.sun.enterprise.util.ORBManager; //TBD SRI
36

37 /**
38  * ListenerRegistry provides an implementation of ListenerRegistration
39  * This implementation creates instances of RemoteListenerConnectors which
40  * are registered on the MEJB on behalf of the local listener.
41  *
42  * @author Hans Hrasna
43  */

44 public class ListenerRegistry implements ListenerRegistration {
45
46     private Hashtable JavaDoc listenerConnectors = new Hashtable JavaDoc();
47     private String JavaDoc OMG_ORB_INIT_PORT_PROPERTY = "org.omg.CORBA.ORBInitialPort";
48     private String JavaDoc serverAddress; // the hostname or ip address of the server
49
//private MEJB server; //TBD
50
private boolean debug = false;
51
52
53     public ListenerRegistry(String JavaDoc ip) {
54         serverAddress = ip;
55     }
56
57     /**
58      * Add a listener to a registered managed object.
59      *
60      * @param name The name of the managed object on which the listener should be added.
61      * @param listener The listener object which will handle the notifications emitted by the registered managed object.
62      * @param filter The filter object. If filter is null, no filtering will be performed before handling notifications.
63      * @param handback The context to be sent to the listener when a notification is emitted.
64      *
65      * @exception InstanceNotFoundException The managed object name provided does not match any of the registered managed objects.
66      *
67      */

68     public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object JavaDoc handback)
69         throws RemoteException JavaDoc {
70             /*
71         String proxyAddress = EventListenerProxy.getEventListenerProxy().getProxyAddress();
72         try {
73             if(debug)System.out.println("ListenerRegistry:addNotificationListener(" + listener + ") to " + name);
74             RemoteListenerConnector connector = new RemoteListenerConnector(proxyAddress);
75             getMBSUtility().addNotificationListener(name, connector, filter, connector.getId());
76             EventListenerProxy.getEventListenerProxy().addListener(connector.getId(), listener, handback);
77             listenerConnectors.put(listener, connector);
78         } catch (javax.management.InstanceNotFoundException inf) {
79             throw new java.rmi.RemoteException(inf.getMessage(), inf);
80         }
81              */

82     }
83
84
85     /**
86      * Remove a listener from a registered managed object.
87      *
88      * @param name The name of the managed object on which the listener should be removed.
89      * @param listener The listener object which will handle the notifications emitted by the registered managed object.
90      * This method will remove all the information related to this listener.
91      *
92      * @exception InstanceNotFoundException The managed object name provided does not match any of the registered managed objects.
93      * @exception ListenerNotFoundException The listener is not registered in the managed object.
94      */

95     public void removeNotificationListener(ObjectName name, NotificationListener listener)
96         throws RemoteException JavaDoc {
97             /*
98         EventListenerProxy proxy = EventListenerProxy.getEventListenerProxy();
99         try {
100             if(debug) {
101                 System.out.println("removeNotificationListener: " + listener);
102                 System.out.println("listenerProxy = " + listenerConnectors.get(((RemoteListenerConnector)listener).getId()));
103             }
104             RemoteListenerConnector connector = ((RemoteListenerConnector)listenerConnectors.get(listener));
105             getMBSUtility().removeNotificationListener(name, connector);
106             proxy.removeListener(connector.getId());
107             listenerConnectors.remove(listener);
108         } catch (javax.management.InstanceNotFoundException inf) {
109             throw new java.rmi.RemoteException(inf.getMessage(), inf);
110         } catch (javax.management.ListenerNotFoundException lnf) {
111             throw new java.rmi.RemoteException(lnf.getMessage(), lnf);
112         }
113              */

114     }
115
116     MBSUtility getMBSUtility(){
117         //TBD SRI
118
return MBSUtility.getMBSUtility();
119         //return com.sun.enterprise.Switch.getSwitch().getManagementObjectManager().getMEJBUtility();
120
}
121     /*
122     MEJB getMEJB() throws RemoteException {
123         if (server == null) {
124             try {
125                 Context ic = new InitialContext();
126                 String mejbJNDIName = System.getProperty("mejb.name","ejb/mgmt/MEJB");
127                 String initialPort = System.getProperty(OMG_ORB_INIT_PORT_PROPERTY);
128                 if (initialPort == null)
129                     initialPort = String.valueOf(ORBManager.getORBInitialPort());
130                 String corbaName = "corbaname:iiop:" + serverAddress + ":" + initialPort + "#" + mejbJNDIName;
131                 java.lang.Object objref = ic.lookup(corbaName);
132                 ManagementHome home = (ManagementHome)PortableRemoteObject.narrow(objref, ManagementHome.class);
133                 server = (MEJB)home.create();
134                 if (debug) System.out.println("ListenerRegistry connected to: " + corbaName);
135             } catch (RemoteException re) {
136                 throw re;
137             } catch (Exception e) {
138                 throw new RemoteException(e.getMessage(), e);
139             }
140         }
141         return server;
142     }
143
144      */

145 }
146
Popular Tags