KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > selfmanagement > event > ManagementRulesMBeanHelper


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.enterprise.admin.selfmanagement.event;
26
27 //jdk imports
28
import java.util.Enumeration JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Set JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.logging.LogManager JavaDoc;
33 import java.util.logging.Level JavaDoc;
34 import java.util.logging.Logger JavaDoc;
35 import java.util.Hashtable JavaDoc;
36
37 //JMX imports
38
import javax.management.ObjectName JavaDoc;
39 import javax.management.MBeanServer JavaDoc;
40 import javax.management.MBeanInfo JavaDoc;
41 import javax.management.MBeanAttributeInfo JavaDoc;
42 import javax.management.MBeanNotificationInfo JavaDoc;
43 import javax.management.MalformedObjectNameException JavaDoc;
44 import javax.management.InstanceNotFoundException JavaDoc;
45 import javax.management.IntrospectionException JavaDoc;
46 import javax.management.ReflectionException JavaDoc;
47
48
49 //core imports
50
import com.sun.logging.LogDomains;
51 import com.sun.enterprise.config.ConfigException;
52 import com.sun.enterprise.config.ConfigContext;
53 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
54 import com.sun.enterprise.config.serverbeans.Mbean;
55 import com.sun.enterprise.config.serverbeans.Server;
56 import com.sun.enterprise.config.serverbeans.ServerHelper;
57 import com.sun.enterprise.admin.common.MBeanServerFactory;
58 import com.sun.enterprise.admin.server.core.AdminService;
59 import com.sun.enterprise.admin.selfmanagement.event.ManagementRuleConstants;
60 import com.sun.enterprise.admin.server.core.CustomMBeanRegistration;
61 import com.sun.enterprise.management.selfmanagement.RuleManager;
62 import static com.sun.enterprise.admin.selfmanagement.event.ManagementRuleConstants.*;
63
64 import com.sun.enterprise.server.ApplicationServer;
65 import com.sun.enterprise.admin.common.ObjectNames;
66 import com.sun.enterprise.config.serverbeans.Domain;
67 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
68 import com.sun.enterprise.config.serverbeans.ApplicationRef;
69 import com.sun.enterprise.config.serverbeans.Applications;
70 import com.sun.enterprise.config.serverbeans.Clusters;
71 import com.sun.enterprise.config.serverbeans.Cluster;
72
73 public class ManagementRulesMBeanHelper {
74     
75     private static Logger JavaDoc _logger =
76                LogDomains.getLogger(LogDomains.SELF_MANAGEMENT_LOGGER);
77     
78     private static String JavaDoc instanceName = (ApplicationServer.getServerContext()).getInstanceName();
79     private static ConfigContext configCtx = (ApplicationServer.getServerContext()).getConfigContext();
80
81     private static ConfigContext getConfigContext() {
82         return AdminService.getAdminService().getAdminContext().getAdminConfigContext();
83     }
84     
85     /**
86      * Gets the registred actions in the domain.
87      * @param enabled if true, gets only enabled actions, otherwise all actions.
88      *
89      * @returns registered actions
90      * @throws ConfigException
91      */

92     public static List JavaDoc<String JavaDoc> getAllActionMBeans(boolean enabled) throws ConfigException {
93         List JavaDoc<String JavaDoc> actionMBeanList = new ArrayList JavaDoc<String JavaDoc>();
94         List JavaDoc<Mbean> mbeanList = ServerBeansFactory.getAllMBeanDefinitions(getConfigContext());
95         for (Mbean mbean : mbeanList) {
96             if (enabled && !mbean.isEnabled())
97                 continue;
98             String JavaDoc implClassName = mbean.getImplClassName();
99             if (implementsInterface(implClassName, "javax.management.NotificationListener"))
100                 actionMBeanList.add(mbean.getName());
101         }
102         return actionMBeanList;
103     }
104     
105     private static boolean implementsInterface(String JavaDoc implClassName, String JavaDoc interfaceName) {
106         Class JavaDoc ifList[] = null;
107         Class JavaDoc class1 = null;
108         try {
109             ClassLoader JavaDoc mbeanClLoader = getMBeanClassLoader();
110             if (mbeanClLoader != null)
111                 class1 = Class.forName(implClassName,false,mbeanClLoader);
112             else
113                 class1 = Class.forName(implClassName);
114             while (class1 != null) {
115                 ifList = class1.getInterfaces();
116                 if(ifList != null) {
117                     for (int i=0; i<ifList.length; i++) {
118                         String JavaDoc canonicalName = ifList[i].getCanonicalName().trim();
119                         if( canonicalName.equals(interfaceName) ) {
120                             return true;
121                         }
122                     }
123                     class1 = class1.getSuperclass();
124                 }
125             }
126         } catch (Exception JavaDoc ex) {
127             _logger.log(Level.FINE, " An unexpcted exception occurred " , ex);
128         }
129         return false;
130     }
131
132     private static ClassLoader JavaDoc getMBeanClassLoader() {
133         try {
134             return (ClassLoader JavaDoc) Class.forName(
135             "com.sun.enterprise.admin.mbeans.custom.loading.MBeanClassLoader").
136             newInstance();
137         } catch (Exception JavaDoc ex) {
138             _logger.log(Level.FINE, " An unexpcted exception occurred " , ex);
139         }
140        return null;
141     
142     }
143     
144     /**
145      * Gets the list of event types.
146      * @param isEE if true, gets events for EE, otherwise gets events for PE.
147      *
148      * @returns list of event types
149      */

150     public static List JavaDoc<String JavaDoc> getEventTypes(boolean isEE) {
151         List JavaDoc<String JavaDoc> eventTypeList = new ArrayList JavaDoc<String JavaDoc>();
152         eventTypeList.add(EVENT_LIFECYCLE);
153         eventTypeList.add(EVENT_LOG);
154         eventTypeList.add(EVENT_TIMER);
155         eventTypeList.add(EVENT_TRACE);
156         eventTypeList.add(EVENT_MONITOR);
157         eventTypeList.add(EVENT_NOTIFICATION);
158         if (isEE) {
159             eventTypeList.add(EVENT_CLUSTER);
160         }
161         return eventTypeList;
162     }
163     
164     /**
165      * Gets the properties for a given event type.
166      * @param eventType for a given event type, gets the associated property names.
167      *
168      * @returns list of property names associated with an event type
169      */

170     public static List JavaDoc<String JavaDoc> getEventProperties(String JavaDoc eventType) {
171         if (eventType == null || "".equals(eventType))
172             return new ArrayList JavaDoc<String JavaDoc>(0);
173         List JavaDoc<String JavaDoc> valueList = null;
174         if (eventType.equals(EVENT_LIFECYCLE)) {
175             valueList = new ArrayList JavaDoc<String JavaDoc>(1);
176             valueList.add(PROPERTY_LIFECYCLE_NAME);
177             return valueList;
178         }
179         if (eventType.equals(EVENT_MONITOR)) {
180             valueList = new ArrayList JavaDoc<String JavaDoc>();
181             valueList.add(PROPERTY_MONITOR_OBSERVED_OBJ);
182             valueList.add(PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME);
183             valueList.add(PROPERTY_MONITOR_OBSERVED_ATTRIBUTE);
184             valueList.add(PROPERTY_MONITOR_GRANULARITY_PERIOD);
185             valueList.add(PROPERTY_MONITOR_NUMBERTYPE);
186             valueList.add(PROPERTY_MONITOR_DIFFERENCEMODE);
187             valueList.add(PROPERTY_MONITOR_INIT_THRESHOLD);
188             valueList.add(PROPERTY_MONITOR_OFFSET);
189             valueList.add(PROPERTY_MONITOR_MODULUS);
190             valueList.add(PROPERTY_MONITOR_LOW_THRESHOLD);
191             valueList.add(PROPERTY_MONITOR_HIGH_THRESHOLD);
192             valueList.add(PROPERTY_MONITOR_STRING_TO_COMPARE);
193             valueList.add(PROPERTY_MONITOR_STRING_NOTIFY);
194             return valueList;
195         }
196         if (eventType.equals(EVENT_TRACE)) {
197             valueList = new ArrayList JavaDoc<String JavaDoc>(1);
198             valueList.add(PROPERTY_TRACE_NAME);
199             return valueList;
200         }
201         if (eventType.equals(EVENT_LOG)) {
202             valueList = new ArrayList JavaDoc<String JavaDoc>(2);
203             valueList.add(PROPERTY_LOG_LOGGERNAME);
204             valueList.add(PROPERTY_LOG_LEVEL);
205             return valueList;
206         }
207         if (eventType.equals(EVENT_TIMER)) {
208             valueList = new ArrayList JavaDoc<String JavaDoc>(5);
209             valueList.add(PROPERTY_TIMER_PATTERN);
210             valueList.add(PROPERTY_TIMER_DATESTRING);
211             valueList.add(PROPERTY_TIMER_PERIOD);
212             valueList.add(PROPERTY_TIMER_NUMBER_OF_OCCURRENCES);
213             valueList.add(PROPERTY_TIMER_MESSAGE);
214             return valueList;
215         }
216         if (eventType.equals(EVENT_NOTIFICATION)) {
217             valueList = new ArrayList JavaDoc<String JavaDoc>(1);
218             valueList.add(PROPERTY_NOTIFICATION_SOURCEMBEAN);
219             valueList.add(PROPERTY_NOTIFICATION_SOURCE_OBJ_NAME);
220             return valueList;
221         }
222         if (eventType.equals(EVENT_CLUSTER)) {
223             valueList = new ArrayList JavaDoc<String JavaDoc>(2);
224             valueList.add(PROPERTY_CLUSTER_NAME);
225             valueList.add(PROPERTY_CLUSTER_SERVERNAME);
226             return valueList;
227         }
228         return new ArrayList JavaDoc<String JavaDoc>(0);
229     }
230     
231     
232     public static List JavaDoc<String JavaDoc> getEventPropertyValues(String JavaDoc eventType, String JavaDoc propertyName)
233     throws ConfigException {
234         if (eventType == null || "".equals(eventType))
235             return new ArrayList JavaDoc<String JavaDoc>(0);
236         List JavaDoc<String JavaDoc> valueList = null;
237         if (eventType.equals(EVENT_LIFECYCLE)) {
238             if (PROPERTY_LIFECYCLE_NAME.equals(propertyName)) {
239                 valueList = new ArrayList JavaDoc<String JavaDoc>(3);
240                 valueList.add("ready");
241                 valueList.add("shutdown");
242                 valueList.add("termination");
243                 return valueList;
244             }
245         }
246         if (eventType.equals(EVENT_MONITOR)) {
247             if (PROPERTY_MONITOR_OBSERVED_OBJ.equals(propertyName)) {
248                 return new ArrayList JavaDoc<String JavaDoc>(0);
249             }
250             if (PROPERTY_MONITOR_OBSERVED_OBJ_MBEAN_NAME.equals(propertyName)) {
251                 return new ArrayList JavaDoc<String JavaDoc>(0);
252             }
253             if (PROPERTY_MONITOR_OBSERVED_ATTRIBUTE.equals(propertyName)) {
254                 return new ArrayList JavaDoc<String JavaDoc>(0);
255             }
256             if (PROPERTY_MONITOR_GRANULARITY_PERIOD.equals(propertyName)) {
257                 return new ArrayList JavaDoc<String JavaDoc>(0);
258             }
259             if (PROPERTY_MONITOR_TYPE.equals(propertyName)) {
260                 valueList = new ArrayList JavaDoc<String JavaDoc>(3);
261                 valueList.add(PROPERTY_MONITOR_COUNTER);
262                 valueList.add(PROPERTY_MONITOR_GAUGE);
263                 valueList.add(PROPERTY_MONITOR_STRING);
264                 return valueList;
265             }
266             if (PROPERTY_MONITOR_NUMBERTYPE.equals(propertyName)) {
267                 valueList = new ArrayList JavaDoc<String JavaDoc>(6);
268                 valueList.add("long");
269                 valueList.add("int");
270                 valueList.add("short");
271                 valueList.add("double");
272                 valueList.add("float");
273                 valueList.add("byte");
274                 return valueList;
275             }
276             if (PROPERTY_MONITOR_DIFFERENCEMODE.equals(propertyName)) {
277                 valueList = new ArrayList JavaDoc<String JavaDoc>(2);
278                 valueList.add("true");
279                 valueList.add("false");
280                 return valueList;
281             }
282             if (PROPERTY_MONITOR_INIT_THRESHOLD.equals(propertyName)) {
283                 return new ArrayList JavaDoc<String JavaDoc>(0);
284             }
285             if (PROPERTY_MONITOR_OFFSET.equals(propertyName)) {
286                 return new ArrayList JavaDoc<String JavaDoc>(0);
287             }
288             if (PROPERTY_MONITOR_MODULUS.equals(propertyName)) {
289                 return new ArrayList JavaDoc<String JavaDoc>(0);
290             }
291             if (PROPERTY_MONITOR_LOW_THRESHOLD.equals(propertyName)) {
292                 return new ArrayList JavaDoc<String JavaDoc>(0);
293             }
294             if (PROPERTY_MONITOR_HIGH_THRESHOLD.equals(propertyName)) {
295                 return new ArrayList JavaDoc<String JavaDoc>(0);
296             }
297             if (PROPERTY_MONITOR_STRING_TO_COMPARE.equals(propertyName)) {
298                 return new ArrayList JavaDoc<String JavaDoc>(0);
299             }
300             if (PROPERTY_MONITOR_STRING_NOTIFY.equals(propertyName)) {
301                 valueList = new ArrayList JavaDoc<String JavaDoc>(2);
302                 valueList.add(PROPERTY_MONITOR_STRING_NOTIFY_MATCH);
303                 valueList.add(PROPERTY_MONITOR_STRING_NOTIFY_DIFFER);
304                 return valueList;
305             }
306         }
307         if (EVENT_TRACE.equals(eventType)) {
308             if (PROPERTY_TRACE_NAME.equals(propertyName)) {
309                 valueList = new ArrayList JavaDoc<String JavaDoc>(6);
310                 valueList.add("web_component_method_entry");
311                 valueList.add("web_component_method_exit");
312                 valueList.add("request_start");
313                 valueList.add("request_end");
314                 valueList.add("ejb_component_method_entry");
315                 valueList.add("ejb_component_method_exit");
316                 return valueList;
317             }
318         }
319         if (EVENT_LOG.equals(eventType)) {
320             if (PROPERTY_LOG_LOGGERNAME.equals(propertyName)) {
321                 valueList = new ArrayList JavaDoc<String JavaDoc>();
322                 Enumeration JavaDoc<String JavaDoc> loggerNames = LogManager.getLogManager().getLoggerNames();
323                 while (loggerNames.hasMoreElements()) {
324                     valueList.add(loggerNames.nextElement());
325                 }
326                 return valueList;
327             }
328             if (PROPERTY_LOG_LEVEL.equals(propertyName)) {
329                 valueList = new ArrayList JavaDoc<String JavaDoc>();
330                 valueList.add(Level.ALL.getName());
331                 valueList.add(Level.CONFIG.getName());
332                 valueList.add(Level.FINE.getName());
333                 valueList.add(Level.FINER.getName());
334                 valueList.add(Level.FINEST.getName());
335                 valueList.add(Level.INFO.getName());
336                 valueList.add(Level.SEVERE.getName());
337                 valueList.add(Level.WARNING.getName());
338                 return valueList;
339             }
340         }
341         if (EVENT_TIMER.equals(eventType)) {
342             if (PROPERTY_TIMER_PATTERN.equals(propertyName) ||
343                     PROPERTY_TIMER_DATESTRING.equals(propertyName) ||
344                     PROPERTY_TIMER_PERIOD.equals(propertyName) ||
345                     PROPERTY_TIMER_NUMBER_OF_OCCURRENCES.equals(propertyName) ||
346                     PROPERTY_TIMER_MESSAGE.equals(propertyName) ) {
347                 return new ArrayList JavaDoc<String JavaDoc>(0);
348             }
349         }
350         if (EVENT_NOTIFICATION.equals(eventType)) {
351             if (PROPERTY_NOTIFICATION_SOURCEMBEAN.equals(propertyName)) {
352                 //return getAllNotificationEmitterMbeans(false);
353
return new ArrayList JavaDoc<String JavaDoc>(0);
354             }
355             if (PROPERTY_NOTIFICATION_SOURCE_OBJ_NAME.equals(propertyName)) {
356                 return new ArrayList JavaDoc<String JavaDoc>(0);
357             }
358         }
359         if (EVENT_CLUSTER.equals(eventType)) {
360             if (PROPERTY_CLUSTER_NAME.equals(propertyName)) {
361                 valueList = new ArrayList JavaDoc<String JavaDoc>(3);
362                 valueList.add("start");
363                 valueList.add("stop");
364                 valueList.add("fail");
365                 return valueList;
366             }
367             if (PROPERTY_CLUSTER_SERVERNAME.equals(propertyName)) {
368                 valueList = new ArrayList JavaDoc<String JavaDoc>();
369                 Server JavaDoc servers[] = ServerHelper.getServersInDomain(getConfigContext());
370                 for (Server JavaDoc server : servers) {
371                     valueList.add(server.getName());
372                 }
373                 return valueList;
374             }
375         }
376         return new ArrayList JavaDoc<String JavaDoc>(0);
377     }
378     
379     public static List JavaDoc<String JavaDoc> getAllNotificationEmitterMbeans(boolean enabled) throws ConfigException {
380         List JavaDoc<String JavaDoc> customMBeanList = new ArrayList JavaDoc<String JavaDoc>();
381         List JavaDoc<Mbean> mbeanList = ServerBeansFactory.getAllMBeanDefinitions(getConfigContext());
382         for (Mbean mbean : mbeanList) {
383             if (enabled && !mbean.isEnabled())
384                 continue;
385             String JavaDoc implClassName = mbean.getImplClassName();
386             if (implementsInterface(implClassName, "javax.management.NotificationEmitter"))
387                 customMBeanList.add(mbean.getName());
388         }
389         return customMBeanList;
390     }
391     
392     
393     /**
394      * Gets the registred MBeans registered in the server's MBean server.
395      * @param filter ObjectName filter for quering MBean server.
396      *
397      * @returns list of registered mbeans
398      * @throws MalformedObjectNameException
399      */

400     public static Set JavaDoc<ObjectName JavaDoc> getRegisteredMBeans(String JavaDoc filter) throws MalformedObjectNameException JavaDoc {
401         ObjectName JavaDoc userFilteredObjectName = null;
402         MBeanServer JavaDoc mbeanServer = MBeanServerFactory.getMBeanServer();
403         if (filter != null) {
404             userFilteredObjectName = new ObjectName JavaDoc(filter);
405             return mbeanServer.queryNames(userFilteredObjectName, null);
406         }
407         String JavaDoc monitoringObjectNameFilter = "com.sun.appserv:category=monitor,*";
408         String JavaDoc jsr77ObjectNameFilter = "com.sun.appserv:category=runtime,*";
409         ObjectName JavaDoc monitoringFilteredObjectName = null;
410         ObjectName JavaDoc jsr77FilteredObjectName = null;
411         try {
412             monitoringFilteredObjectName = new ObjectName JavaDoc(monitoringObjectNameFilter);
413             jsr77FilteredObjectName = new ObjectName JavaDoc(jsr77ObjectNameFilter);
414         } catch (Exception JavaDoc ex) {
415             _logger.log(Level.FINE, " An unexpcted exception occurred " , ex);
416         }
417         Set JavaDoc<ObjectName JavaDoc> setObjNames = mbeanServer.queryNames(monitoringFilteredObjectName, null);
418         setObjNames.addAll(mbeanServer.queryNames(jsr77FilteredObjectName,null));
419         return setObjNames;
420     }
421     
422     /**
423      * Gets the attributes for a given ObjectName.
424      * @param objName ObjectName for which the attributes are required.
425      *
426      * @returns list of attributes
427      * @throws InstanceNotFoundException,IntrospectionException, ReflectionException
428      */

429     public static List JavaDoc<String JavaDoc> getAttributes(ObjectName JavaDoc objName) throws InstanceNotFoundException JavaDoc, IntrospectionException JavaDoc,
430             ReflectionException JavaDoc {
431         if (objName == null)
432             return new ArrayList JavaDoc<String JavaDoc>(0);
433         MBeanInfo JavaDoc mbInfo = MBeanServerFactory.getMBeanServer().getMBeanInfo(objName);
434         MBeanAttributeInfo JavaDoc attrInfoArr[] = mbInfo.getAttributes();
435         List JavaDoc<String JavaDoc> attributes = new ArrayList JavaDoc<String JavaDoc>();
436         for (MBeanAttributeInfo JavaDoc attrInfo : attrInfoArr) {
437             attributes.add(attrInfo.getName());
438         }
439         return attributes;
440     }
441     
442     public static List JavaDoc<String JavaDoc> getMBeanAttributes(String JavaDoc objectNameStr) throws MalformedObjectNameException JavaDoc,
443             InstanceNotFoundException JavaDoc, IntrospectionException JavaDoc,
444             ReflectionException JavaDoc {
445         ObjectName JavaDoc objName = new ObjectName JavaDoc(objectNameStr);
446         return getAttributes(objName);
447     }
448     
449     public static List JavaDoc<String JavaDoc> getNotificationTypes(ObjectName JavaDoc objName) throws InstanceNotFoundException JavaDoc, IntrospectionException JavaDoc,
450             ReflectionException JavaDoc {
451         if (objName == null)
452             return new ArrayList JavaDoc<String JavaDoc>(0);
453         MBeanInfo JavaDoc mbInfo = MBeanServerFactory.getMBeanServer().getMBeanInfo(objName);
454         MBeanNotificationInfo JavaDoc notifInfoArr[] = mbInfo.getNotifications();
455         List JavaDoc<String JavaDoc> notifications = new ArrayList JavaDoc<String JavaDoc>();
456         for (MBeanNotificationInfo JavaDoc notifInfo : notifInfoArr) {
457             String JavaDoc notifTypes[] = notifInfo.getNotifTypes();
458             for (String JavaDoc notifType : notifTypes)
459                 notifications.add(notifType);
460         }
461         return notifications;
462     }
463     
464     public static List JavaDoc<String JavaDoc> getNotificationTypes(String JavaDoc objectNameStr) throws MalformedObjectNameException JavaDoc,
465             InstanceNotFoundException JavaDoc, IntrospectionException JavaDoc,
466             ReflectionException JavaDoc {
467         ObjectName JavaDoc objName = new ObjectName JavaDoc(objectNameStr);
468         return getNotificationTypes(objName);
469     }
470     
471     
472     
473     public static List JavaDoc<String JavaDoc> getAttributes(String JavaDoc dottedName) { return null; }
474     
475     public static List JavaDoc<String JavaDoc> getDottedNames(String JavaDoc dottedName) { return null; }
476     
477     public static String JavaDoc getObjName(String JavaDoc mBeanName) {
478         String JavaDoc objName = null;
479         String JavaDoc cascadedObjName = null;
480         if (mBeanName != null) {
481             try {
482                 Domain domain = ServerBeansFactory.getDomainBean(configCtx);
483                 ApplicationRef appRef = verifyMBean(mBeanName, domain);
484                 if (appRef != null) {
485                     Applications apps = domain.getApplications();
486                     Mbean definedMBean = apps.getMbeanByName(mBeanName);
487                     if(definedMBean != null) {
488                         objName = definedMBean.getObjectName();
489                         cascadedObjName = getCascadingAwareObjectName(new ObjectName JavaDoc(objName)).toString();
490                     }
491                 }
492             } catch(ConfigException ex) {
493                 _logger.log(Level.INFO, "An unexpected exception occured.", ex);
494             } catch (Exception JavaDoc ex) {
495                 _logger.log(Level.INFO, "An unexpected exception occured.", ex);
496             }
497         }
498         //objName = ObjectNames.getApplicationObjectName(instanceName,mBeanName);
499
/*if (!(objName.endsWith(",server=" + instanceName))) {
500             objName = objName + ",server=" + instanceName;
501         }*/

502         return cascadedObjName;
503     }
504    
505     public static ObjectName JavaDoc getCascadingAwareObjectName(final ObjectName JavaDoc configON) throws RuntimeException JavaDoc {
506         try {
507             final String JavaDoc serverNameKey = "server";
508             //final String serverNameVal = System.getProperty("com.sun.aas.instanceName");
509
final Hashtable JavaDoc properties = configON.getKeyPropertyList();
510             properties.put(serverNameKey, instanceName);
511             final ObjectName JavaDoc ron = new ObjectName JavaDoc(configON.getDomain(), properties);
512             return ( ron );
513         } catch(final Exception JavaDoc e) {
514             throw new RuntimeException JavaDoc(e);
515         }
516     }
517
518     /*public static String getRealObjectName(final ObjectName configON, String key)
519         throws RuntimeException {
520         try {
521             final String serverNameVal = System.getProperty("com.sun.aas.instanceName");
522             if(!(configON.getKeyProperty(key).equals(serverNameVal))) {
523                 //If the object name doesn't already have the specified key value
524                 final Hashtable properties = configON.getKeyPropertyList();
525                 properties.put(key, serverNameVal);
526                 final ObjectName ron = new ObjectName(configON.getDomain(), properties);
527                 return ( ron.toString() );
528             } else {
529                 return ( configON.toString() );
530             }
531         } catch(final Exception e) {
532             throw new RuntimeException(e);
533         }
534     }*/

535  
536     private static ApplicationRef verifyMBean(String JavaDoc mBeanName, Domain domain) {
537         ApplicationRef appRef = null;
538         
539         try {
540             Server JavaDoc instanceBean = ServerBeansFactory.getServerBean(configCtx);
541             appRef = instanceBean.getApplicationRefByRef(mBeanName);
542                                                                                                                                                
543             if (appRef == null) {
544                 //check at cluster level, if this instance is part of cluster
545
Clusters clusters = domain.getClusters();
546                 Cluster[] cluster = clusters.getCluster();
547                 for (Cluster val : cluster) {
548                     if ((val.getServerRefByRef(instanceName)) != null) {
549                         appRef = val.getApplicationRefByRef(mBeanName);
550                         break;
551                     }
552                 }
553             }
554                                                                                                                                                
555             //should have obtained the app reference, if all well
556
if (appRef != null) {
557                 //check there exists a definition
558
Applications apps = domain.getApplications();
559                 Mbean definedMBean = apps.getMbeanByName(mBeanName);
560                 if (definedMBean == null ) {
561                     appRef = null;
562                 }
563             }
564         } catch (ConfigException ex) {
565             _logger.log(Level.INFO, "smgt.config_error", ex);
566         }
567                                                                                                                                                
568         return appRef;
569     }
570
571 }
572
573
Popular Tags