KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > selfmanagement > reconfig > ManagementRuleReconfig


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 package com.sun.enterprise.management.selfmanagement.reconfig;
25
26 import com.sun.enterprise.management.selfmanagement.SelfManagementService;
27 import com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEvent;
28 import com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEventListener;
29
30 import com.sun.enterprise.admin.event.AdminEventListener;
31 import com.sun.enterprise.admin.event.AdminEventListenerException;
32 import com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEvent;
33 import com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEventListener;
34 import com.sun.enterprise.config.ConfigAdd;
35 import com.sun.enterprise.config.ConfigSet;
36 import com.sun.enterprise.config.ConfigDelete;
37 import com.sun.enterprise.config.ConfigChange;
38 import com.sun.enterprise.config.ConfigContext;
39 import com.sun.enterprise.config.ConfigException;
40 import com.sun.enterprise.config.ConfigUpdate;
41 import com.sun.enterprise.config.ConfigBean;
42 import com.sun.enterprise.config.serverbeans.Config;
43 import com.sun.enterprise.config.serverbeans.ElementProperty;
44 import com.sun.enterprise.config.serverbeans.ManagementRules;
45 import com.sun.enterprise.config.serverbeans.ManagementRule;
46 import com.sun.enterprise.config.serverbeans.Action;
47 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
48 import com.sun.enterprise.config.serverbeans.Server;
49
50 import java.util.ArrayList JavaDoc;
51 import java.util.logging.Logger JavaDoc;
52 import java.util.logging.Level JavaDoc;
53 import com.sun.logging.LogDomains;
54
55 /**
56  * This class handles dynamic reconfiguration notification related to
57  * management-rule creation, update and deletion.
58  *
59  * @author Pankaj Jairath
60  */

61 public class ManagementRuleReconfig implements ManagementRuleEventListener{
62     
63     private static SelfManagementService service =
64                                  SelfManagementService.getService();
65     
66     /** Logger for self management service */
67     private static Logger JavaDoc _logger = null;
68     
69     static {
70         _logger = LogDomains.getLogger(LogDomains.SELF_MANAGEMENT_LOGGER);
71     }
72     
73     /**
74      * Create a new management-rule
75      */

76     public void handleCreate(ManagementRuleEvent event)
77                                             throws AdminEventListenerException {
78         _logger.log(Level.FINE,"sgmt.reconfig_handlecreatereceived");
79         
80         try{
81             ConfigContext configContext = event.getConfigContext();
82             Config config = ServerBeansFactory.getConfigBean(configContext);
83             ConfigAdd configAdd = null;
84             ConfigChange configChange = null;
85             ArrayList JavaDoc<ConfigChange> configChangeList = event.getConfigChangeList();
86             ManagementRule rule = null;
87             String JavaDoc xpath = null;
88             String JavaDoc pXPath = null;
89             Object JavaDoc object;
90             
91             for (int i=0; i < configChangeList.size(); i++){
92                 configChange = configChangeList.get(i);
93                 if (configChange instanceof ConfigAdd) {
94                     _logger.log(Level.INFO,"sgmt.reconfig_handlecreaterulereceived");
95                     xpath = configChange.getXPath();
96                     //
97
if (xpath != null) {
98                         _logger.log(Level.INFO, "sgmt.reconfig_handlexpath",xpath);
99                         rule = (ManagementRule)configContext.exactLookup(xpath);
100                         if (rule.isEnabled()) {
101                             service.addRule(rule, configContext);
102                         } else {
103                             service.addDisabledRule(rule);
104                         }
105                     }
106                 } else if(configChange instanceof ConfigSet) {
107                     //handle action addition
108
pXPath = configChange.getParentXPath();
109                     String JavaDoc name = configChange.getName();
110                     if (name.equals(ManagementRule.ACTION)) {
111                         _logger.log(Level.INFO,"smgt.handleactionadd",pXPath);
112                         rule = (ManagementRule)configContext.exactLookup(pXPath);
113                         service.handleActionAdd(rule, configContext);
114                     }
115                 }
116             }
117         } catch (Exception JavaDoc ex) {
118            throw new AdminEventListenerException(ex);
119         }
120     }
121     
122     
123     /**
124      * Update an existing management-rule.
125      */

126     public void handleUpdate(ManagementRuleEvent event)
127                                             throws AdminEventListenerException {
128         _logger.log(Level.INFO,"sgmt.reconfig_handleupdatereceived");
129
130         try {
131             ConfigContext configContext = event.getConfigContext();
132             ConfigContext oldConfigContext = event.getOldConfigContext();
133             Config config = ServerBeansFactory.getConfigBean(configContext);
134             ConfigUpdate configUp = null;
135             ArrayList JavaDoc<ConfigUpdate> configChangeList = event.getConfigChangeList();
136             String JavaDoc xPath = null;
137             Object JavaDoc object;
138
139             for (int i=0; i < configChangeList.size(); i++){
140                 configUp = configChangeList.get(i);
141
142                 xPath = configUp.getXPath();
143                 if (xPath!=null) {
144                     _logger.log(Level.INFO,"sgmt.handleupdatexpath", xPath);
145                     object = configContext.exactLookup(xPath);
146                     if (object instanceof ManagementRules) {
147                         ManagementRules rules = (ManagementRules)object;
148                         service.handleRulesUpdate(configContext,configUp);
149                     } else if(object instanceof ManagementRule) {
150                         ManagementRule rule = (ManagementRule)oldConfigContext.exactLookup(xPath);
151                         service.handleRuleUpdate(rule,configUp,configContext);
152                     } else if (object instanceof Action) {
153                         String JavaDoc pXPath = xPath.substring(0,xPath.lastIndexOf("/"));;
154                         ManagementRule rule = (ManagementRule)configContext.exactLookup(pXPath);
155                         service.handleActionUpdate(rule,configUp);
156                     }
157                  }
158             }
159                      
160        
161         } catch (Exception JavaDoc ex) {
162            throw new AdminEventListenerException(ex);
163         }
164  
165     }
166     
167     
168     /**
169      * Delete an existing management-rule.
170      */

171     public void handleDelete(ManagementRuleEvent event)
172                                            throws AdminEventListenerException {
173         _logger.log(Level.INFO,"sgmt.reconfig_handledeletereceived");
174         try{
175             ConfigContext configContext = event.getOldConfigContext();
176             Config config = ServerBeansFactory.getConfigBean(configContext);
177             ConfigDelete configDel = null;
178             ArrayList JavaDoc<ConfigDelete> configChangeList = event.getConfigChangeList();
179             ManagementRule rule = null;
180             String JavaDoc xpath = null;
181             Object JavaDoc object;
182
183             for (int i=0; i < configChangeList.size(); i++){
184                 configDel = configChangeList.get(i);
185
186                 xpath = configDel.getXPath();
187                 if (xpath != null){
188                     _logger.log(Level.INFO, "sgmt.reconfig_handledelxpath",xpath);
189                     //rule = (ManagementRule)configContext.exactLookup(xpath);
190
object = configContext.exactLookup(xpath);
191                     if (object instanceof Action) {
192                         //handle action removal - noaction
193
} else if (object instanceof ManagementRule) {
194                         rule = (ManagementRule)object;
195                         String JavaDoc ruleName = rule.getName();
196                         service.deleteRule(ruleName);
197                     }
198                 }
199             }
200         } catch( Exception JavaDoc ex){
201            throw new AdminEventListenerException(ex);
202         }
203     }
204 }
205
Popular Tags