KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > mbeans > ManagementRulesMBean


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  * $Id: ManagementRulesMBean.java,v 1.4 2005/12/25 03:42:24 tcfujii Exp $
26  */

27
28 package com.sun.enterprise.admin.mbeans;
29
30 //jdk imports
31
import java.util.Properties JavaDoc;
32 import java.util.Enumeration JavaDoc;
33 import java.util.Set JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.ArrayList 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 //config imports
50
import com.sun.enterprise.admin.config.BaseConfigMBean;
51 import com.sun.enterprise.admin.config.ConfigMBeanHelper;
52
53 //core imports
54
import com.sun.enterprise.config.serverbeans.ElementProperty;
55 import com.sun.enterprise.config.serverbeans.ManagementRules;
56 import com.sun.enterprise.config.serverbeans.ManagementRule;
57 import com.sun.enterprise.config.serverbeans.Event;
58 import com.sun.enterprise.config.serverbeans.Action;
59 import com.sun.enterprise.config.ConfigException;
60 import com.sun.enterprise.config.ConfigContext;
61 import com.sun.enterprise.admin.selfmanagement.event.ManagementRulesMBeanHelper;
62
63
64 public class ManagementRulesMBean extends BaseConfigMBean
65 {
66     
67     /**
68      * Create new self management rule with contained event and action(optional)
69      * @param ruleName name of the management rule. Required.
70      * @param bRuleEnabled enabled/disabled rule state.
71      * @param ruleDescription textual decription of the rule.
72      * @param eventType one of the predefined event types. Required.
73      * @param eventLevel events severety level (default "INFO")
74      * @param eventDescription textual decription of the evant
75      * @param eventRecordEvent whether the event is to be logged or not ("true")
76      * @param eventProperties event's properties
77      * @param actionMbeanName actionMbeanNames associated with rule
78      *
79      * @returns ObjectName of created management-rule
80      * @throws Exception
81      */

82 public ObjectName JavaDoc createManagementRule(
83             String JavaDoc ruleName, //required
84
Boolean JavaDoc bRuleEnabled,
85             String JavaDoc ruleDescription,
86             String JavaDoc eventType, //required
87
String JavaDoc eventLevel,
88             Boolean JavaDoc eventRecordEvent,
89             String JavaDoc eventDescription,
90             Properties JavaDoc eventProperties,
91             String JavaDoc actionMbeanName
92         ) throws Exception JavaDoc
93 {
94     ManagementRule newRule = new ManagementRule();
95     //Rule attrs
96
newRule.setName(ruleName);
97     if(ruleDescription!=null)
98        newRule.setDescription(ruleDescription);
99     if(bRuleEnabled!=null)
100        newRule.setEnabled(bRuleEnabled.booleanValue());
101     //Event
102
Event event = new Event();
103     event.setType(eventType);
104     if(eventRecordEvent!=null)
105        event.setRecordEvent(eventRecordEvent.booleanValue());
106     if(eventLevel!=null)
107        event.setLevel(eventLevel);
108     if(eventDescription!=null)
109        event.setDescription(eventDescription);
110     //Event properties
111
if (null != eventProperties)
112         {
113             Enumeration JavaDoc keys = eventProperties.keys();
114             while (keys.hasMoreElements())
115             {
116                 final String JavaDoc key = (String JavaDoc)keys.nextElement();
117                 ElementProperty prop = new ElementProperty();
118                 prop.setName(key);
119                 prop.setValue((String JavaDoc)eventProperties.get(key));
120                 event.addElementProperty(prop);
121             }
122         }
123     newRule.setEvent(event);
124     
125     //Action
126
if(actionMbeanName!=null)
127     {
128         Action action = new Action();
129         action.setActionMbeanName(actionMbeanName);
130         newRule.setAction(action);
131         
132     }
133     // insert new rule to config tree
134
ManagementRules rules = (ManagementRules)getBaseConfigBean();
135     rules.addManagementRule(newRule);
136     return ConfigMBeanHelper.getChildObjectName(super.m_registry, super.info, newRule);
137 }
138
139     /**
140      * Add Action element to maagement rule
141      * @param ruleName name of the management rule
142      * @param actionMbeanNames actionMbeanNames associated with rule
143      *
144      * @throws ConfigException
145      */

146 public void addActionToManagementRule(
147             String JavaDoc ruleName, //required
148
String JavaDoc actionMbeanName) throws ConfigException
149 {
150     ManagementRules rules = (ManagementRules)getBaseConfigBean();
151     ManagementRule rule = rules.getManagementRuleByName(ruleName);
152     Action action = new Action();
153     action.setActionMbeanName(actionMbeanName);
154     rule.setAction(action);
155 }
156
157
158     /**
159      * Gets the registred actions in the domain.
160      * @param enabled if true, gets only enabled actions, otherwise all actions.
161      *
162      * @returns registered actions
163      * @throws ConfigException
164      */

165 public List JavaDoc<String JavaDoc> getAllActionMBeans(boolean enabled) throws ConfigException {
166     return ManagementRulesMBeanHelper.getAllActionMBeans(enabled);
167 }
168
169     /**
170      * Gets the list of event types.
171      * @param isEE if true, gets events for EE, otherwise gets events for PE.
172      *
173      * @returns list of event types
174      */

175 public List JavaDoc<String JavaDoc> getEventTypes(boolean isEE) {
176     return ManagementRulesMBeanHelper.getEventTypes(isEE);
177 }
178
179     /**
180      * Gets the associated propertied for a given event.
181      * @param eventType for a given event type, gets the associated property names.
182      *
183      * @returns list of property names associated with an event type
184      */

185 public List JavaDoc<String JavaDoc> getEventProperties(String JavaDoc eventType) {
186     return ManagementRulesMBeanHelper.getEventProperties(eventType);
187 }
188
189
190     /**
191      * Gets the possible values for a given event type and property name.
192      * @param eventType event type to which the propertyName belongs.
193      * @param propertyName name of the property
194      *
195      * @returns list of property values associated with a property name.
196      */

197 public List JavaDoc<String JavaDoc> getEventPropertyValues(String JavaDoc eventType, String JavaDoc propertyName)
198                     throws ConfigException {
199     return ManagementRulesMBeanHelper.getEventPropertyValues(eventType, propertyName);
200 }
201
202     /**
203      * Gets the registred custom mbeans which can be notification emitters.
204      * @param enabled if true, gets only enabled emitters, otherwise all emitters.
205      *
206      * @returns custom mbeans which are notification emitters
207      * @throws ConfigException
208      */

209 List JavaDoc<String JavaDoc> getAllNotificationEmitterMbeans(boolean enabled) throws ConfigException {
210     return ManagementRulesMBeanHelper.getAllNotificationEmitterMbeans(enabled);
211 }
212
213
214     /**
215      * Gets the registred MBeans registered in the server's MBean server.
216      * @param filter ObjectName filter for quering MBean server.
217      *
218      * @returns list of registered mbeans
219      * @throws MalformedObjectNameException
220      */

221 public Set JavaDoc<ObjectName JavaDoc> getRegisteredMBeans(String JavaDoc filter) throws
222                                   MalformedObjectNameException JavaDoc {
223     return ManagementRulesMBeanHelper.getRegisteredMBeans(filter);
224 }
225
226     /**
227      * Gets the attributes for a given ObjectName.
228      * @param objName ObjectName for which the attributes are required.
229      *
230      * @returns list of attributes
231      * @throws InstanceNotFoundException,IntrospectionException, ReflectionException
232      */

233 public List JavaDoc<String JavaDoc> getAttributes(ObjectName JavaDoc objName) throws
234                               InstanceNotFoundException JavaDoc,
235                               IntrospectionException JavaDoc,
236                               ReflectionException JavaDoc {
237     return ManagementRulesMBeanHelper.getAttributes(objName);
238 }
239
240     /**
241      * Gets the attributes for a given ObjectName in a string form.
242      * @param objNameStr ObjectName for which the attributes are required.
243      *
244      * @returns list of attributes
245      * @throws InstanceNotFoundException,IntrospectionException, ReflectionException
246      * @throws MalformedObjectNameException
247      */

248 public List JavaDoc<String JavaDoc> getMBeanAttributes(String JavaDoc objectNameStr)
249                          throws MalformedObjectNameException JavaDoc,
250                          InstanceNotFoundException JavaDoc, IntrospectionException JavaDoc,
251                          ReflectionException JavaDoc {
252     return ManagementRulesMBeanHelper.getMBeanAttributes(objectNameStr);
253 }
254
255     /**
256      * Gets the Notifications for a given ObjectName.
257      * @param objName ObjectName for which the Notifications are required.
258      *
259      * @returns list of Notifications
260      * @throws InstanceNotFoundException,IntrospectionException, ReflectionException
261      */

262 public List JavaDoc<String JavaDoc> getNotificationTypes(ObjectName JavaDoc objName) throws
263                                           InstanceNotFoundException JavaDoc,
264                                           IntrospectionException JavaDoc,
265                                           ReflectionException JavaDoc {
266     return ManagementRulesMBeanHelper.getNotificationTypes(objName);
267 }
268
269     /**
270      * Gets the notifications for a given ObjectName in a string form.
271      * @param objectNameStr objectNameStr for which the notifications are required.
272      *
273      * @returns list of notifications
274      * @throws InstanceNotFoundException,IntrospectionException, ReflectionException
275      * @throws MalformedObjectNameException
276      */

277 public List JavaDoc<String JavaDoc> getNotificationTypes(String JavaDoc objectNameStr) throws
278                      MalformedObjectNameException JavaDoc,
279                      InstanceNotFoundException JavaDoc, IntrospectionException JavaDoc,
280                      ReflectionException JavaDoc {
281     return ManagementRulesMBeanHelper.getNotificationTypes(objectNameStr);
282 }
283
284
285 public List JavaDoc<String JavaDoc> getAttributes(String JavaDoc dottedName) { return null; }
286
287 public List JavaDoc<String JavaDoc> getDottedNames(String JavaDoc dottedName) { return null; }
288
289
290 }
291
292
Popular Tags