KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > remote > ConnectionNotificationEmitter


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.remote;
10
11 import java.io.IOException JavaDoc;
12 import javax.management.NotificationBroadcasterSupport JavaDoc;
13 import javax.management.remote.JMXConnectionNotification JavaDoc;
14 import javax.management.remote.JMXConnector JavaDoc;
15
16 /**
17  * @version $Revision: 1.4 $
18  */

19 public class ConnectionNotificationEmitter extends NotificationBroadcasterSupport JavaDoc
20 {
21    private static long sequenceNumber;
22
23    private JMXConnector JavaDoc connector;
24
25    public ConnectionNotificationEmitter(JMXConnector JavaDoc connector)
26    {
27       this.connector = connector;
28    }
29
30    private long getNextNotificationNumber()
31    {
32       synchronized (ConnectionNotificationEmitter.class)
33       {
34          return sequenceNumber++;
35       }
36    }
37
38    private String JavaDoc getConnectionId()
39    {
40       try
41       {
42          return connector.getConnectionId();
43       }
44       catch (IOException JavaDoc x)
45       {
46          return null;
47       }
48    }
49
50    public void sendConnectionNotificationOpened()
51    {
52       JMXConnectionNotification JavaDoc notification = new JMXConnectionNotification JavaDoc(JMXConnectionNotification.OPENED, connector, getConnectionId(), getNextNotificationNumber(), "Connection opened", null);
53       sendNotification(notification);
54    }
55
56    public void sendConnectionNotificationClosed()
57    {
58       JMXConnectionNotification JavaDoc notification = new JMXConnectionNotification JavaDoc(JMXConnectionNotification.CLOSED, connector, getConnectionId(), getNextNotificationNumber(), "Connection closed", null);
59       sendNotification(notification);
60    }
61
62    public void sendConnectionNotificationFailed()
63    {
64       JMXConnectionNotification JavaDoc notification = new JMXConnectionNotification JavaDoc(JMXConnectionNotification.FAILED, connector, getConnectionId(), getNextNotificationNumber(), "Connection failed", null);
65       sendNotification(notification);
66    }
67
68    public void sendConnectionNotificationLost(long howMany)
69    {
70       JMXConnectionNotification JavaDoc notification = new JMXConnectionNotification JavaDoc(JMXConnectionNotification.NOTIFS_LOST, connector, getConnectionId(), getNextNotificationNumber(), "Some notification (" + howMany + ") was lost", null);
71       sendNotification(notification);
72    }
73 }
74
Popular Tags