001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jmx;
030:
031: import javax.management.MBeanNotificationInfo;
032: import javax.management.MBeanServerDelegate;
033: import javax.management.MBeanServerNotification;
034: import javax.management.NotificationFilter;
035: import javax.management.NotificationListener;
036: import javax.management.ObjectName;
037:
038: /**
039: * The main interface for retrieving and managing JMX objects.
040: */
041: public class MBeanServerDelegateImpl extends MBeanServerDelegate {
042: private static final ObjectName DELEGATE_NAME;
043:
044: private String _agentId;
045: private long _seq;
046:
047: MBeanServerDelegateImpl(String agentId) {
048: _agentId = agentId;
049: }
050:
051: /**
052: * Return the MBean server agent id.
053: */
054: public String getMBeanServerId() {
055: return _agentId;
056: }
057:
058: /**
059: * Returns the implementation vendor.
060: */
061: public String getImplementationName() {
062: return "Resin-JMX";
063: }
064:
065: /**
066: * Returns the implementation vendor.
067: */
068: public String getImplementationVendor() {
069: return "Caucho Technology";
070: }
071:
072: /**
073: * Returns the implementation version.
074: */
075: public String getImplementationVersion() {
076: return "Resin-" + com.caucho.Version.VERSION;
077: }
078:
079: /**
080: * Sends the register notification.
081: */
082: public void sendRegisterNotification(ObjectName name) {
083: serverNotification(name,
084: MBeanServerNotification.REGISTRATION_NOTIFICATION);
085: }
086:
087: /**
088: * Sends the register notification.
089: */
090: public void sendUnregisterNotification(ObjectName name) {
091: serverNotification(name,
092: MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
093: }
094:
095: public void addNotificationListener(NotificationListener listener,
096: NotificationFilter filter, Object handback) {
097: super .addNotificationListener(listener, filter, handback);
098: }
099:
100: /**
101: * Sends the notification
102: */
103: private void serverNotification(ObjectName name, String type) {
104: MBeanServerNotification notif;
105:
106: notif = new MBeanServerNotification(type, DELEGATE_NAME,
107: _seq++, name);
108:
109: sendNotification(notif);
110: }
111:
112: public MBeanNotificationInfo[] getNotificationInfo() {
113: MBeanNotificationInfo[] notifs = super .getNotificationInfo();
114:
115: return notifs;
116: }
117:
118: static {
119: ObjectName name = null;
120:
121: try {
122: name = new ObjectName(
123: "JMImplementation:type=MBeanServerDelegate");
124: } catch (Throwable e) {
125: e.printStackTrace();
126: }
127:
128: DELEGATE_NAME = name;
129: }
130: }
|