KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > DeploymentNotificationHelper


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.admin.server.core;
25
26 import java.io.BufferedReader JavaDoc;
27 import java.io.File JavaDoc;
28 import java.io.FileNotFoundException JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.io.InputStreamReader JavaDoc;
31 import java.io.IOException JavaDoc;
32 import java.net.InetAddress JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Collection JavaDoc;
36 import java.util.Enumeration JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.logging.Level JavaDoc;
39 import java.util.logging.Logger JavaDoc;
40 import java.util.Properties JavaDoc;
41 import java.util.StringTokenizer JavaDoc;
42 import java.util.Vector JavaDoc;
43
44 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
45 import javax.management.MBeanException JavaDoc;
46 import javax.management.MBeanInfo JavaDoc;
47 import javax.management.MBeanRegistration JavaDoc;
48 import javax.management.MBeanServer JavaDoc;
49 import javax.management.ObjectName JavaDoc;
50
51 import com.sun.enterprise.admin.AdminContext;
52 import com.sun.enterprise.admin.common.constant.AdminConstants;
53 import com.sun.enterprise.admin.common.constant.ConfigAttributeName;
54 import com.sun.enterprise.admin.common.constant.DeploymentConstants;
55 import com.sun.enterprise.admin.common.exception.AFException;
56 import com.sun.enterprise.admin.common.exception.AFJDBCResourceException;
57 import com.sun.enterprise.admin.common.exception.AFResourceException;
58 import com.sun.enterprise.admin.common.exception.AFRuntimeStoreException;
59 import com.sun.enterprise.admin.common.exception.ControlException;
60 import com.sun.enterprise.admin.common.exception.DeploymentException;
61 import com.sun.enterprise.admin.common.exception.IllegalStateException;
62 import com.sun.enterprise.admin.common.exception.MBeanConfigException;
63 import com.sun.enterprise.admin.common.exception.PortInUseException;
64 import com.sun.enterprise.admin.common.exception.ServerInstanceException;
65 import com.sun.enterprise.admin.common.InitConfFileBean;
66 import com.sun.enterprise.admin.common.MBeanServerFactory;
67 import com.sun.enterprise.admin.common.ObjectNameHelper;
68 import com.sun.enterprise.admin.common.ObjectNames;
69 import com.sun.enterprise.admin.common.RequestID;
70 import com.sun.enterprise.admin.common.ServerInstanceStatus;
71 import com.sun.enterprise.admin.common.Status;
72 import com.sun.enterprise.admin.event.AdminEvent;
73 import com.sun.enterprise.admin.event.AdminEventCache;
74 import com.sun.enterprise.admin.event.AdminEventListenerException;
75 import com.sun.enterprise.admin.event.AdminEventMulticaster;
76 import com.sun.enterprise.admin.event.AdminEventResult;
77 import com.sun.enterprise.admin.event.ApplicationDeployEvent;
78 import com.sun.enterprise.admin.event.BaseDeployEvent;
79 import com.sun.enterprise.admin.event.ConfigChangeEvent;
80 import com.sun.enterprise.admin.event.EventBuilder;
81 import com.sun.enterprise.admin.event.EventContext;
82 import com.sun.enterprise.admin.event.EventStack;
83 import com.sun.enterprise.admin.event.ModuleDeployEvent;
84 import com.sun.enterprise.admin.event.ResourceDeployEvent;
85 import com.sun.enterprise.admin.server.core.AdminService;
86 import com.sun.enterprise.admin.server.core.channel.AdminChannel;
87 import com.sun.enterprise.admin.server.core.channel.RMIClient;
88 import com.sun.enterprise.admin.server.core.ManualChangeManager;
89 import com.sun.enterprise.admin.server.core.mbean.config.Domain2ServerTransformer;
90 import com.sun.enterprise.admin.util.ArgChecker;
91 import com.sun.enterprise.admin.util.Assert;
92 import com.sun.enterprise.admin.util.ExceptionUtil;
93 import com.sun.enterprise.admin.util.HostAndPort;
94 import com.sun.enterprise.admin.util.StringValidator;
95 import com.sun.enterprise.config.ConfigBean;
96 import com.sun.enterprise.config.ConfigBeansFactory;
97 import com.sun.enterprise.config.ConfigContext;
98 import com.sun.enterprise.config.ConfigContext;
99 import com.sun.enterprise.config.ConfigException;
100 import com.sun.enterprise.config.ConfigFactory;
101 import com.sun.enterprise.config.ConfigFactory;
102 import com.sun.enterprise.config.serverbeans.*;
103 import com.sun.enterprise.config.serverbeans.Applications;
104 import com.sun.enterprise.config.serverbeans.J2eeApplication;
105 import com.sun.enterprise.config.serverbeans.JavaConfig;
106 import com.sun.enterprise.config.serverbeans.ServerTags;
107 import com.sun.enterprise.config.serverbeans.ServerXPathHelper;
108 import com.sun.enterprise.connectors.ConnectorRuntime;
109 import com.sun.enterprise.connectors.util.JmsRaMapping;
110 import com.sun.enterprise.deployment.backend.*;
111 import com.sun.enterprise.instance.InstanceDefinition;
112 import com.sun.enterprise.instance.InstanceEnvironment;
113 import com.sun.enterprise.instance.InstanceEnvironment;
114 import com.sun.enterprise.instance.ServerManager;
115 import com.sun.enterprise.security.auth.realm.BadRealmException;
116 import com.sun.enterprise.security.auth.realm.file.FileRealm;
117 import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
118 import com.sun.enterprise.security.auth.realm.NoSuchUserException;
119 import com.sun.enterprise.security.util.IASSecurityException;
120 import com.sun.enterprise.server.Constants;
121 import com.sun.enterprise.util.i18n.StringManager;
122 import com.sun.enterprise.util.net.NetUtils;
123
124 import com.sun.enterprise.admin.server.core.AdminService;
125 import com.sun.enterprise.admin.AdminContext;
126
127 /**TBD
128 */

129
130 public class DeploymentNotificationHelper
131 {
132      public static final Logger JavaDoc sLogger =
133             Logger.getLogger(AdminConstants.kLoggerName);
134
135      private static final int CONFIG_CHANGED = 7;
136
137     // i18n StringManager
138
private static StringManager localStrings =
139         StringManager.getManager( DeploymentNotificationHelper.class );
140
141     /**
142         Convenience method to multicast events. This method is being used to
143         events other than ModuleDeployEvent.
144     */

145
146         /*
147     private static boolean multicastEvent(int eventType, String entityName)
148         throws DeploymentException
149     {
150         return multicastEvent(eventType, entityName, null);
151     }
152
153          */

154         
155         /*
156     public static boolean multicastEvent(int eventType, String entityName,
157             String moduleType) throws DeploymentException {
158         return multicastEvent(eventType, entityName, moduleType, false);
159     }
160
161          */

162         
163     /**
164         Multicasts the event to the respective listeners. The listeners are
165         multicast from here even if the instance is not running. The
166         AdminEventMulticaster should take care of it.
167         @return true if the instance is up and event was sent and successfully
168             handled or if the instance is down, false otherwise.
169     */

170         /*
171     public boolean multicastEvent(int eventType, String entityName,
172           String moduleType , boolean cascade) throws DeploymentException {
173         return multicastEvent(eventType, entityName, moduleType, cascade, false, null);
174     }
175          */

176
177                                                                                                                                                
178     /**
179      * Multicasts the event to the respective listeners. The listeners are
180      * multicast from here even if the instance is not running. The
181      * AdminEventMulticaster should take care of it.
182      * @return true if the instance is up and event was sent and successfully
183      * handled or if the instance is down, false otherwise.
184      */

185     public static boolean multicastEvent(int eventType, String JavaDoc entityName,
186            String JavaDoc moduleType , boolean cascade, boolean forceDeploy, int loadUnloadAction, String JavaDoc targetName) throws DeploymentException
187     {
188         //String name = getInstanceName();
189
AdminEvent event = null;
190         EventBuilder builder = new EventBuilder();
191
192         //XXX Can we put the following 4 lines be done in the EventBuilder?
193
EventStack stack = EventContext.getEventStackFromThreadLocal();
194         ConfigContext ctx = stack.getConfigContext();
195         stack.setTarget(targetName);
196         stack.setConfigChangeList(ctx.getConfigChangeList());
197
198         try{
199             if (eventType == BaseDeployEvent.APPLICATION_DEPLOYED)
200             {
201                 event = builder.createApplicationDeployEvent(
202                     BaseDeployEvent.DEPLOY, entityName, false, forceDeploy,
203                     loadUnloadAction);
204             }
205             else if (eventType == BaseDeployEvent.APPLICATION_UNDEPLOYED)
206             {
207                 event = builder.createApplicationDeployEvent(
208                     BaseDeployEvent.UNDEPLOY, entityName, cascade, forceDeploy, loadUnloadAction);
209             }
210             else if (eventType == BaseDeployEvent.APPLICATION_REDEPLOYED)
211             {
212                 event = builder.createApplicationDeployEvent(
213                     BaseDeployEvent.REDEPLOY, entityName, false, forceDeploy,
214                     loadUnloadAction);
215             }
216             else if (eventType == BaseDeployEvent.MODULE_DEPLOYED)
217             {
218                 event = builder.createModuleDeployEvent(
219                     BaseDeployEvent.DEPLOY, entityName, moduleType, cascade, forceDeploy);
220             }
221             else if (eventType == BaseDeployEvent.MODULE_UNDEPLOYED)
222             {
223                 event = builder.createModuleDeployEvent(
224                     BaseDeployEvent.UNDEPLOY, entityName, moduleType, cascade, forceDeploy);
225             }
226             else if (eventType == BaseDeployEvent.MODULE_REDEPLOYED)
227             {
228                 event = builder.createModuleDeployEvent(
229                     BaseDeployEvent.REDEPLOY, entityName, moduleType);
230             }
231             else if (eventType == BaseDeployEvent.APPLICATION_ENABLE)
232             {
233                 event = builder.createApplicationDeployEvent(
234                     BaseDeployEvent.ENABLE, entityName, false, forceDeploy,
235                     loadUnloadAction);
236             }
237             else if (eventType == BaseDeployEvent.APPLICATION_DISABLE)
238             {
239                 event = builder.createApplicationDeployEvent(
240                     BaseDeployEvent.DISABLE, entityName, false, forceDeploy,
241                     loadUnloadAction);
242             }
243             else if(eventType == BaseDeployEvent.MODULE_ENABLE)
244             {
245                 event = builder.createModuleDeployEvent(
246                     BaseDeployEvent.ENABLE, entityName, moduleType, false, forceDeploy);
247             }
248             else if(eventType == BaseDeployEvent.MODULE_DISABLE)
249             {
250                 event = builder.createModuleDeployEvent(
251                     BaseDeployEvent.DISABLE, entityName, moduleType, false, forceDeploy);
252             }
253             else if(eventType == BaseDeployEvent.APPLICATION_REFERENCED)
254             {
255                       event = builder.createApplicationDeployEvent(
256                     BaseDeployEvent.ADD_REFERENCE, entityName, false, forceDeploy, loadUnloadAction);
257             }
258             else if(eventType == BaseDeployEvent.APPLICATION_UNREFERENCED)
259             {
260                     event = builder.createApplicationDeployEvent(
261                     BaseDeployEvent.REMOVE_REFERENCE, entityName, false, forceDeploy, loadUnloadAction);
262             }
263             else if (eventType == CONFIG_CHANGED)
264             {
265                 event = builder.createConfigChangeEvent(targetName, null);
266             }
267             else
268             {
269                 String JavaDoc msg =
270                     localStrings.getString( "admin.server.core.mbean.config.no_such_event",
271                                             new Integer JavaDoc(eventType) );
272                 throw new RuntimeException JavaDoc( msg );
273             }
274         } catch (ConfigException ex) {
275             DeploymentException de = new DeploymentException(ex.getMessage());
276             de.initCause(ex);
277             throw de;
278         }
279
280         //set target destination for the event
281
if (targetName != null) {
282             event.setTargetDestination(targetName);
283         }
284
285         if (event instanceof ApplicationDeployEvent
286                 || event instanceof ModuleDeployEvent) {
287             AdminEventCache.populateConfigChange(getConfigContext(), event);
288         }
289         
290         if (sLogger.isLoggable(Level.FINEST)) {
291             sLogger.log(Level.FINEST, "mbean.event_sent", event.getEventInfo());
292         } else {
293             sLogger.log(Level.FINE, "mbean.send_event", event.toString());
294         }
295
296         AdminEventResult multicastResult =
297                 AdminEventMulticaster.multicastEvent(event);
298         sLogger.log(Level.FINE, "mbean.event_res",
299                 multicastResult.getResultCode());
300         sLogger.log(Level.FINE, "mbean.event_reply",
301                 multicastResult.getAllMessagesAsString());
302         boolean eventSuccess = true;
303             //ALREADY SET in Admin Event Multicaster
304
//AdminEventCache cache =
305
// AdminEventCache.getInstance(mInstanceName);
306
//cache.setRestartNeeded(true);
307

308             // if there is an exception thrown when loading modules
309
// rethrow the exception
310
AdminEventListenerException ale = null;
311             ale = multicastResult.getFirstAdminEventListenerException();
312             if (ale != null) {
313                 sLogger.log(Level.WARNING, "mbean.event_failed",
314                     ale.getMessage());
315                 DeploymentException de =
316                     new DeploymentException(ale.getMessage());
317                 de.initCause(ale);
318                 throw de;
319             }
320         return eventSuccess;
321     }
322
323     private static ConfigContext getConfigContext() {
324          AdminContext adminContext =
325                         AdminService.getAdminService().getAdminContext();
326          return adminContext.getAdminConfigContext();
327     }
328 }
329
Popular Tags