001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)NotificationServiceMBeanImpl.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.esb.management.impl.notification;
030:
031: import java.io.Serializable;
032:
033: import javax.management.Attribute;
034: import javax.management.AttributeList;
035: import javax.management.AttributeNotFoundException;
036: import javax.management.DynamicMBean;
037: import javax.management.InstanceNotFoundException;
038: import javax.management.InvalidAttributeValueException;
039: import javax.management.MBeanAttributeInfo;
040: import javax.management.MBeanConstructorInfo;
041: import javax.management.MBeanException;
042: import javax.management.MBeanInfo;
043: import javax.management.MBeanNotificationInfo;
044: import javax.management.MBeanOperationInfo;
045: import javax.management.Notification;
046: import javax.management.NotificationBroadcasterSupport;
047: import javax.management.NotificationListener;
048: import javax.management.ObjectName;
049: import javax.management.ReflectionException;
050:
051: import com.sun.esb.management.api.notification.EventNotificationListener;
052: import com.sun.esb.management.api.notification.NotificationService;
053: import com.sun.esb.management.common.ManagementRemoteException;
054: import com.sun.jbi.EnvironmentContext;
055: import com.sun.jbi.management.MBeanNames;
056: import com.sun.jbi.ui.common.I18NBundle;
057:
058: /**
059: * @author graj
060: *
061: */
062: public class NotificationServiceMBeanImpl extends
063: NotificationBroadcasterSupport implements NotificationListener,
064: DynamicMBean, Serializable, NotificationService {
065: static final long serialVersionUID = -1L;
066:
067: private String name = "NotificationService";
068: private String description = "Notification Service Broadcaster";
069:
070: /** i18n */
071: private static I18NBundle I18NBUNDLE = null;
072:
073: /** Jbi Environment context. */
074: protected EnvironmentContext environmentContext;
075:
076: /**
077: * Events that generate notifications.
078: */
079: enum EventType {
080: Installed, Upgraded, Uninstalled, Deployed, Undeployed, Ready, Started, Stopped, ShutDown
081: }
082:
083: /**
084: * Sources of notifications.
085: */
086: enum SourceType {
087: JBIRuntime, BindingComponent, ServiceEngine, SharedLibrary, ServiceUnit, ServiceAssembly
088: }
089:
090: /**
091: * Common prefix for all notification messages.
092: */
093: static final String JBI_PREFIX = "com.sun.jbi.";
094:
095: /**
096: * Notification types emitted by the runtime.
097: */
098: static final String[] NOTIFICATION_TYPES = {
099: JBI_PREFIX + EventType.Ready + "." + SourceType.JBIRuntime,
100: JBI_PREFIX + EventType.Started + "."
101: + SourceType.JBIRuntime,
102: JBI_PREFIX + EventType.Stopped + "."
103: + SourceType.JBIRuntime,
104: JBI_PREFIX + EventType.Installed + "."
105: + SourceType.SharedLibrary,
106: JBI_PREFIX + EventType.Uninstalled + "."
107: + SourceType.SharedLibrary,
108: JBI_PREFIX + EventType.Installed + "."
109: + SourceType.BindingComponent,
110: JBI_PREFIX + EventType.Started + "."
111: + SourceType.BindingComponent,
112: JBI_PREFIX + EventType.Stopped + "."
113: + SourceType.BindingComponent,
114: JBI_PREFIX + EventType.ShutDown + "."
115: + SourceType.BindingComponent,
116: JBI_PREFIX + EventType.Uninstalled + "."
117: + SourceType.BindingComponent,
118: JBI_PREFIX + EventType.Installed + "."
119: + SourceType.ServiceEngine,
120: JBI_PREFIX + EventType.Started + "."
121: + SourceType.ServiceEngine,
122: JBI_PREFIX + EventType.Stopped + "."
123: + SourceType.ServiceEngine,
124: JBI_PREFIX + EventType.ShutDown + "."
125: + SourceType.ServiceEngine,
126: JBI_PREFIX + EventType.Uninstalled + "."
127: + SourceType.ServiceEngine,
128: JBI_PREFIX + EventType.Deployed + "."
129: + SourceType.ServiceAssembly,
130: JBI_PREFIX + EventType.Started + "."
131: + SourceType.ServiceAssembly,
132: JBI_PREFIX + EventType.Stopped + "."
133: + SourceType.ServiceAssembly,
134: JBI_PREFIX + EventType.ShutDown + "."
135: + SourceType.ServiceAssembly,
136: JBI_PREFIX + EventType.Undeployed + "."
137: + SourceType.ServiceAssembly,
138: JBI_PREFIX + EventType.Deployed + "."
139: + SourceType.ServiceUnit,
140: JBI_PREFIX + EventType.Started + "."
141: + SourceType.ServiceUnit,
142: JBI_PREFIX + EventType.Stopped + "."
143: + SourceType.ServiceUnit,
144: JBI_PREFIX + EventType.ShutDown + "."
145: + SourceType.ServiceUnit,
146: JBI_PREFIX + EventType.Undeployed + "."
147: + SourceType.ServiceUnit };
148:
149: /**
150: * Class name for notifications emitted by the runtime.
151: */
152: static final String NOTIFICATION_CLASS_NAME = "javax.management.Notification";
153:
154: /**
155: * Desription for notifications emitted by the runtime.
156: */
157: static final String NOTIFICATION_DESCRIPTION = "JBI runtime event";
158:
159: static final String[] ITEM_NAMES = { "EventType", "SourceType",
160: "TargetName", "SourceName", "ServiceAssemblyName",
161: "ComponentName" };
162:
163: /** default constructor */
164: public NotificationServiceMBeanImpl(EnvironmentContext anEnvContext) {
165: this .environmentContext = anEnvContext;
166: this .registerForLocalNotifications();
167: }
168:
169: /**
170: * Handles event notifications from the runtime and sends to remote clients
171: * @param a notification
172: * @param a handback
173: *
174: * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, java.lang.Object)
175: */
176: public void handleNotification(Notification notification,
177: Object handback) {
178: super .sendNotification(notification);
179: }
180:
181: /**
182: * Retrieve an attribute
183: * @param the attribute name
184: * @return the attribute value
185: *
186: * @see javax.management.DynamicMBean#getAttribute(java.lang.String)
187: */
188: public Object getAttribute(String attribute)
189: throws AttributeNotFoundException, MBeanException,
190: ReflectionException {
191: if (attribute.equals("name")) {
192: return getName();
193: }
194: if (attribute.equals("description")) {
195: return getDescription();
196: }
197: return null;
198: }
199:
200: /**
201: * Get an attribute list
202: * @param the list of attribute names
203: * @return the attributelist
204: * @see javax.management.DynamicMBean#getAttributes(java.lang.String[])
205: */
206: public AttributeList getAttributes(String[] attributes) {
207: // TODO Auto-generated method stub
208: return null;
209: }
210:
211: /**
212: * Get the MBean Info
213: * @return the MBeanInfo
214: *
215: * @see javax.management.DynamicMBean#getMBeanInfo()
216: */
217: public MBeanInfo getMBeanInfo() {
218: MBeanInfo beanInfo = new MBeanInfo(
219: "ESBNotificationBroadcaster",
220: "ESBNotificationBroadcaster",
221: new MBeanAttributeInfo[] {},
222: new MBeanConstructorInfo[] {},
223: new MBeanOperationInfo[] {},
224: new MBeanNotificationInfo[] { new MBeanNotificationInfo(
225: NOTIFICATION_TYPES, NOTIFICATION_CLASS_NAME,
226: NOTIFICATION_DESCRIPTION) });
227: return beanInfo;
228: }
229:
230: /**
231: * Invoke an operation
232: * @param operationName
233: * @param object parameters
234: * @param param signatures
235: * @return result of the invoke
236: *
237: * @see javax.management.DynamicMBean#invoke(java.lang.String, java.lang.Object[], java.lang.String[])
238: */
239: public Object invoke(String actionName, Object[] params,
240: String[] signature) throws MBeanException,
241: ReflectionException {
242: // TODO Auto-generated method stub
243: return null;
244: }
245:
246: /**
247: * Set an attribute value
248: * @param the attribute to set
249: *
250: * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
251: */
252: public void setAttribute(Attribute attribute)
253: throws AttributeNotFoundException,
254: InvalidAttributeValueException, MBeanException,
255: ReflectionException {
256: if (attribute.getName().equals("name")) {
257: setName((String) attribute.getValue());
258: } else if (attribute.getName().equals("description")) {
259: setDescription((String) attribute.getValue());
260: }
261: }
262:
263: /**
264: * Set a list of attribute values
265: * @param the list of attributes to set
266: * @return the attribute list
267: *
268: * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList)
269: */
270: public AttributeList setAttributes(AttributeList attributes) {
271: // TODO Auto-generated method stub
272: return null;
273: }
274:
275: /**
276: * @return the name
277: */
278: public String getName() {
279: return this .name;
280: }
281:
282: /**
283: * @param name the name to set
284: */
285: public void setName(String name) {
286: this .name = name;
287: }
288:
289: /**
290: * @return the description
291: */
292: public String getDescription() {
293: return this .description;
294: }
295:
296: /**
297: * @param description the description to set
298: */
299: public void setDescription(String description) {
300: this .description = description;
301: }
302:
303: /**
304: * Add a notification listener
305: * @param event notification listener object
306: *
307: * @see com.sun.esb.management.api.notification.NotificationService#addNotificationEventListener(com.sun.esb.management.api.notification.EventNotificationListener)
308: */
309: public void addNotificationEventListener(
310: EventNotificationListener listener)
311: throws ManagementRemoteException {
312: }
313:
314: /**
315: * Remove a notification listener
316: * @param event notification listener object
317: *
318: * @see com.sun.esb.management.api.notification.NotificationService#removeNotificationEventListener(com.sun.esb.management.api.notification.EventNotificationListener)
319: */
320: public void removeNotificationEventListener(
321: EventNotificationListener listener)
322: throws ManagementRemoteException {
323: }
324:
325: /**
326: * Get the Framework Notification MBean
327: * @return
328: */
329: protected ObjectName getFrameworkDomainNotificationMBean() {
330: return this .environmentContext.getMBeanNames()
331: .getSystemServiceMBeanName(
332: MBeanNames.ServiceName.Framework,
333: MBeanNames.ServiceType.Notification, "domain");
334: }
335:
336: /**
337: * Register for notifications from the framework MBean
338: */
339: protected void registerForLocalNotifications() {
340: ObjectName mbeanName = getFrameworkDomainNotificationMBean();
341:
342: try {
343: Object[] params = { this , null, null };
344: String[] signature = {
345: "javax.management.NotificationListener",
346: "javax.management.NotificationFilter",
347: "java.lang.Object" };
348: this .environmentContext.getMBeanServer().invoke(mbeanName,
349: "addNotificationListener", params, signature);
350: } catch (InstanceNotFoundException e) {
351: // Could not register for local notifications
352: } catch (MBeanException e) {
353: // Could not register for local notifications
354: } catch (ReflectionException e) {
355: // Could not register for local notifications
356: }
357: }
358: }
|