KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > remoting > rmi > ConnectionNotifier


1 package org.jboss.mx.remoting.rmi;
2
3 import java.io.IOException JavaDoc;
4 import javax.management.NotificationBroadcasterSupport JavaDoc;
5 import javax.management.remote.JMXConnectionNotification JavaDoc;
6 import javax.management.remote.JMXConnector JavaDoc;
7
8 import EDU.oswego.cs.dl.util.concurrent.SynchronizedLong;
9
10 /**
11  * Handles the firing of notifications related to the connection
12  * status of the connector.
13  *
14  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
15  */

16 public class ConnectionNotifier extends NotificationBroadcasterSupport JavaDoc
17 {
18    private JMXConnector JavaDoc connector;
19
20    private static SynchronizedLong sequenceNumber = new SynchronizedLong(0);
21
22    public ConnectionNotifier(JMXConnector JavaDoc connector)
23    {
24       this.connector = connector;
25    }
26
27    public void fireConnectedNotification()
28    {
29       JMXConnectionNotification JavaDoc notification = new JMXConnectionNotification JavaDoc(JMXConnectionNotification.OPENED,
30                                                                              connector,
31                                                                              getConnectionId(),
32                                                                              sequenceNumber.increment(),
33                                                                              "JMXConnector connected",
34                                                                              null);
35    sendNotification(notification);
36    }
37
38    private String JavaDoc getConnectionId()
39    {
40       String JavaDoc id = null;
41       try
42       {
43          id = connector.getConnectionId();
44       }
45       catch(IOException JavaDoc e)
46       {
47       }
48       return id;
49    }
50
51    public void fireClosedNotification()
52    {
53       JMXConnectionNotification JavaDoc notification = new JMXConnectionNotification JavaDoc(JMXConnectionNotification.CLOSED,
54                                                                              connector,
55                                                                              getConnectionId(),
56                                                                              sequenceNumber.increment(),
57                                                                              "JMXConnector closed",
58                                                                              null);
59       sendNotification(notification);
60    }
61 }
62
Popular Tags