KickJava   Java API By Example, From Geeks To Geeks.

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


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.rmi.Naming JavaDoc;
27 import javax.management.*;
28
29 /**
30  * RemoteListenerConnectors are instantiated by the ListenerRegistry
31  * with the address of the callback port of the RemoteEventListener
32  * and then registered with the MBeanServer by the MEJB.
33  *
34  * @author Hans Hrasna
35  */

36 public class RemoteListenerConnector implements NotificationListener, java.io.Serializable JavaDoc {
37
38     private String JavaDoc proxyAddress; // the RMI address of the remote event listener
39
private RemoteEventListener listener = null; //the remote event listener
40
private MBeanServer server = null; // the MBeanServer holds the object this is listening to
41
// which is set when this is registered in the MEJB
42
private String JavaDoc id = hashCode() + ":" + System.currentTimeMillis();
43     private boolean debug = false;
44
45     public RemoteListenerConnector(String JavaDoc address) {
46         proxyAddress = address;
47     }
48
49     public void handleNotification(Notification evt, Object JavaDoc h) {
50         try {
51             if (debug) System.out.println("RemoteListenerConnector.handleNotification()");
52             if (listener == null) {
53                 listener = (RemoteEventListener)Naming.lookup(proxyAddress);
54             }
55             listener.handleNotification(evt, h);
56         } catch (java.rmi.RemoteException JavaDoc ce) {
57             if (server != null) {
58                 if (debug) System.out.println("RemoteListenerConnector.server.removeNotificationListener("+ (ObjectName)evt.getSource() + ", " + this + ")");
59                 try {
60                     server.removeNotificationListener((ObjectName)evt.getSource(), this);
61                 } catch (javax.management.ListenerNotFoundException JavaDoc e) {
62                     if(debug) System.out.println(toString() + ": " + e); //occurs normally if event was fowarded from J2EEDomain
63
} catch (Exception JavaDoc e1) {
64                     System.out.println(toString() + ": " + e1);
65                 }
66             }
67         } catch (Exception JavaDoc e) {
68             System.out.println(toString() + ": " + e);
69             if (debug) {
70                 try {
71                     System.out.println("Naming.list(\"//localhost:1100\")");
72                     String JavaDoc [] names = Naming.list("//localhost:1100");
73                     for(int x=0;x<names.length;x++) {
74                         System.out.println("names["+x+"] = " + names[x]);
75                     }
76                 } catch(Exception JavaDoc e1) {
77                     e1.printStackTrace();
78                 }
79             }
80         }
81     }
82
83     public String JavaDoc getId() {
84         return id;
85     }
86
87     public void setMBeanServer(MBeanServer s) {
88         server = s;
89     }
90 }
91
Popular Tags