001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Marc Wick.
020: * Contributor(s): ______________________.
021: */package org.continuent.sequoia.controller.jmx;
022:
023: import javax.management.ListenerNotFoundException;
024: import javax.management.MBeanAttributeInfo;
025: import javax.management.MBeanConstructorInfo;
026: import javax.management.MBeanInfo;
027: import javax.management.MBeanNotificationInfo;
028: import javax.management.MBeanOperationInfo;
029: import javax.management.MBeanParameterInfo;
030: import javax.management.NotCompliantMBeanException;
031: import javax.management.Notification;
032: import javax.management.NotificationBroadcasterSupport;
033: import javax.management.NotificationEmitter;
034: import javax.management.NotificationFilter;
035: import javax.management.NotificationListener;
036: import javax.management.StandardMBean;
037:
038: import org.continuent.sequoia.common.i18n.JmxTranslate;
039:
040: /**
041: * This class defines a AbstractStandardMBean
042: *
043: * @author <a href="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
044: * @version 1.0
045: */
046: public abstract class AbstractStandardMBean extends StandardMBean
047: implements NotificationEmitter {
048: /**
049: * the broadcaster instance we write a wrapper for
050: */
051: private transient NotificationBroadcasterSupport broadcaster;
052:
053: /**
054: * Creates a new <code>AbstractStandardMBean.java</code> object
055: *
056: * @param mbeanInterface The Management Interface exported by this MBean.
057: * @throws NotCompliantMBeanException - if the mbeanInterface does not follow
058: * JMX design patterns for Management Interfaces, or if this does
059: * not implement the specified interface.
060: */
061: public AbstractStandardMBean(Class mbeanInterface)
062: throws NotCompliantMBeanException {
063: super (mbeanInterface);
064: broadcaster = new NotificationBroadcasterSupport();
065: }
066:
067: /**
068: * @see javax.management.NotificationBroadcaster#addNotificationListener(javax.management.NotificationListener,
069: * javax.management.NotificationFilter, java.lang.Object)
070: */
071: public void addNotificationListener(NotificationListener listener,
072: NotificationFilter filter, Object handback) {
073: broadcaster.addNotificationListener(listener, filter, handback);
074: }
075:
076: /**
077: * Returns the notification broadcaster.
078: *
079: * @return a <code>NotificationBroadcasterSupport</code>
080: */
081: public NotificationBroadcasterSupport getBroadcaster() {
082: return broadcaster;
083: }
084:
085: /**
086: * @see javax.management.NotificationBroadcaster#getNotificationInfo()
087: */
088: public MBeanNotificationInfo[] getNotificationInfo() {
089: // is the broadcaster already initialized ?
090: if (broadcaster == null)
091: // no we return empty array
092: return new MBeanNotificationInfo[0];
093:
094: return broadcaster.getNotificationInfo();
095: }
096:
097: /**
098: * @see javax.management.NotificationBroadcaster#removeNotificationListener(javax.management.NotificationListener)
099: */
100: public void removeNotificationListener(NotificationListener listener)
101: throws ListenerNotFoundException {
102: broadcaster.removeNotificationListener(listener);
103: }
104:
105: /**
106: * @see javax.management.NotificationEmitter#removeNotificationListener(javax.management.NotificationListener,
107: * javax.management.NotificationFilter, java.lang.Object)
108: */
109: public void removeNotificationListener(
110: NotificationListener listener, NotificationFilter filter,
111: Object handback) throws ListenerNotFoundException {
112: broadcaster.removeNotificationListener(listener, filter,
113: handback);
114: }
115:
116: /**
117: * Sends a notification.
118: *
119: * @param notification The notification to send.
120: */
121: public void sendNotification(Notification notification) {
122: broadcaster.sendNotification(notification);
123: }
124:
125: //
126: // StandardMBean methods
127: //
128:
129: /**
130: * Allow to retrieve internationalization description on mbeans as well
131: *
132: * @return part of the key to look for in the translation file.
133: */
134: public abstract String getAssociatedString();
135:
136: /**
137: * Returns the description of the MBean.
138: *
139: * @return a <code>String</code> containing the description
140: */
141: protected String getDescription(MBeanInfo info) {
142: return JmxTranslate.get("mbean." + getAssociatedString()
143: + ".description");
144: }
145:
146: /**
147: * @see javax.management.StandardMBean#getDescription(javax.management.MBeanConstructorInfo)
148: */
149: protected String getDescription(MBeanConstructorInfo ctor) {
150: return JmxTranslate.get("mbean." + getAssociatedString()
151: + ".constructor." + ctor.getSignature().length);
152: }
153:
154: /**
155: * @see javax.management.StandardMBean#getParameterName(javax.management.MBeanConstructorInfo,
156: * javax.management.MBeanParameterInfo, int)
157: */
158: protected String getParameterName(MBeanConstructorInfo ctor,
159: MBeanParameterInfo param, int sequence) {
160: return JmxTranslate.get("mbean." + getAssociatedString()
161: + ".constructor." + ctor.getSignature().length
162: + ".parameter.name." + sequence);
163: }
164:
165: /**
166: * @see javax.management.StandardMBean#getDescription(javax.management.MBeanConstructorInfo,
167: * javax.management.MBeanParameterInfo, int)
168: */
169: protected String getDescription(MBeanConstructorInfo ctor,
170: MBeanParameterInfo param, int sequence) {
171: return JmxTranslate.get("mbean." + getAssociatedString()
172: + ".constructor." + ctor.getSignature().length
173: + ".parameter.description." + sequence);
174: }
175:
176: /**
177: * @see javax.management.StandardMBean#getDescription(javax.management.MBeanAttributeInfo)
178: */
179: protected String getDescription(MBeanAttributeInfo info) {
180: return JmxTranslate.get("mbean." + getAssociatedString()
181: + ".attribute." + info.getName());
182: }
183:
184: /**
185: * @see javax.management.StandardMBean#getDescription(javax.management.MBeanOperationInfo)
186: */
187: protected String getDescription(MBeanOperationInfo info) {
188: return JmxTranslate.get("mbean." + getAssociatedString() + "."
189: + info.getName());
190: }
191:
192: /**
193: * @see javax.management.StandardMBean#getParameterName(javax.management.MBeanOperationInfo,
194: * javax.management.MBeanParameterInfo, int)
195: */
196: protected String getParameterName(MBeanOperationInfo op,
197: MBeanParameterInfo param, int sequence) {
198: return JmxTranslate.get("mbean." + getAssociatedString() + "."
199: + op.getName() + ".parameter.name." + sequence);
200: }
201:
202: /**
203: * @see javax.management.StandardMBean#getDescription(javax.management.MBeanOperationInfo,
204: * javax.management.MBeanParameterInfo, int)
205: */
206: protected String getDescription(MBeanOperationInfo op,
207: MBeanParameterInfo param, int sequence) {
208: return JmxTranslate.get("mbean." + getAssociatedString() + "."
209: + op.getName() + ".parameter.description." + sequence);
210: }
211: }
|