KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > jmx > AbstractStandardMBean


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Marc Wick.
20  * Contributor(s): ______________________.
21  */

22
23 package org.continuent.sequoia.controller.jmx;
24
25 import javax.management.ListenerNotFoundException JavaDoc;
26 import javax.management.MBeanAttributeInfo JavaDoc;
27 import javax.management.MBeanConstructorInfo JavaDoc;
28 import javax.management.MBeanInfo JavaDoc;
29 import javax.management.MBeanNotificationInfo JavaDoc;
30 import javax.management.MBeanOperationInfo JavaDoc;
31 import javax.management.MBeanParameterInfo JavaDoc;
32 import javax.management.NotCompliantMBeanException JavaDoc;
33 import javax.management.Notification JavaDoc;
34 import javax.management.NotificationBroadcasterSupport JavaDoc;
35 import javax.management.NotificationEmitter JavaDoc;
36 import javax.management.NotificationFilter JavaDoc;
37 import javax.management.NotificationListener JavaDoc;
38 import javax.management.StandardMBean JavaDoc;
39
40 import org.continuent.sequoia.common.i18n.JmxTranslate;
41
42 /**
43  * This class defines a AbstractStandardMBean
44  *
45  * @author <a HREF="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
46  * @version 1.0
47  */

48 public abstract class AbstractStandardMBean extends StandardMBean JavaDoc
49     implements
50       NotificationEmitter JavaDoc
51 {
52   /**
53    * the broadcaster instance we write a wrapper for
54    */

55   private transient NotificationBroadcasterSupport JavaDoc broadcaster;
56
57   /**
58    * Creates a new <code>AbstractStandardMBean.java</code> object
59    *
60    * @param mbeanInterface The Management Interface exported by this MBean.
61    * @throws NotCompliantMBeanException - if the mbeanInterface does not follow
62    * JMX design patterns for Management Interfaces, or if this does
63    * not implement the specified interface.
64    */

65   public AbstractStandardMBean(Class JavaDoc mbeanInterface)
66       throws NotCompliantMBeanException JavaDoc
67   {
68     super(mbeanInterface);
69     broadcaster = new NotificationBroadcasterSupport JavaDoc();
70   }
71
72   /**
73    * @see javax.management.NotificationBroadcaster#addNotificationListener(javax.management.NotificationListener,
74    * javax.management.NotificationFilter, java.lang.Object)
75    */

76   public void addNotificationListener(NotificationListener JavaDoc listener,
77       NotificationFilter JavaDoc filter, Object JavaDoc handback)
78   {
79     broadcaster.addNotificationListener(listener, filter, handback);
80   }
81
82   /**
83    * Returns the notification broadcaster.
84    *
85    * @return a <code>NotificationBroadcasterSupport</code>
86    */

87   public NotificationBroadcasterSupport JavaDoc getBroadcaster()
88   {
89     return broadcaster;
90   }
91
92   /**
93    * @see javax.management.NotificationBroadcaster#getNotificationInfo()
94    */

95   public MBeanNotificationInfo JavaDoc[] getNotificationInfo()
96   {
97     // is the broadcaster already initialized ?
98
if (broadcaster == null)
99       // no we return empty array
100
return new MBeanNotificationInfo JavaDoc[0];
101
102     return broadcaster.getNotificationInfo();
103   }
104
105   /**
106    * @see javax.management.NotificationBroadcaster#removeNotificationListener(javax.management.NotificationListener)
107    */

108   public void removeNotificationListener(NotificationListener JavaDoc listener)
109       throws ListenerNotFoundException JavaDoc
110   {
111     broadcaster.removeNotificationListener(listener);
112   }
113
114   /**
115    * @see javax.management.NotificationEmitter#removeNotificationListener(javax.management.NotificationListener,
116    * javax.management.NotificationFilter, java.lang.Object)
117    */

118   public void removeNotificationListener(NotificationListener JavaDoc listener,
119       NotificationFilter JavaDoc filter, Object JavaDoc handback)
120       throws ListenerNotFoundException JavaDoc
121   {
122     broadcaster.removeNotificationListener(listener, filter, handback);
123   }
124
125   /**
126    * Sends a notification.
127    *
128    * @param notification The notification to send.
129    */

130   public void sendNotification(Notification JavaDoc notification)
131   {
132     broadcaster.sendNotification(notification);
133   }
134
135   //
136
// StandardMBean methods
137
//
138

139   /**
140    * Allow to retrieve internationalization description on mbeans as well
141    *
142    * @return part of the key to look for in the translation file.
143    */

144   public abstract String JavaDoc getAssociatedString();
145
146   /**
147    * Returns the description of the MBean.
148    *
149    * @return a <code>String</code> containing the description
150    */

151   protected String JavaDoc getDescription(MBeanInfo JavaDoc info)
152   {
153     return JmxTranslate.get("mbean." + getAssociatedString() + ".description");
154   }
155
156   /**
157    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanConstructorInfo)
158    */

159   protected String JavaDoc getDescription(MBeanConstructorInfo JavaDoc ctor)
160   {
161     return JmxTranslate.get("mbean." + getAssociatedString() + ".constructor."
162         + ctor.getSignature().length);
163   }
164
165   /**
166    * @see javax.management.StandardMBean#getParameterName(javax.management.MBeanConstructorInfo,
167    * javax.management.MBeanParameterInfo, int)
168    */

169   protected String JavaDoc getParameterName(MBeanConstructorInfo JavaDoc ctor,
170       MBeanParameterInfo JavaDoc param, int sequence)
171   {
172     return JmxTranslate.get("mbean." + getAssociatedString() + ".constructor."
173         + ctor.getSignature().length + ".parameter.name." + sequence);
174   }
175
176   /**
177    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanConstructorInfo,
178    * javax.management.MBeanParameterInfo, int)
179    */

180   protected String JavaDoc getDescription(MBeanConstructorInfo JavaDoc ctor,
181       MBeanParameterInfo JavaDoc param, int sequence)
182   {
183     return JmxTranslate.get("mbean." + getAssociatedString() + ".constructor."
184         + ctor.getSignature().length + ".parameter.description." + sequence);
185   }
186
187   /**
188    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanAttributeInfo)
189    */

190   protected String JavaDoc getDescription(MBeanAttributeInfo JavaDoc info)
191   {
192     return JmxTranslate.get("mbean." + getAssociatedString() + ".attribute."
193         + info.getName());
194   }
195
196   /**
197    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanOperationInfo)
198    */

199   protected String JavaDoc getDescription(MBeanOperationInfo JavaDoc info)
200   {
201     return JmxTranslate.get("mbean." + getAssociatedString() + "."
202         + info.getName());
203   }
204
205   /**
206    * @see javax.management.StandardMBean#getParameterName(javax.management.MBeanOperationInfo,
207    * javax.management.MBeanParameterInfo, int)
208    */

209   protected String JavaDoc getParameterName(MBeanOperationInfo JavaDoc op,
210       MBeanParameterInfo JavaDoc param, int sequence)
211   {
212     return JmxTranslate.get("mbean." + getAssociatedString() + "."
213         + op.getName() + ".parameter.name." + sequence);
214   }
215
216   /**
217    * @see javax.management.StandardMBean#getDescription(javax.management.MBeanOperationInfo,
218    * javax.management.MBeanParameterInfo, int)
219    */

220   protected String JavaDoc getDescription(MBeanOperationInfo JavaDoc op,
221       MBeanParameterInfo JavaDoc param, int sequence)
222   {
223     return JmxTranslate.get("mbean." + getAssociatedString() + "."
224         + op.getName() + ".parameter.description." + sequence);
225   }
226 }
Popular Tags