001: /* JFox, the OpenSource J2EE Application Server
002: *
003: * Copyright (C) 2002 huihoo.org
004: * Distributable under GNU LGPL license
005: * See the GNU Lesser General Public License for more details.
006: */
007:
008: package javax.management;
009:
010: import java.net.InetAddress;
011: import java.net.UnknownHostException;
012:
013: import org.huihoo.jfox.jmx.ExtendedMBeanServerNotification;
014:
015: /**
016: * Represents the Mbean server from the management point of view.
017: * The MBeanServerDelegate MBean emits the MBeanServerNotifications when an MBean is
018: * registered/deregistered in the MBean server.
019: *
020: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
021: */
022:
023: public class MBeanServerDelegate implements MBeanServerDelegateMBean,
024: NotificationBroadcaster {
025:
026: static final String JMX_SPECIFICATION_NAME = "Java Management Extensions";
027: static final String JMX_SPECIFICATION_VERSION = "1.2";
028: static final String JMX_SPECIFICATION_VENDOR = "Sun Microsystems";
029: static final String JMX_IMPLEMENTATION_NAME = "JFoxMX";
030: static final String JMX_IMPLEMENTATION_VENDOR = "huihoo.org";
031: static final String JMX_IMPLEMENTATION_VERSION = "v1.2";
032:
033: /** The MBean server agent identification.*/
034: private String mbeanServerId; // mbserverId = hostname_mserverdelegate-address
035: /** The NotificationBroadcasterSupport object that sends the notifications */
036: private NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport();
037:
038: protected static ObjectName delegateObjectName;
039: static {
040: try {
041: delegateObjectName = new ObjectName(
042: "JMImplementation:type=MBeanServerDelegate");
043: } catch (MalformedObjectNameException ignore) {
044: }
045: }
046:
047: protected long sequence = 0;
048:
049: public MBeanServerDelegate() {
050: String host = "localhost";
051: try {
052: host = InetAddress.getLocalHost().getHostName();
053: } catch (UnknownHostException unknownhostexception) {
054: }
055:
056: // mbserverId = hostname_mserverdelegate-address
057: mbeanServerId = new String(host + "_" + this .toString());
058:
059: }
060:
061: /**
062: * Returns the MBean server agent identification
063: */
064: public String getMBeanServerId() {
065: return mbeanServerId;
066: }
067:
068: /**
069: * Returns the full name of the JMX specification implemented
070: * by this product.
071: */
072: public String getSpecificationName() {
073: return JMX_SPECIFICATION_NAME;
074: }
075:
076: /**
077: * Returns the version of the JMX specification implemented
078: * by this product.
079: */
080: public String getSpecificationVersion() {
081: return JMX_IMPLEMENTATION_VERSION;
082: }
083:
084: /**
085: * Returns the vendor of the JMX specification implemented
086: * by this product.
087: */
088: public String getSpecificationVendor() {
089: return JMX_IMPLEMENTATION_VENDOR;
090: }
091:
092: /**
093: * Returns the JMX implementation name (the name of this product).
094: */
095: public String getImplementationName() {
096: return JMX_IMPLEMENTATION_NAME;
097: }
098:
099: /**
100: * Returns the JMX implementation version (the version of this product).
101: */
102: public String getImplementationVersion() {
103: return JMX_IMPLEMENTATION_VERSION;
104: }
105:
106: /**
107: * Returns the JMX implementation vendor (the vendor of this product).
108: */
109: public String getImplementationVendor() {
110: return JMX_SPECIFICATION_VENDOR;
111: }
112:
113: /**
114: * Enables to add a listener to a registered MBean.
115: *
116: * @param listener The listener object which will handle the notifications emitted by the registered MBean.
117: * @param filter The filter object. If filter is null, no filtering will be performed before handling notifications.
118: * @param handback The context to be sent to the listener when a notification is emitted.
119: *
120: * @exception IllegalArgumentException Listener parameter is null.
121: */
122: public void addNotificationListener(NotificationListener listener,
123: NotificationFilter filter, Object handback)
124: throws IllegalArgumentException {
125: broadcaster.addNotificationListener(listener, filter, handback);
126: }
127:
128: /**
129: * Enables to remove a listener from a registered MBean.
130: *
131: * @param listener The listener object which will handle the notifications emitted by the registered MBean.
132: * This method will remove all the information related to this listener.
133: *
134: * @exception ListenerNotFoundException The listener is not registered in the MBean.
135: */
136: public void removeNotificationListener(NotificationListener listener)
137: throws ListenerNotFoundException {
138: broadcaster.removeNotificationListener(listener);
139: }
140:
141: /**
142: * Enables the MBean server to send a notification.
143: *
144: * @param notification The notification to send.
145: */
146: public void sendNotification(Notification notification) {
147: broadcaster.sendNotification(notification);
148: }
149:
150: /**
151: * Returns a NotificationInfo object contaning the name of the Java class of the notification
152: * and the notification types sent.
153: *
154: * as extension, add the ExtendedMBeanServerNotification
155: */
156: public MBeanNotificationInfo[] getNotificationInfo() {
157: MBeanNotificationInfo ninfo[] = {
158: new MBeanNotificationInfo(
159: new String[] {
160: MBeanServerNotification.REGISTRATION_NOTIFICATION,
161: MBeanServerNotification.UNREGISTRATION_NOTIFICATION },
162: "javax.management.MBeanServerNotification",
163: "Notifications sent by the MBeanServerDelegate MBean When MBean Registered or Unregistered"),
164: new MBeanNotificationInfo(
165: new String[] {
166: ExtendedMBeanServerNotification.DESERIALIZE_NOTIFICATION,
167: ExtendedMBeanServerNotification.GET_ATTRIBUTE_NOTIFICATION,
168: ExtendedMBeanServerNotification.GET_ATTRIBUTES_NOTIFICATION,
169: ExtendedMBeanServerNotification.GET_MBEANINFO_NOTIFICATION,
170: ExtendedMBeanServerNotification.GET_OBJECTINSTANCE_NOTIFICATION,
171: ExtendedMBeanServerNotification.INVOKE_NOTIFICATION,
172: ExtendedMBeanServerNotification.ISINSTANCEOF_NOTIFICATION,
173: ExtendedMBeanServerNotification.ISREGISTERED_NOTIFICATION,
174: ExtendedMBeanServerNotification.QUERYMBEANS_NOTIFICATION,
175: ExtendedMBeanServerNotification.REMOVE_NOTIFICATIONLISTENER_NOTIFICATION,
176: ExtendedMBeanServerNotification.SET_ATTRIBUTE_NOTIFICATION,
177: ExtendedMBeanServerNotification.SET_ATTRIBUTES_NOTIFICATION, },
178: "javax.management.ExtendedMBeanServerNotification",
179: "extension Notifications sent by the MBeanServerDelegate MBean exception the MBean Registered or Unregistered")
180:
181: };
182: return ninfo;
183: }
184:
185: /*
186: public void sendNotification(String type ,ObjectName objectName){
187: if(!(type.equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) && !(type.equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)))
188: throw new RuntimeOperationsException(new IllegalArgumentException("Wrong type of MBeanServerNotifacation " + type));
189:
190: MBeanServerNotification notification = new MBeanServerNotification(type, delegateObjectName, sequence++, objectName);
191: this.sendNotification(notification);
192: }
193: */
194:
195: }
|