001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: *
022: * --------------------------------------------------------------------------
023: * $Id: Server.java 10039 2007-03-01 13:46:10Z pelletib $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.server;
026:
027: import java.rmi.RMISecurityManager;
028: import java.util.ArrayList;
029: import java.util.List;
030:
031: import javax.management.MBeanServer;
032: import javax.management.MBeanServerFactory;
033: import javax.management.ObjectName;
034: import javax.management.modelmbean.ModelMBean;
035: import javax.management.remote.JMXServiceURL;
036: import javax.naming.InitialContext;
037: import javax.rmi.PortableRemoteObject;
038: import javax.security.jacc.PolicyContext;
039: import javax.security.jacc.PolicyContextException;
040: import javax.security.jacc.PolicyContextHandler;
041:
042: import org.apache.commons.modeler.ManagedBean;
043: import org.apache.commons.modeler.Registry;
044:
045: import org.objectweb.carol.util.configuration.ConfigurationRepository;
046: import org.objectweb.carol.util.configuration.ProtocolConfiguration;
047:
048: import org.objectweb.jonas_lib.I18n;
049: import org.objectweb.jonas_lib.deployment.work.WorkCleaner;
050: import org.objectweb.jonas_lib.version.Version;
051:
052: import org.objectweb.jonas.adm.Adm;
053: import org.objectweb.jonas.adm.AdmInterface;
054: import org.objectweb.jonas.common.JProp;
055: import org.objectweb.jonas.common.Log;
056: import org.objectweb.jonas.common.LogManagement;
057: import org.objectweb.jonas.jmx.J2eeObjectName;
058: import org.objectweb.jonas.jmx.JmxService;
059: import org.objectweb.jonas.jmx.JonasObjectName;
060: import org.objectweb.jonas.management.JonasMBeanTools;
061: import org.objectweb.jonas.management.ReconfigManager;
062: import org.objectweb.jonas.management.j2eemanagement.J2EEDomain;
063: import org.objectweb.jonas.security.PolicyProvider;
064: import org.objectweb.jonas.security.interceptors.jrmp.ctxcheck.Initializer;
065: import org.objectweb.jonas.security.jacc.JPolicyContextHandler;
066: import org.objectweb.jonas.service.JonasAlreadyStartedException;
067: import org.objectweb.jonas.service.ServiceException;
068: import org.objectweb.jonas.service.ServiceManager;
069: import org.objectweb.jotm.Current;
070:
071: import org.objectweb.util.monolog.api.BasicLevel;
072: import org.objectweb.util.monolog.api.Logger;
073: import org.objectweb.util.monolog.wrapper.javaLog.MonologFormatter;
074:
075: /**
076: * This class implements an JOnAS Server.
077: * @author Philippe Coq
078: * @author Philippe Durieux
079: * @author Jeff Mesnil
080: * @author Regis Le Brettevillois - Libelis / JOnAS team - evidian Service as
081: * org.objectweb.jonas.service.Service 02/04/25
082: * @author Sebastien Chassande-Barrioz sebastien.chassande@inrialpes.fr Monolog
083: * for traces
084: * @author Adriana Danes 03/01/20: -Highlight configuration properties 03/03/..:
085: * -Force jmx service startup -Create and register the JonAS
086: * configuration MBean. This MBean manages JOnAS persistent
087: */
088: public class Server {
089:
090: /**
091: * Property value for the default file
092: */
093: private static final String DEF_LOG_CONFIGFILE = "trace";
094:
095: /**
096: * Internationalization
097: */
098: private static I18n i18n = I18n.getInstance(Server.class);
099:
100: /**
101: * Property for the configuration log file
102: */
103: private static final String LOG_CONFIGFILE = "jonas.log.configfile";
104:
105: /**
106: * Logger
107: */
108: private static Logger logger = null;
109:
110: /**
111: * Property for the security propagation
112: */
113: private static final String SECURITY_PROPAGATION = "jonas.security.propagation";
114:
115: /**
116: * Property for the Csiv2 propagation
117: */
118: private static final String CSIV2_PROPAGATION = "jonas.csiv2.propagation";
119:
120: /**
121: * Property for the security manager
122: */
123: private static final String SECURITY_MANAGER = "jonas.security.manager";
124:
125: /**
126: * Property for the security context check.
127: */
128: private static final String SEC_CHECK = "jonas.security.context.check";
129:
130: /**
131: * Property for the master
132: */
133: private static final String IS_MASTER = "jonas.service.discovery.master";
134:
135: /**
136: * J2EE Application Server Name
137: */
138: private static final String SERVERNAME = "JOnAS";
139:
140: /**
141: * Default sleep value
142: */
143: private static final int SLEEP_VALUE = 10000;
144:
145: /**
146: * Property for the transaction propagation
147: */
148: private static final String TRANSACTION_PROPAGATION = "jonas.transaction.propagation";
149:
150: /**
151: * The Server singleton value
152: */
153: private static Server unique = null;
154:
155: /**
156: * ID of the MBean server
157: */
158: private String idMbeanServer = null;
159:
160: /**
161: * MBean Server
162: */
163: private MBeanServer mbeanServer = null;
164:
165: /**
166: * Server start exception
167: */
168: private Exception startException = null;
169:
170: /**
171: * True if I am the master on the domain
172: */
173: private boolean ismaster;
174:
175: /**
176: * Get the unique instance. Create it at first call.
177: * @return unique instance.
178: */
179: public static Server getInstance() {
180: if (unique == null) {
181: unique = new Server();
182: }
183: return unique;
184: }
185:
186: /**
187: * Server main routine. No args.
188: * @param args the arguments of the server
189: * @exception Exception can not start server
190: */
191: public static void main(String[] args) throws Exception {
192: Server server = null;
193:
194: // Add Mx4J logger as wrapper (allow to put the right class for debug in
195: // the log)
196: // Also add carol class which print traces
197: System
198: .setProperty(
199: MonologFormatter.WRAPPERS_PROPERTY,
200: "mx4j.log.CommonsLogger,mx4j.log.Logger,org.objectweb.easybeans.log.JDKLogger,org.objectweb.carol.util.configuration.TraceCarol,org.objectweb.carol.cmi.configuration.TraceCmi");
201:
202: try {
203: server = Server.getInstance();
204: server.start();
205: } catch (JonasAlreadyStartedException e) {
206: // if we get this exception this means that
207: // we are trying to restart the same JOnAS
208: System.err.println(i18n.getMessage(
209: "Server.main.alreadyStarted", SERVERNAME));
210: // rethrow JonasAlreadyStartedException
211: throw e;
212: } catch (Exception e) {
213: // These are not needed because bootstrap will also print out the
214: // stack trace
215: //System.err.println("JOnAS error: " + e);
216: //e.printStackTrace(System.err);
217:
218: // We don't use here the trace system.
219: System.err.println(SERVERNAME + " halting");
220: try {
221: if (server != null) {
222: server.stop();
223: }
224: } catch (Exception he) {
225: System.err.println("Exception starting JOnAS: " + e);
226: e.printStackTrace(System.err);
227: System.err.println("Exception during server.stop: "
228: + he.getMessage());
229: throw he;
230: }
231: throw e;
232: }
233: }
234:
235: /**
236: * Associated Adm object
237: */
238: private static Adm adm = null;
239:
240: /**
241: * J2EE Management domain
242: */
243: private String domainName = null;
244:
245: /**
246: * J2EEServer associate
247: */
248: private J2EEServer j2EEServer = null;
249:
250: /**
251: * J2EEDomain associated
252: */
253: private J2EEDomain j2eeDomain = null;
254:
255: /**
256: * File for log configuration
257: */
258: private String logConfigFile;
259:
260: /**
261: * JOnAS configuration properties
262: */
263: private JProp props = null;
264:
265: /**
266: * Current server name (the server instance name)
267: */
268: private String serverName = null;
269:
270: /**
271: * Current server's JONAS_BASE
272: */
273: private String jonasBase = null;
274: /**
275: * The associated ServiceManager for JOnAS
276: */
277: private ServiceManager sm = null;
278:
279: /**
280: * Protocols list
281: */
282: private String srvProtocols = "";
283:
284: /**
285: * Private constructor to force only 1 instance.
286: * @throws Exception (for example if JProp can't read properties file)
287: */
288: private Server() {
289: // read the JOnAS properties
290: props = JProp.getInstance();
291:
292: // set configuration info into the Log System (monolog)
293: logConfigFile = props.getValue(LOG_CONFIGFILE,
294: DEF_LOG_CONFIGFILE);
295: Log.configure(logConfigFile);
296:
297: // get a logger for server traces
298: logger = Log.getLogger(Log.JONAS_SERVER_PREFIX);
299:
300: // create the service manager
301: sm = ServiceManager.getInstance();
302:
303: // Check if I am the master
304: ismaster = new Boolean(props.getValue(IS_MASTER, "false")
305: .trim()).booleanValue();
306:
307: // get JONAS_BASE
308: jonasBase = props.getValue(JProp.JONAS_BASE);
309:
310: // prints JVM infos
311: logger.log(BasicLevel.INFO, jvmInfos());
312:
313: // called only once for a JVM
314: PolicyProvider.init();
315:
316: }
317:
318: /**
319: * Gets J2EEDomain
320: * @return J2EEDomain
321: */
322: public J2EEDomain getJ2EEDomain() {
323: return j2eeDomain;
324: }
325:
326: /**
327: * Gets J2EEServer.
328: * @return J2EEServer
329: */
330: public J2EEServer getJ2EEServer() {
331: return j2EEServer;
332: }
333:
334: /**
335: * Initialize the MBean server
336: * @throws Exception if MBean server cannot be found/created
337: */
338: private void initMBeanServer() throws Exception {
339:
340: // Set domain name for creating MBeans
341: JonasObjectName.setDomain(domainName);
342:
343: boolean existingMbeanServer = false;
344: // First, try to find an MBean Server
345: List mbeanServers = MBeanServerFactory.findMBeanServer(null);
346: if (mbeanServers.size() > 0) {
347: mbeanServer = (MBeanServer) mbeanServers.get(0);
348: existingMbeanServer = true;
349: } else {
350: // Need to create an MBean server
351: mbeanServer = MBeanServerFactory
352: .createMBeanServer(domainName);
353: }
354:
355: ObjectName mbeanServerDelegate = new ObjectName(
356: "JMImplementation:type=MBeanServerDelegate");
357: idMbeanServer = (String) mbeanServer.getAttribute(
358: mbeanServerDelegate, "MBeanServerId");
359: if (existingMbeanServer) {
360: logger.log(BasicLevel.INFO,
361: "Use an existing MBean server with id '"
362: + idMbeanServer + "'.");
363: }
364: }
365:
366: /**
367: * Initialize interception and carol
368: * @param props the JOnAS properties
369: * @param serverName the name of the server for creating mbeans
370: * @return list of protocols
371: * @throws Exception if carol init failed
372: */
373: public String initCarol(JProp props, String serverName)
374: throws Exception {
375:
376: // Intialize Carol
377: ConfigurationRepository.init(domainName, serverName);
378:
379: // Initialize Interceptors
380: String sec = props.getValue(SECURITY_PROPAGATION, "false")
381: .trim();
382: String trans = props.getValue(TRANSACTION_PROPAGATION, "false")
383: .trim();
384: String csiv2 = props.getValue(CSIV2_PROPAGATION, "true").trim();
385: String secCheck = props.getValue(SEC_CHECK, "false").trim();
386:
387: if (sec.equals("true")) {
388: // jrmp interceptors
389: ConfigurationRepository
390: .addInterceptors("jrmp",
391: "org.objectweb.jonas.security.interceptors.jrmp.SecurityInitializer");
392: // cmi interceptors
393: ConfigurationRepository
394: .addInterceptors("cmi",
395: "org.objectweb.jonas.security.interceptors.jrmp.SecurityInitializer");
396: // iiop interceptors flag
397: ConfigurationRepository
398: .addInterceptors("iiop",
399: "org.objectweb.jonas.security.interceptors.iiop.SecurityInitializer");
400:
401: // Assert security context ?
402: if ("true".equals(secCheck)) {
403: ConfigurationRepository.addInterceptors("jrmp",
404: Initializer.class.getName());
405: ConfigurationRepository.addInterceptors("cmi",
406: Initializer.class.getName());
407: }
408:
409: }
410:
411: if (csiv2.equals("true")) {
412: ConfigurationRepository
413: .addInterceptors("iiop",
414: "org.objectweb.jonas.security.iiop.Csiv2Initializer");
415: }
416:
417: if (trans.equals("true")) {
418: // jrmp interceptors flag
419: ConfigurationRepository
420: .addInterceptors("jrmp",
421: "org.objectweb.jotm.jta.rmi.JTAInterceptorInitializer");
422: // jrmp interceptors flag
423: ConfigurationRepository
424: .addInterceptors("cmi",
425: "org.objectweb.jotm.jta.rmi.JTAInterceptorInitializer");
426: // iiop interceptors flag
427: ConfigurationRepository.addInterceptors("iiop",
428: "org.objectweb.jotm.ots.OTSORBInitializer");
429: }
430:
431: // Activate HA interceptors if HA service is configured
432: try {
433: ServiceManager.getInstance().getService("ha");
434: ConfigurationRepository
435: .addInterceptors("cmi",
436: "org.objectweb.jonas.ha.interceptor.HAInterceptorInitializer");
437: } catch (ServiceException se) {
438: // Discard exception
439: }
440:
441: // Set carol mode in server mode (will use fixed port if set)
442: System.setProperty("carol.server.mode", "true");
443:
444: // get Carol configuration
445: // Should go as Carol MBean
446: String protocols = "";
447: String prefix = "rmi/";
448: ProtocolConfiguration[] protocolConfigurations = ConfigurationRepository
449: .getConfigurations();
450: for (int c = 0; c < protocolConfigurations.length; c++) {
451: if (protocols == "") {
452: protocols = prefix
453: + protocolConfigurations[c].getName();
454: } else {
455: protocols += "," + prefix
456: + protocolConfigurations[c].getName();
457: }
458: }
459: return protocols;
460: }
461:
462: /**
463: * Initialize the context handlers (JACC)
464: * @throws PolicyContextException if handlers can't be registered
465: */
466: private void initJACCPolicyContextHandlers()
467: throws PolicyContextException {
468: PolicyContextHandler policyContextHandler = new JPolicyContextHandler();
469: String[] keys = policyContextHandler.getKeys();
470: for (int k = 0; k < keys.length; k++) {
471: PolicyContext.registerHandler(keys[k],
472: policyContextHandler, true);
473: }
474: }
475:
476: /**
477: * Stop the server and stop the JVM (MBean method)
478: * @throws Exception if the server can't be destroyed
479: */
480: public void kill() throws Exception {
481: if (adm != null) {
482: adm.killServer();
483: }
484: }
485:
486: /**
487: * Start the server
488: * @throws Exception if server can't be started
489: */
490: public void start() throws Exception {
491:
492: // Server name
493: serverName = props.getValue(JProp.JONAS_NAME,
494: JProp.JONAS_DEF_NAME);
495:
496: // Domain name
497: domainName = props.getValue(JProp.DOMAIN_NAME,
498: JProp.JONAS_DEF_NAME);
499:
500: Thread srvThread = new Thread() {
501: public void run() {
502: try {
503:
504: initMBeanServer();
505:
506: // Initialize Context Interceptors and Carol
507: srvProtocols = initCarol(props, serverName);
508:
509: // RMI Security Manager
510: boolean useSecurityManager = new Boolean(props
511: .getValue(SECURITY_MANAGER, "true").trim())
512: .booleanValue();
513:
514: if (useSecurityManager) {
515: if (System.getSecurityManager() == null) {
516: System
517: .setSecurityManager(new RMISecurityManager());
518: }
519: } else {
520: logger.log(BasicLevel.INFO,
521: "Security manager is not set.");
522: }
523:
524: // Initialize Policy Context handlers (JACC)
525: try {
526: initJACCPolicyContextHandlers();
527: } catch (PolicyContextException pce) {
528: logger
529: .log(BasicLevel.ERROR,
530: "Could not register JOnAS Policy Context Handlers");
531: throw pce;
532: }
533:
534: // First of all, start registry service
535: sm.startRegistry();
536:
537: // then, start JMX service (start an MBean server and create RMI
538: // connector for it registered in JNDI)
539: sm.startJmx(idMbeanServer);
540:
541: // start the cleaner thread (deleting unused working files)
542: WorkCleaner.getInstance().start();
543:
544: // Get the MBean register (and load mbeans-descriptors)
545: Registry oRegistry = JonasMBeanTools.getRegistry();
546:
547: // Create and register a J2EE MBean for the domain management
548: ObjectName domainOn = null;
549: try {
550: // Create a JMX object name for the Domain MBean
551: domainOn = J2eeObjectName
552: .J2EEDomain(domainName);
553: j2eeDomain = new J2EEDomain(domainOn.toString());
554: ManagedBean oManaged = oRegistry
555: .findManagedBean("J2EEDomain");
556: ModelMBean oMBean = oManaged
557: .createMBean(j2eeDomain);
558: mbeanServer.registerMBean(oMBean, domainOn);
559: } catch (javax.management.InstanceAlreadyExistsException ae) {
560: // should never occur
561: logger.log(BasicLevel.ERROR, ae);
562: } catch (Exception e) {
563: logger.log(BasicLevel.WARN,
564: "Could not register J2EEDomain MBean");
565: }
566:
567: // If this server is a master, the Domain MBean
568: // is set master, which enables domain monitoring
569: if (checkDiscoveryEnabled() && ismaster) {
570: j2eeDomain.setMaster();
571: }
572:
573: // Create and register necessary MBeans for the server management
574: ObjectName serverOn = null;
575: ArrayList urls = null;
576: try {
577: // Create and register a MBean allowing server reconfiguration
578: ReconfigManager reconfigManagerMBean = new ReconfigManager(
579: props.getConfigFileEnv(), mbeanServer);
580: mbeanServer.registerMBean(reconfigManagerMBean,
581: JonasObjectName.serverConfig());
582:
583: // Create and register a MBean allowing the JOnAS server management
584: serverOn = J2eeObjectName.J2EEServer(
585: domainName, serverName);
586: // Get the VERSIONS file content
587: String versions = JProp.getInstance("VERSIONS")
588: .getVersionFile();
589: j2EEServer = new J2EEServer(
590: serverOn.toString(), unique,
591: serverName, Version.getNumber(),
592: Version.VENDOR, srvProtocols, versions);
593: j2EEServer.setJonasBase(jonasBase);
594: ManagedBean oManaged = oRegistry
595: .findManagedBean("J2EEServer");
596: ModelMBean oMBean = oManaged
597: .createMBean(j2EEServer);
598: mbeanServer.registerMBean(oMBean, serverOn);
599:
600: //Get the urls for the server to be added into the J2EEDomain mbean.
601: try {
602: JmxService jmxService = ((JmxService) sm
603: .getJmxService());
604: JMXServiceURL[] connectorServerURLs = jmxService
605: .getConnectorServerURLs();
606: urls = new ArrayList();
607: for (int i = 0; i < connectorServerURLs.length; i++) {
608: // The connectorServerURLs may contain null
609: // if the list of protocols in Carol contain
610: // other protocols than the standard ones (JRMP, JEREMIE,
611: // IIOP, CMI)
612: if (connectorServerURLs[i] != null) {
613: urls.add(connectorServerURLs[i]
614: .toString());
615: }
616: }
617: } catch (ServiceException e) {
618: // if there was a problem getting the urls
619: urls = null;
620: }
621: // Add local server to the J2EEDomain
622: j2eeDomain.addLocalServer(j2EEServer, urls);
623:
624: // Create and register a MBean for the logging service management
625: LogManagement logMBean = LogManagement
626: .getInstance();
627: mbeanServer.registerMBean(logMBean,
628: JonasObjectName
629: .logService(logConfigFile));
630: } catch (Exception e) {
631: logger.log(BasicLevel.WARN,
632: "Could not create J2EEServer MBean : "
633: + e.getMessage(), e);
634: }
635:
636: // Create the MBean for the corresponding JVM
637: ObjectName onJvm = null;
638: try {
639: onJvm = J2eeObjectName.JVM(domainName,
640: serverName, serverName);
641: ManagedBean oManaged = oRegistry
642: .findManagedBean("JVM");
643: JavaVm oJvm = new JavaVm(onJvm.toString(),
644: props);
645: ModelMBean oMBean = oManaged.createMBean(oJvm);
646: mbeanServer.registerMBean(oMBean, onJvm);
647: // Update J2EEServer MBean
648: j2EEServer.addJavaVM(onJvm.toString());
649: } catch (Exception e) {
650: logger.log(BasicLevel.WARN,
651: "Could not create JVM MBean : "
652: + e.getMessage(), e);
653: }
654:
655: // Creates the Adm instance for remote administration
656: try {
657: adm = new Adm(props);
658: } catch (Exception e) {
659: e.printStackTrace();
660: throw new Exception("Cannot create Adm : " + e);
661: }
662:
663: // start all other services
664: sm.startServices();
665:
666: // Add local server to the J2EEDomain
667: j2eeDomain.setLocalServerRunning();
668:
669: // TM Server or EJB Server ?
670: boolean isEJB = true;
671: try {
672: sm.getEjbService();
673: } catch (ServiceException se) {
674: isEJB = false;
675: }
676: adm.serverReady(isEJB);
677:
678: /* Do recovery right before saying JOnAS has started, if the transaction
679: * service has been configured. This is done at the end of all the service
680: * startups, since by then the resource adapters loaded by the Resource
681: * service have been registered with JOTM and JOTM recovery can be done
682: * in a performant manner against all the resource adapters at once.
683: */
684: boolean isTM = true;
685: try {
686: sm.getTransactionService();
687: } catch (ServiceException se) {
688: isTM = false;
689: }
690: if (isTM) {
691: // Start recovery
692: try {
693: Current.getTransactionRecovery()
694: .startResourceManagerRecovery();
695: } catch (Exception ex) {
696: if (logger.isLoggable(BasicLevel.DEBUG)) {
697: logger
698: .log(
699: BasicLevel.DEBUG,
700: "JOTM startResourceManagerRecovery failed: ",
701: ex);
702: }
703: throw new Exception(
704: "Cannot start JOTM resource manager recovery",
705: ex);
706: }
707: }
708: } catch (Throwable e) {
709: startException = new Exception(e);
710: return;
711: }
712:
713: System.out.println(i18n.getMessage(
714: "Server.start.serverIsReady", serverName,
715: Version.getNumber()));
716: logger.log(BasicLevel.INFO, i18n.getMessage(
717: "Server.start.serverStarted", serverName,
718: srvProtocols));
719:
720: // Don't stop this thread to keep the server alive.
721:
722: while (true) {
723: try {
724: Thread.sleep(SLEEP_VALUE);
725: } catch (Exception e) {
726: return;
727: }
728: }
729: }
730: };
731: logger.log(BasicLevel.DEBUG, "Current Thread classloader: "
732: + Thread.currentThread().getContextClassLoader());
733: srvThread.setName(serverName + " Main");
734: srvThread.setContextClassLoader(Thread.currentThread()
735: .getContextClassLoader());
736: logger.log(BasicLevel.DEBUG, "New Thread classloader: "
737: + srvThread.getContextClassLoader());
738: srvThread.start();
739:
740: // Only exit when JOnAS has completely started
741: while (adm == null && srvThread.isAlive()) {
742: Thread.sleep(50);
743: }
744:
745: if (adm != null && startException == null) {
746: while (startException == null
747: && adm.getServerState() != Adm.READY) {
748: Thread.sleep(250);
749: }
750: }
751: if (startException != null) {
752: logger.log(BasicLevel.INFO, i18n.getMessage(
753: "Server.start.errorStarting", serverName,
754: startException));
755: throw new Exception("Error in Server start", startException);
756: }
757: }
758:
759: /**
760: * @return information on JVM currently used
761: */
762: public static String jvmInfos() {
763: StringBuffer sb = new StringBuffer();
764: sb.append("JVM used is ");
765: sb.append(System.getProperty("java.version"));
766: sb.append(" version of ");
767: sb.append(System.getProperty("java.vm.name"));
768: sb.append("-");
769: sb.append(System.getProperty("java.vm.version"));
770: sb.append("/");
771: sb.append(System.getProperty("java.vendor"));
772: sb.append(" vendor on ");
773: sb.append(System.getProperty("os.name"));
774: sb.append(" ");
775: sb.append(System.getProperty("os.version"));
776: sb.append("/");
777: sb.append(System.getProperty("os.arch"));
778: sb.append(" OS.");
779: return sb.toString();
780: }
781:
782: /**
783: * Stop the server without stopping the JVM
784: * @throws Exception if the server can't be stopped
785: */
786: public void stop() throws Exception {
787: if (adm != null) {
788: System.out.println(i18n.getMessage(
789: "Server.stop.serverIsStopped", serverName));
790: logger.log(BasicLevel.INFO, i18n.getMessage(
791: "Server.stop.serverStopped", serverName));
792: adm.stopServer();
793: }
794: }
795:
796: /**
797: * @return Returns the status of the server started or not.
798: */
799: public static boolean isStarted() {
800: return unique != null;
801: }
802:
803: /**
804: * check the server state
805: * @param jonasName JOnAS instance name
806: * @return true if reachable
807: */
808: private boolean checkServer(String jonasName) {
809:
810: // Gets reference on Adm object
811: boolean reachable = false;
812: String admName = jonasName + Adm.ADMNAME_SUFFIX;
813: try {
814: InitialContext initialContext = new InitialContext();
815: AdmInterface admI = (AdmInterface) PortableRemoteObject
816: .narrow(initialContext.lookup(admName),
817: AdmInterface.class);
818: int state = admI.getServerState();
819: reachable = (state == Adm.READY);
820: } catch (Exception e) {
821: reachable = false;
822: }
823: return reachable;
824: }
825:
826: /**
827: * @return true if the discovery service is present in the services list
828: */
829: private boolean checkDiscoveryEnabled() {
830: boolean discoveryEnabled = false;
831: String[] services = JProp.getInstance().getValueAsArray(
832: "jonas.services");
833: for (int i = 0; i < services.length; i++) {
834: if ("discovery".equals(services[i])) {
835: discoveryEnabled = true;
836: }
837: }
838: return discoveryEnabled;
839: }
840: }
|