01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package mx4j.remote;
10:
11: import java.io.IOException;
12: import javax.management.NotificationBroadcasterSupport;
13: import javax.management.remote.JMXConnectionNotification;
14: import javax.management.remote.JMXConnector;
15:
16: /**
17: * @version $Revision: 1.4 $
18: */
19: public class ConnectionNotificationEmitter extends
20: NotificationBroadcasterSupport {
21: private static long sequenceNumber;
22:
23: private JMXConnector connector;
24:
25: public ConnectionNotificationEmitter(JMXConnector connector) {
26: this .connector = connector;
27: }
28:
29: private long getNextNotificationNumber() {
30: synchronized (ConnectionNotificationEmitter.class) {
31: return sequenceNumber++;
32: }
33: }
34:
35: private String getConnectionId() {
36: try {
37: return connector.getConnectionId();
38: } catch (IOException x) {
39: return null;
40: }
41: }
42:
43: public void sendConnectionNotificationOpened() {
44: JMXConnectionNotification notification = new JMXConnectionNotification(
45: JMXConnectionNotification.OPENED, connector,
46: getConnectionId(), getNextNotificationNumber(),
47: "Connection opened", null);
48: sendNotification(notification);
49: }
50:
51: public void sendConnectionNotificationClosed() {
52: JMXConnectionNotification notification = new JMXConnectionNotification(
53: JMXConnectionNotification.CLOSED, connector,
54: getConnectionId(), getNextNotificationNumber(),
55: "Connection closed", null);
56: sendNotification(notification);
57: }
58:
59: public void sendConnectionNotificationFailed() {
60: JMXConnectionNotification notification = new JMXConnectionNotification(
61: JMXConnectionNotification.FAILED, connector,
62: getConnectionId(), getNextNotificationNumber(),
63: "Connection failed", null);
64: sendNotification(notification);
65: }
66:
67: public void sendConnectionNotificationLost(long howMany) {
68: JMXConnectionNotification notification = new JMXConnectionNotification(
69: JMXConnectionNotification.NOTIFS_LOST, connector,
70: getConnectionId(), getNextNotificationNumber(),
71: "Some notification (" + howMany + ") was lost", null);
72: sendNotification(notification);
73: }
74: }
|