KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.admin.server.core;
24
25 //JDK imports
26
import com.sun.enterprise.admin.event.MBeanElementChangeEvent;
27 import com.sun.enterprise.admin.event.MBeanElementChangeEventListener;
28 import java.io.File JavaDoc;
29 import java.util.Properties JavaDoc;
30
31 //JMX imports
32
import javax.management.MBeanServer JavaDoc;
33 import javax.management.MalformedObjectNameException JavaDoc;
34 import javax.management.ObjectName JavaDoc;
35 //admin imports
36
import com.sun.enterprise.admin.common.MBeanServerFactory;
37 import com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor;
38
39 import com.sun.enterprise.admin.event.AdminEventListenerRegistry;
40 import com.sun.enterprise.admin.event.AdminEventListener;
41 import com.sun.enterprise.admin.event.tx.TransactionsRecoveryEventListener;
42 import com.sun.enterprise.admin.event.tx.TransactionsRecoveryEvent;
43 import com.sun.enterprise.admin.event.WebConfigChangeEventListener;
44 import com.sun.enterprise.admin.event.DynamicReconfigEvent;
45 import com.sun.enterprise.admin.event.DynamicReconfigEventListener;
46 import com.sun.enterprise.admin.monitor.GenericMonitorMBean;
47 import com.sun.enterprise.admin.server.core.channel.AdminChannel;
48 import com.sun.enterprise.instance.ServerManager;
49 import com.sun.enterprise.admin.common.constant.AdminConstants;
50 import com.sun.enterprise.instance.InstanceEnvironment;
51
52 import com.sun.enterprise.server.Constants;
53 import com.sun.enterprise.server.ServerContext;
54 import com.sun.enterprise.server.ServerContextImpl;
55
56 import com.sun.appserv.server.ServerLifecycleException;
57 import com.sun.appserv.server.ServerLifecycle;
58
59 import com.sun.enterprise.config.ConfigContext;
60 import com.sun.enterprise.config.ConfigException;
61 import com.sun.enterprise.config.serverbeans.ServerHelper;
62 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
63
64 import com.sun.enterprise.web.PEWebContainer;
65
66 //Logging related imports
67
import java.util.logging.Level JavaDoc;
68 import java.util.logging.Logger JavaDoc;
69 import com.sun.logging.LogDomains;
70
71 //Utility methods
72
import com.sun.enterprise.util.io.FileUtils;
73 import com.sun.enterprise.util.i18n.StringManager;
74
75 //autodeploy
76
import com.sun.enterprise.deployment.autodeploy.AutoDeployControllerImpl;
77 import com.sun.enterprise.deployment.autodeploy.AutoDeployController;
78 import com.sun.enterprise.deployment.autodeploy.AutoDeployConstants;
79 import com.sun.enterprise.deployment.autodeploy.AutoDeploymentException;
80 import com.sun.enterprise.deployment.autodeploy.AutoDeployControllerFactroy;
81 import com.sun.enterprise.deployment.autodeploy.AutoDeployControllerFactroyImpl;
82
83 //web service
84
import com.sun.enterprise.webservice.WsUtil;
85
86 import com.sun.enterprise.admin.AdminContext;
87 import com.sun.enterprise.admin.meta.MBeanRegistry;
88 import com.sun.enterprise.admin.meta.MBeanRegistryFactory;
89 import com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerFactory;
90 import com.sun.enterprise.admin.common.ObjectNames;
91 import com.sun.enterprise.admin.server.core.channel.RRStateFactory;
92
93 //AMX: can't import, module build-order dependency
94
//import com.sun.enterprise.management.support.Loader;
95

96 import com.sun.enterprise.Switch;
97 import com.sun.enterprise.admin.monitor.callflow.Agent;
98 import com.sun.enterprise.admin.monitor.callflow.AgentAdapter;
99
100 /**
101  * Admin service is a singleton in every instance and acts as gateway to server
102  * administration tasks.
103  */

104 public class AdminService {
105
106     /**
107      * Admin service type DASD. Used to identify admin service in a server
108      * instance that acts as DAS and also allows normal server operations like
109      * deployment and running of user applications.
110      */

111     public static final String JavaDoc TYPE_DASD = "das-and-server";
112
113     /**
114      * Admin service type DAS. Used to identify admin service in a server
115      * instance dedicated to administration.
116      */

117     public static final String JavaDoc TYPE_DAS = "das";
118
119     /**
120      * Admin service type SERVER. Used to identify admin service in a server
121      * instance dedicated to running user applications.
122      */

123     public static final String JavaDoc TYPE_SERVER = "server";
124
125     /*
126      * Flag to enable performance. If the flag is enabled, checking for manual
127      * changes is done every 2 minutes instead of at every access to config
128      * files.
129      */

130     public static final boolean ENABLE_PERFORMANCE_THREAD = true;
131     
132     /** The logger from LogDomains */
133     /* Note that this is the ONLY class that is dependent on the LogDomains.
134      * Once registered through LogDomains, others can get it using standard
135      * call Logger.getLogger() */

136     public static final Logger JavaDoc sLogger
137             = LogDomains.getLogger(AdminConstants.kLoggerName);
138
139     private static StringManager localStrings =
140         StringManager.getManager(AdminService.class);
141
142     private static AdminService adminService = null;
143
144     /** prefix for administrative domain name */
145     private static final String JavaDoc ADMIN_DOMAIN_NAME_PREFIX = "com.sun.appserv.";
146
147     /** default administrative domain name */
148     private static final String JavaDoc DEF_ADMIN_DOMAIN_NAME="com.sun.appserv.server";
149
150     private static String JavaDoc kTempDirNamePrefix = "s1astemp";
151     private static String JavaDoc kGUITempDirName = "gui";
152     private static String JavaDoc kTempDirNameSuffix =
153             "" + ((System.getProperty(Constants.IAS_ROOT) != null) ?
154             System.getProperty(Constants.IAS_ROOT).hashCode() : 0);
155     /* The temporary directory name should be a function of domain name,
156      * admin-server id and the install root, otherwise it won't
157      * work for the multiple installations on the same machine. */

158     private static int sMBeanServerID;
159     public static final int kDefaultImpl = 0;
160     private static final String JavaDoc SS_MBEAN_CLASS = "com.sun.enterprise.admin.mbeans.SystemServicesMBean";
161     private String JavaDoc adminServiceType;
162     private ServerContext context;
163     private AdminContext adminContext;
164     private ServerLifecycle adminChannel;
165     private String JavaDoc mTempDirPath;
166     private String JavaDoc mGUITempDirPath;
167     private AutoDeployController autoDeployController;
168     
169     /** A field to denote the default name for all the config and runtime mbeans that are
170      * generated from the meta-information (descriptor, like admin-mbean-descriptor.xml) */

171     public static final String JavaDoc PRIVATE_MBEAN_DOMAIN_NAME = "com.sun.appserv";
172     public static final String JavaDoc DAS_DIAGNOSTIC_MBEAN_CLASS_NAME =
173                 "com.sun.enterprise.admin.mbeans.DomainDiagnostics";
174
175
176     /**
177      * private constructor. AdminService instance should be initialized
178      * through package method createAdminService().
179      */

180     private AdminService() {
181         sMBeanServerID = kDefaultImpl; //the only implementation for now
182
}
183
184     /**
185      * Create admin service. Admin Service is initialized by an internal
186      * lifecycle module (AdminServiceLifeCycle).
187      */

188     static AdminService createAdminService(ServerContext sc) {
189         System.setProperty("com.sun.aas.admin.logger.name",
190                 AdminConstants.kLoggerName);
191         String JavaDoc type = TYPE_SERVER;
192         if (ServerManager.ADMINSERVER_ID.equals(sc.getInstanceName())) {
193             type = TYPE_DAS;
194         }
195         ConfigContext cc = sc.getConfigContext();
196         try {
197             com.sun.enterprise.config.serverbeans.AdminService as =
198                     ServerBeansFactory.getConfigBean(cc).getAdminService();
199             if (as != null) {
200                 type = as.getType();
201             }
202         } catch (ConfigException ce) {
203             ce.printStackTrace();
204             sLogger.log(Level.WARNING, "core.admin_service_default_config",
205                     type);
206         }
207         AdminService as = instantiateAdminService(type);
208         as.setContext(sc);
209         AdminContext ac = sc.getPluggableFeatureFactory().getAdminContext();
210         if (ac instanceof AdminContextImpl) {
211             ((AdminContextImpl)ac).setServerContext((ServerContextImpl)sc);
212         }
213         as.setAdminContext(ac);
214         setAdminService(as);
215         return as;
216     }
217
218     /**
219      * Instantiate admin service. This method verifies that specified type
220      * is a known type and then creates an admin service object initialized
221      * for the specified type.
222      */

223     private static AdminService instantiateAdminService(String JavaDoc type) {
224         AdminService as = null;
225         if (TYPE_DASD.equals(type) || TYPE_DAS.equals(type)
226                 || TYPE_SERVER.equals(type)) {
227              as = new AdminService();
228              as.setType(type);
229         } else {
230             throw new RuntimeException JavaDoc(localStrings.getString(
231                     "admin.server.core.unknown_admin_service_type", type));
232         }
233         return as;
234     }
235
236     /**
237      * Set AdminService. This method should be called by createInstance()
238      * method after instantiating the service. This enables other objects to use
239      * static method getAdminService to get access to admin service.
240      */

241     private static void setAdminService(AdminService srv) {
242         adminService = srv;
243     }
244
245     /**
246      * Get admin service object. Admin service is started when server starts
247      * up.
248      */

249     public static AdminService getAdminService() {
250         return adminService;
251     }
252
253     /**
254      * Initialize admin service. This is called just after creating the
255      * instance and before any public methods are called on admin service.
256      * Initializes the admin server's MBeanServer.
257      * Currently initializes the MBeanServer with default implementation in
258      * com.sun.enterprise.admin.server.core.jmx.MBeanServerImpl.
259      * Should there be multiple implementations, this method needs to be
260      * modified.
261      * @throws LifeCycleException in case the initialzation fails.
262      */

263     void init() throws ServerLifecycleException {
264
265         if (isDas()) {
266             // remove restart required state file when starting up DAS
267
RRStateFactory.removeStateFile();
268         }
269         adminChannel = new AdminChannelLifecycle();
270         adminChannel.onInitialization(context);
271
272         MBeanServer JavaDoc mbs = null;
273
274         try {
275             if (sMBeanServerID == kDefaultImpl) {
276                 SunoneInterceptor.setAdminContext(adminContext);
277                 mbs = SunoneInterceptor.getMBeanServerInstance();
278                 MBeanServerFactory.initialize(this, mbs);
279             } else {
280                 throw new RuntimeException JavaDoc(localStrings.getString(
281                         "admin.server.core.mbs_init_error"));
282             }
283             if (adminContext != null) {
284                 adminContext.setMBeanServer(mbs);
285             }
286             sLogger.log(Level.INFO, "core.mbs_init_ok");
287         initCallFlow();
288         }
289         catch (Throwable JavaDoc t) {
290             sLogger.log(Level.FINEST, t.getMessage(), t);
291             if (isDas()) {
292                 sLogger.log(Level.SEVERE, "core.mbs_init_exception", t);
293             }
294             else {
295                 sLogger.log(Level.WARNING, "core.mbs_init_exception", t);
296             }
297             throw new ServerLifecycleException(t.getMessage());
298         }
299     }
300
301     private void initCallFlow() {
302         try {
303             Class JavaDoc cl = Class.forName(
304                     "com.sun.enterprise.admin.monitor.callflow.AgentImpl");
305             Agent agent = (Agent) cl.newInstance();
306             Switch.getSwitch().setCallFlowAgent(agent);
307         } catch (Throwable JavaDoc t) {
308             sLogger.log(Level.SEVERE, "core.callflow_agent_init_failed", t);
309             Switch.getSwitch().setCallFlowAgent(new AgentAdapter());
310         }
311     }
312
313     /**
314      * Start admin service. This is called prior to any public method call
315      * on admin service. This should be used to prepare admin service to
316      * receive public method calls.
317      */

318     void start() throws ServerLifecycleException {
319         com.sun.enterprise.ManagementObjectManager mgmtObjManager = com.sun.enterprise.Switch.getSwitch().getManagementObjectManager();
320         if (isDas()) {
321             startAdminInstance();
322             mgmtObjManager.registerJ2EEDomain();
323         }
324         
325         initializeAMXMBeans( isDas() );
326             
327         // Register JVM and J2EEServer managed objects
328
mgmtObjManager.registerJVM();
329         mgmtObjManager.registerJ2EEServer();
330             
331         if (isDas()) {
332         // das j2ee server should have been registered prior to this
333
// so
334
// mgmtObjManager.registerJ2EEServer() should run before this
335
mgmtObjManager.registerDasJ2EEServers();
336             mgmtObjManager.registerAllJ2EEClusters();
337     }
338
339         if (canRunUserApps()) {
340             startNormalInstance();
341         }
342
343
344         initializePerInstanceSystemService();
345         //This code initializes dotted names by enumerating
346
// all objectnames using domain.xml
347
initializeDottedNames();
348         registerTransactionsRecoveryEventMBean();
349         mgmtObjManager.registerTransactionService();
350         
351         // initialize the Web Service Container services
352
WsUtil.start();
353         // register DASDiagnosticMBean
354
createDASDiagnosticMBean();
355
356     }
357
358     /**
359      * Admin service is ready. All other services have started up successfully.
360      */

361     void ready() throws ServerLifecycleException {
362         if (isDas()) {
363            //check and start autodeploy service -FIX for 4933846
364
startAutoDeployService();
365         }
366         if (adminChannel != null) {
367             adminChannel.onReady(context);
368         }
369         initiateCustomMBeanLoading();
370         registerJVMMonitoringMBeans();
371         
372         // would be cleaner to issue JMX Notifications for a variety
373
// of events, but that would mean adding an MBean for AdminService.
374
notifyAMXThatAdminServiceIsReady();
375     }
376
377     /**
378      * Stop admin service. This is called when shutdown process starts.
379      */

380     void stop() throws ServerLifecycleException {
381         if (adminChannel != null) {
382             adminChannel.onShutdown();
383         }
384         com.sun.enterprise.ManagementObjectManager mgmtObjManager = com.sun.enterprise.Switch.getSwitch().getManagementObjectManager();
385         
386         //FIXE ME - Prakash
387
// Unregister J2EEDomain, j2eeserver and jvm managed objects.
388

389         if (isDas()) {
390             //stop checking for manual changes
391
if(ENABLE_PERFORMANCE_THREAD) ManualChangeTracker.stop();
392             stopAdminInstance();
393         }
394         if (canRunUserApps()) {
395             //autodeploy service stoped
396
stopAutoDeployService();
397             stopNormalInstance();
398         }
399         // as we are killing the VM, there is no real need of shutting down MBS.
400
}
401
402     /**
403      * Destroy admin service. This is called just before JVM is destroyed.
404      */

405     void destroy() throws ServerLifecycleException {
406     }
407
408     /**
409      * Get server context.
410      */

411     public ServerContext getContext() {
412         return ((adminService == null) ? null : adminService.context);
413     }
414
415     /**
416      * Set context to specified value. Typically, lifecycle manager will call
417      * this method during initialization to set appropriate context.
418      */

419     void setContext(ServerContext ctx) {
420         context = ctx;
421     }
422
423     /**
424      * Get admin context.
425      */

426     public AdminContext getAdminContext() {
427         return adminContext;
428     }
429
430     /**
431      * Returns the administrative domain name for this server. If
432      * administrative domain name property is not defined,
433      * DEF_ADMIN_DOMAIN_NAME is returned.
434      *
435      * @return administrative domain name
436      */

437     public String JavaDoc getAdministrativeDomainName() throws ConfigException {
438
439         String JavaDoc serverName = adminContext.getServerName();
440         ConfigContext ctx = adminContext.getAdminConfigContext();
441         String JavaDoc aDomainName =
442             ServerHelper.getAdministrativeDomainName(ctx, serverName);
443
444         // return default administrative domain name if administrative domain
445
// name property is not defined
446
if ( (aDomainName == null) || ("".equals(aDomainName)) ) {
447             return DEF_ADMIN_DOMAIN_NAME;
448         } else {
449             return ADMIN_DOMAIN_NAME_PREFIX + aDomainName;
450         }
451     }
452
453     /**
454      * Set admin context.
455      */

456     protected void setAdminContext(AdminContext ctx) {
457          adminContext = ctx;
458     }
459
460     /**
461      * Get name of server instance.
462      */

463     public String JavaDoc getInstanceName() {
464         return ((context == null) ? null : context.getInstanceName());
465     }
466
467     /**
468      * Get root monitoring MBean. Monitoring MBeans within a server instance
469      * are organized in a tree. This object represents the root of the tree.
470      */

471     public GenericMonitorMBean getRootMonitorMBean() {
472         return GenericMonitorMBean.getRoot();
473     }
474
475     /**
476      * Helper method to start admin server instance
477      */

478     private void startAdminInstance() throws ServerLifecycleException {
479         setAdminInstanceProperties();
480         // Test code here
481
// new com.sun.enterprise.admin.event.EventTester();
482
// Uncomment following line to test monitoring
483
// new com.sun.enterprise.admin.monitor.MonitoringTester();
484
createTempDir();
485     }
486
487     /**
488      * Helper method to stop admin server instance.
489      */

490     private void stopAdminInstance() throws ServerLifecycleException {
491         deleteTempDir();
492     }
493
494     /**
495      * Helper method to start normal (non-admin) instances
496      */

497     private void startNormalInstance() throws ServerLifecycleException {
498         initLogManagerReconfigSupport();
499         registerTransactionsRecoveryEventListener();
500         // Test code here
501
// new com.sun.enterprise.admin.event.EventTester("str");
502
}
503
504     /**
505      * Helper method to stop normal (non-admin) instances
506      */

507     private void stopNormalInstance() throws ServerLifecycleException {
508     }
509
510     /**
511      * Is this admin service running within admin server instance. Admin service
512      * runs in all server instances.
513      * @return true if the service is running in an admin server instance,
514      * false otherwise.
515      * @deprecated Use the method isDas() instead.
516      */

517     public boolean isAdminInstance() {
518         if (ServerManager.ADMINSERVER_ID.equals(context.getInstanceName())) {
519             return true;
520         } else {
521             return false;
522         }
523     }
524
525     /**
526      * Is admin service configured for administration of domain. A domain has
527      * several server instances and typically one of them is capable of
528      * administering the other server instances in the domain.
529      * @return true if the admin service is running in an instance that can
530      * administer other instances in the domain, false otherwise.
531      */

532     public boolean isDas() {
533         if (TYPE_DASD.equals(adminServiceType)
534                 || TYPE_DAS.equals(adminServiceType)) {
535             return true;
536         } else {
537             return false;
538         }
539     }
540
541     /**
542      * Is admin service running in a server instance that is primarily intended
543      * for running user applications. Admin service runs in all server
544      * instances, but sometimes there is one server instance dedicated to
545      * administration of other instances in the domain and user applications
546      * can not not be run on that instance.
547      * @return true if user applications can be run on the server instance
548      * where this admin service is running, false otherwise.
549      */

550     public boolean canRunUserApps() {
551         if (TYPE_DAS.equals(adminServiceType)) {
552             return false;
553         } else {
554             return true;
555         }
556     }
557  
558     /**
559      * Get admin service type. Admin service type is defined in admin service
560      * configuration.
561      * @return one of TYPE_DAS, TYPE_DASD, TYPE_SERVER
562      */

563     public String JavaDoc getType() {
564         return adminServiceType;
565     }
566
567     /**
568      * Set type of admin service.
569      */

570     private void setType(String JavaDoc type) {
571         adminServiceType = type;
572     }
573     
574     /**
575      Creates the time stamp files (if do not exist) for the instances that the
576      admin server manages.
577     */

578     private void createTimeStampFilesForInstances() {
579         String JavaDoc[] instanceIds = ServerManager.instance().getInstanceNames(true);
580         for (int i = 0 ; i < instanceIds.length ; i ++) {
581             try {
582                 String JavaDoc instanceId = instanceIds[i];
583                 InstanceEnvironment ie = new InstanceEnvironment(instanceId);
584                 ie.createTimeStampFiles();
585                 sLogger.log(Level.FINE, "core.ts_files_ok", instanceId);
586             }
587             catch (Exception JavaDoc e) {
588                 //Log the exception for this instance, squelching is OK?
589
sLogger.log(Level.WARNING, "core.ts_files_failed", e);
590             }
591         }
592         
593     }
594
595     /**
596         Gets the name of the temporary folder where the admin-server would be
597         creating some temporary data. Note that this method is not a pure
598         accessor in the sense that it will create the folder on disk if
599         it does not exist.
600         @return String representing the absolute path of temporary folder, which
601         may be null if the file creation fails.
602     */

603     public String JavaDoc getTempDirPath() {
604         if (mTempDirPath == null) {
605         /* Give it one more try, if on the startup the
606            user does not have enough space and/or the temp
607            file was not created. Note that the first-time failure will
608            be detected in the log at startup.
609            Also note that this additional safety does not come without
610            the overhead of the null check for every call to this function.
611        */

612             createTempDir();
613         }
614         
615         return ( mTempDirPath );
616     }
617
618     /**
619         Gets the name of the temporary folder where the admin-GUI would be
620         creating some temporary data. Note that this method is not a pure
621         accessor in the sense that it will create the folder on disk if
622         it does not exist.
623         @return String representing the absolute path of temporary folder
624         for GUI, which may be null if the file creation fails.
625     */

626     public String JavaDoc getGUITempDirPath() {
627         if (mGUITempDirPath == null) {
628         /* Give it one more try, if on the startup the
629            user does not have enough space and/or the temp
630            file was not created. Note that the first-time failure will
631            be detected in the log at startup.
632            Also note that this additional safety does not come without
633            the overhead of the null check for every call to this function.
634        */

635             createTempDir();
636         }
637         else {
638             final File JavaDoc gd = new File JavaDoc(mGUITempDirPath);
639             if (!gd.exists()) {
640                 final boolean s = gd.mkdirs();
641                 if (!s) {
642                    final String JavaDoc msg = localStrings.getString("admin.server.core.gui_dir_failure", mGUITempDirPath);
643                    throw new RuntimeException JavaDoc(msg);
644                 }
645             }
646         }
647         
648         return ( mGUITempDirPath );
649     }
650
651     private void createTempDir() {
652         try {
653             String JavaDoc domainName = ServerManager.instance().getDomainName();
654             String JavaDoc localTmpDir = System.getProperty("java.io.tmpdir");
655             String JavaDoc asTempDirName = kTempDirNamePrefix + domainName +
656                     context.getInstanceName() + kTempDirNameSuffix;
657             /* for admin server, e.g. </tmp>/s1astempdomain1admin-server */
658             File JavaDoc tempFolder = new File JavaDoc(localTmpDir, asTempDirName);
659             mTempDirPath = tempFolder.getCanonicalPath();
660
661             /* for GUI, e.g. </tmp>/s1astempdomain1admin-server/gui*/
662             File JavaDoc guiTempFolder = new File JavaDoc(mTempDirPath, kGUITempDirName);
663             mGUITempDirPath = guiTempFolder.getCanonicalPath();
664             if (tempFolder.exists()) {
665                 /*
666                     If it exists, the delete method during earlier admin-server
667                     lifecycle was not able to delete the directory and
668                     that should be OK. The intent here is to create a
669                     directory if there does not exist one.
670                 */

671                 sLogger.log(Level.FINEST, "core.tmp_folder_exists",
672                     mTempDirPath);
673                 return;
674             }
675             /* try to create admin-server's temporary directory */
676             boolean couldCreate = tempFolder.mkdirs();
677             if (! couldCreate) {
678                 sLogger.log(Level.WARNING, "core.tmp_folder_creation_failed",
679                         mTempDirPath);
680             }
681             else {
682                 sLogger.log(Level.FINEST, "core.tmp_folder_created_ok",
683                     mTempDirPath);
684             }
685             /* try to create temporary directory for GUI*/
686             couldCreate = guiTempFolder.mkdirs();
687             if (! couldCreate) {
688                 sLogger.log(Level.WARNING, "core.gui_tmp_folder_creation_failed",
689                         mGUITempDirPath);
690             }
691             else {
692                 sLogger.log(Level.FINEST, "core.gui_tmp_folder_created_ok",
693                     mGUITempDirPath);
694             }
695         }
696         catch(Throwable JavaDoc t) {
697             sLogger.log(Level.WARNING, "core.tmp_folder_creation_failed", t);
698         }
699     }
700
701     private void deleteTempDir() {
702         try {
703             FileUtils.whack(new File JavaDoc(mTempDirPath));
704             sLogger.log(Level.FINEST, "core.tmp_folder_deleted_ok",
705                 mTempDirPath);
706         }
707         catch(Throwable JavaDoc t) {
708             sLogger.log(Level.WARNING, "core.tmp_folder_deletion_failed",
709                     mTempDirPath);
710         }
711     }
712
713     /**
714      * Set system properties for admin server instance. Some of the admin code
715      * relies on the property <code>com.sun.aas.javaRoot</code>. This method
716      * will initialize the property using the value set by JVM plugin. If the
717      * property is already set, it will not be changed.
718      */

719     private void setAdminInstanceProperties() {
720         try {
721             String JavaDoc adminJavaRoot = System.getProperty(ADMIN_JAVAROOT);
722             String JavaDoc pluginJavaRoot = System.getProperty(PLUGIN_JAVAROOT);
723             if (adminJavaRoot == null) {
724                 if (pluginJavaRoot != null) {
725                     System.setProperty(ADMIN_JAVAROOT, pluginJavaRoot);
726                 } else {
727                     sLogger.log(Level.WARNING, "core.no_java_home");
728                 }
729             }
730         } catch (Throwable JavaDoc t) {
731             sLogger.log(Level.WARNING, "core.set_admin_property_failed");
732             sLogger.log(Level.FINE, "general.unexpected_exception", t);
733         }
734     }
735
736     private static final String JavaDoc ADMIN_JAVAROOT = "com.sun.aas.javaRoot";
737     private static final String JavaDoc PLUGIN_JAVAROOT = "JAVA_HOME";
738
739     /**
740      *to start autodeploy service
741      */

742     private void startAutoDeployService(){
743         try {
744             AutoDeployControllerFactroy controllerFactory = new AutoDeployControllerFactroyImpl();
745             autoDeployController = controllerFactory.createAutoDeployController(context);
746             if(autoDeployController !=null ) {
747                 autoDeployController.enableAutoDeploy();
748             }
749         } catch(Throwable JavaDoc tw) {
750             sLogger.log(Level.FINE, "general.unexpected_exception", tw);
751         }
752     }
753     
754     /**
755      *to stop autodeploy service
756      */

757     private void stopAutoDeployService(){
758         try {
759             if(autoDeployController !=null) {
760              autoDeployController.disableAutoDeploy();
761              autoDeployController=null;
762             }
763         } catch(Throwable JavaDoc tw) {
764             sLogger.log(Level.FINE, "general.unexpected_exception", tw);
765         }
766     }
767     
768     /**
769      * MBeanRegistry is used to generate all dotted names
770      * available in the system. This is achived by iterating
771      * through domain.xml and generating object name and
772      * dotted name for every element (some special cases)
773      *
774      * Dotted name is generated from the descriptor entry
775      *
776      * Once these are generated, an mbean is notified about
777      * these dotted names. In short, this mbean will keep track
778      * of the dotted names and is used by cli for get/set
779      * commands
780      */

781     private void initializeDottedNames() {
782         try {
783             MBeanRegistry mr = MBeanRegistryFactory.getAdminMBeanRegistry();
784             mr.generateAndRegisterAllDottedNames(context.getConfigContext(),
785                            context.getDefaultDomainName());
786         } catch (Throwable JavaDoc t) {
787              sLogger.log(Level.WARNING, "admin.dotted_names_init_exception", t);
788         }
789     }
790     
791     private void registerTransactionsRecoveryEventListener() {
792         try
793         {
794              AdminEventListenerRegistry.addEventListener(
795                 TransactionsRecoveryEvent.eventType,
796                 (AdminEventListener)(new com.sun.enterprise.transaction.TransactionsRecoveryEventListenerImpl()));
797         }
798         catch (Throwable JavaDoc t)
799         {
800              sLogger.log(Level.WARNING, "admin.transactions_recovery_listener_registration_exception", t);
801         }
802
803     }
804     private void registerTransactionsRecoveryEventMBean() {
805         try {
806             MBeanRegistryFactory.getAdminMBeanRegistry().instantiateMBean(
807                     "transactions-recovery", new String JavaDoc[]{adminContext.getDomainName()}, null, null, true );
808         } catch (Throwable JavaDoc t) {
809             sLogger.log(Level.FINE, "core.transactions_recovery_mbean_register_error", t);
810         }
811     }
812
813     
814     private void initLogManagerReconfigSupport() {
815         registerLogManagerMBean();
816         registerLogManagerEventListener();
817         registerDynamicReconfigEventListener();
818     }
819
820     private void registerLogManagerMBean() {
821         MBeanServer JavaDoc mbs = adminContext.getMBeanServer();
822         try {
823             Object JavaDoc mbean =
824                     com.sun.enterprise.server.logging.LogMBean.getInstance();
825             mbs.registerMBean(mbean, getLogManagerMBeanName());
826         } catch (Throwable JavaDoc t) {
827             sLogger.log(Level.WARNING, "core.logmgr_mbean_not_registered");
828             sLogger.log(Level.FINE, "core.logmgr_mbean_register_error", t);
829         }
830     }
831
832     private ObjectName JavaDoc getLogManagerMBeanName()
833             throws MalformedObjectNameException JavaDoc {
834         Properties JavaDoc props = new Properties JavaDoc();
835         props.put("server", adminContext.getServerName());
836         props.put("category", "runtime");
837         props.put("name", "logmanager");
838         ObjectName JavaDoc on = new ObjectName JavaDoc(adminContext.getDomainName(), props);
839         return on;
840     }
841
842     private void registerLogManagerEventListener() {
843          AdminEventListenerRegistry.addLogLevelChangeEventListener(
844                 new com.sun.enterprise.server.logging.LogLevelChangeEventListenerImpl());
845     }
846
847     private void registerDynamicReconfigEventListener() {
848          AdminEventListenerRegistry.addEventListener(
849                 DynamicReconfigEvent.eventType, new
850                 com.sun.enterprise.admin.server.core.channel.DynamicReconfigEventListenerImpl());
851     }
852     /** Registers the file transfer service (aka SystemServicesMBean) that will
853      * be registered in all the instances. Note that this MBean will have slightly
854      * different ObjectName depending upon where it is registered.
855      * @see ObjectNames.getPerInstanceSystemServicesObjectName
856      * <p>
857      * The principal use of this MBean is in <ul>
858      * <li> download of stubs in case of DAS </li>
859      * <li> synchronization in case of non DAS instances </li>.
860      */

861     private void initializePerInstanceSystemService() throws ServerLifecycleException {
862         ObjectName JavaDoc on = null;
863         try {
864             final MBeanServer JavaDoc mbs = getMBeanServer();
865             on = ObjectNames.getPerInstanceSystemServicesObjectName(this.getInstanceName());
866             final Object JavaDoc impl = Class.forName(SS_MBEAN_CLASS).newInstance();
867             mbs.registerMBean(impl, on);
868             sLogger.finer("Admin Message: System Services MBean Registered with on: " + on.toString());
869             if (isDas()) {
870                 //register SystemService MBean under the old 8.0 name as well
871
//to backward compatibility with 8.0 RI client - hardcoded
872
mbs.registerMBean(impl, new ObjectName JavaDoc("ias:type=system-services"));
873                 sLogger.finer("Admin Message: System Services MBean Registered with sibling name: " + on.toString());
874             }
875         }
876         catch (final Exception JavaDoc e) {
877             throw new ServerLifecycleException(e);
878         }
879     }
880     
881     
882
883     private static final String JavaDoc AMX_DAS_LOADER_CLASSNAME =
884         "com.sun.enterprise.management.support.Loader";
885         
886     private static final String JavaDoc AMX_NON_DAS_LOADER_CLASSNAME =
887         "com.sun.enterprise.management.support.NonDASLoader";
888         
889     public static final String JavaDoc AMX_LOADER_DEFAULT_OBJECTNAME =
890         "amx-support:name=mbean-loader";
891     
892     private ObjectName JavaDoc mAMXLoaderObjectName = null;
893         
894     /**
895         Initializes AMX MBeans
896         Uses Class.forName() due to build-order issues.
897      */

898     private void initializeAMXMBeans( boolean isDAS ) {
899         try {
900             // can't 'import' it because it's in the admin module, which
901
// compiles after the module this file is in.
902
final String JavaDoc loaderClassname =
903                 isDAS ? AMX_DAS_LOADER_CLASSNAME : AMX_NON_DAS_LOADER_CLASSNAME;
904                 
905             final Class JavaDoc loaderClass = Class.forName( loaderClassname );
906             final Object JavaDoc loader = loaderClass.newInstance();
907             ObjectName JavaDoc tempObjectName = new ObjectName JavaDoc( AMX_LOADER_DEFAULT_OBJECTNAME );
908             
909             mAMXLoaderObjectName =
910                 getMBeanServer().registerMBean( loader, tempObjectName ).getObjectName();
911             
912             sLogger.log(Level.INFO, "mbean.init_amx_success");
913         }
914         catch(Exception JavaDoc e) {
915             // why is this being ignored????
916
sLogger.log(Level.SEVERE, "mbean.init_amx_failed", e);
917             //ignore
918
throw new Error JavaDoc( e );
919         }
920     }
921     
922         private MBeanServer JavaDoc
923     getMBeanServer() {
924         try {
925             return AppServerMBeanServerFactory.getMBeanServerInstance();
926         }
927         catch( Exception JavaDoc e ) {
928             throw new RuntimeException JavaDoc( e );
929         }
930     }
931     
932
933     /**
934         Make a [synchronous] call to AMX. Semantics are that this should
935         be a quick call, not a long-running one.
936      */

937     private void notifyAMXThatAdminServiceIsReady() {
938         try {
939             getMBeanServer().invoke( mAMXLoaderObjectName, "adminServiceReady", null, null );
940         }
941         catch( Exception JavaDoc e ) {
942             throw new RuntimeException JavaDoc( e );
943         }
944     }
945     
946             
947     private void initiateCustomMBeanLoading() throws ServerLifecycleException {
948         try {
949         final MBeanServer JavaDoc mbs = adminContext.getMBeanServer();
950         final ConfigContext cc = context.getConfigContext();
951         new CustomMBeanRegistrationHelper(mbs, cc).registerMBeans();
952         } catch (final Exception JavaDoc e) {
953             e.printStackTrace();
954             throw new ServerLifecycleException(e); // we must not abort the startup, we must not affect other operations that may follow
955
}
956         initializeMBeanEventListeners();
957     }
958     private void registerJVMMonitoringMBeans() {
959         try {
960             //register the thread-dump related MBeans
961
final ObjectName JavaDoc dummy1 = new ObjectName JavaDoc("foo:bar=bar1"), dummy2 = new ObjectName JavaDoc("foo:bar=bar2");
962             if (this.isDas()) {
963                 final Object JavaDoc jvmic = Class.forName("com.sun.enterprise.admin.mbeans.jvm.JVMInformationCollector").newInstance();
964                 com.sun.enterprise.admin.common.MBeanServerFactory.getMBeanServer().registerMBean(jvmic, dummy1);
965             }
966             final Object JavaDoc jvmi = Class.forName("com.sun.enterprise.admin.mbeans.jvm.JVMInformation").newInstance();
967             com.sun.enterprise.admin.common.MBeanServerFactory.getMBeanServer().registerMBean(jvmi, dummy2);
968         } catch (final Exception JavaDoc e) {
969             e.printStackTrace();
970         }
971     }
972
973     // createDASDiagnosticMBean
974
private void createDASDiagnosticMBean() {
975         try {
976                 final MBeanServer JavaDoc mbs = getMBeanServer();
977                 ObjectName JavaDoc on = new ObjectName JavaDoc(
978                                 PRIVATE_MBEAN_DOMAIN_NAME + ":" +
979                 "type=DomainDiagnostics,name=" + getInstanceName() + ",category=monitor");
980                         Class JavaDoc cl = Class.forName(DAS_DIAGNOSTIC_MBEAN_CLASS_NAME);
981                 mbs.registerMBean(cl.newInstance(), on);
982         } catch (Throwable JavaDoc t) {
983             t.printStackTrace();
984             sLogger.log(Level.INFO, "core.das_diag__mbean_not_registered", t.getMessage());
985         }
986     }
987     private void initializeMBeanEventListeners() {
988         try {
989             Class JavaDoc c = null; //Class for listener of MBeanElementChange events
990
if (this.isDas()) {
991                 c = Class.forName("com.sun.enterprise.admin.mbeans.custom.InProcessMBeanElementChangeEventListenerImpl");
992             }
993             else {
994                 c = Class.forName("com.sun.enterprise.ee.admin.mbeans.RemoteMBeanElementChangeEventListenerImpl");
995             }
996             final Object JavaDoc o = c.newInstance();
997             AdminEventListenerRegistry.addEventListener(MBeanElementChangeEvent.EVENT_TYPE, (MBeanElementChangeEventListener)o);
998         } catch (final Exception JavaDoc e) {
999             e.printStackTrace(); //ok to squelch
1000
}
1001    }
1002}
1003
Popular Tags