
org.ow2.jonas.server.Server Maven / Gradle / Ivy
The newest version!
/**
* JOnAS: Java(TM) Open Application Server
* Copyright (C) 1999-2005 Bull S.A.
* Contact: [email protected]
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
*
* --------------------------------------------------------------------------
* $Id:Server.java 10850 2007-07-05 14:16:50Z durieuxp $
* --------------------------------------------------------------------------
*/
package org.ow2.jonas.server;
import java.rmi.RMISecurityManager;
import java.util.ArrayList;
import java.util.List;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import javax.management.remote.JMXServiceURL;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.security.jacc.PolicyContext;
import javax.security.jacc.PolicyContextException;
import javax.security.jacc.PolicyContextHandler;
import javax.transaction.xa.XAException;
import org.ow2.carol.util.configuration.ConfigurationRepository;
import org.ow2.carol.util.configuration.ProtocolConfiguration;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Handler;
import org.objectweb.util.monolog.api.Logger;
import org.objectweb.util.monolog.wrapper.javaLog.MonologFormatter;
import org.ow2.jonas.Version;
import org.ow2.jonas.adm.AdmInterface;
import org.ow2.jonas.jmx.JmxService;
import org.ow2.jonas.lib.bootstrap.JProp;
import org.ow2.jonas.lib.log.LogBuffer;
import org.ow2.jonas.lib.log.LogManagement;
import org.ow2.jonas.lib.management.domain.J2EEDomain;
import org.ow2.jonas.lib.management.javaee.J2eeObjectName;
import org.ow2.jonas.lib.management.reconfig.ReconfigManager;
import org.ow2.jonas.lib.security.jacc.handlers.JPolicyContextHandler;
import org.ow2.jonas.lib.util.I18n;
import org.ow2.jonas.lib.util.JonasObjectName;
import org.ow2.jonas.lib.util.Log;
import org.ow2.jonas.lib.work.WorkCleaner;
import org.ow2.jonas.security.interceptors.jrmp.ctxcheck.Initializer;
import org.ow2.jonas.security.internal.PolicyProvider;
import org.ow2.jonas.service.JonasAlreadyStartedException;
import org.ow2.jonas.service.ServiceException;
import org.ow2.jonas.service.manager.ServiceManager;
import org.ow2.jonas.tm.TransactionService;
/**
* This class implements an JOnAS Server.
* @author Philippe Coq
* @author Philippe Durieux
* @author Jeff Mesnil
* @author Regis Le Brettevillois - Libelis 02/04/25
* @author Sebastien Chassande-Barrioz [email protected] Monolog
* for traces
* @author Adriana Danes 03/01/20: -Highlight configuration properties 03/03/..:
* -Force jmx service startup -Create and register the JOnAS
* configuration MBean. This MBean manages JOnAS persistent
* 04/04/07 - Refactor MBean registration / unregistration
*/
public class Server {
/**
* Property value for the default file
*/
private static final String DEF_LOG_CONFIGFILE = "trace";
/**
* Internationalization
*/
private static I18n i18n = I18n.getInstance(Server.class);
/**
* Property for the configuration log file
*/
private static final String LOG_CONFIGFILE = "jonas.log.configfile";
/**
* Logger
*/
private static Logger logger = null;
/**
* Property for the security propagation
*/
private static final String SECURITY_PROPAGATION = "jonas.security.propagation";
/**
* Property for the Csiv2 propagation
*/
private static final String CSIV2_PROPAGATION = "jonas.csiv2.propagation";
/**
* Property for the security manager
*/
private static final String SECURITY_MANAGER = "jonas.security.manager";
/**
* Property for the security context check.
*/
private static final String SEC_CHECK = "jonas.security.context.check";
/**
* Property for the master
*/
private static final String IS_MASTER = "jonas.master";
/**
* J2EE Application Server Name
*/
private static final String SERVERNAME = "JOnAS";
/**
* Default sleep value
*/
private static final int SLEEP_VALUE = 10000;
/**
* Property for the transaction propagation
*/
private static final String TRANSACTION_PROPAGATION = "jonas.transaction.propagation";
/**
* The Server singleton value
*/
private static Server unique = null;
/**
* ID of the MBean server
*/
private String idMbeanServer = null;
/**
* MBean Server
*/
private MBeanServer mbeanServer = null;
/**
* jmx service
*/
private JmxService jmx = null;
/**
* Server start exception
*/
private Exception startException = null;
/**
* True if I am the master on the domain
*/
private boolean ismaster;
/**
* Get the unique instance. Create it at first call.
* @return unique instance.
*/
public static Server getInstance() {
if (unique == null) {
unique = new Server();
}
return unique;
}
/**
* Server main routine. No args.
* @param args the arguments of the server
* @exception Exception can not start server
*/
public static void main(String[] args) throws Exception {
Server server = null;
// Add Mx4J logger as wrapper (allow to put the right class for debug in
// the log)
// Also add carol class which print traces
System.setProperty(MonologFormatter.WRAPPERS_PROPERTY, "mx4j.log.CommonsLogger,mx4j.log.Logger,java.util.logging.Logger, org.ow2.util.log.JDKLogger, org.apache.juli.logging.DirectJDKLog, org.ow2.carol.util.configuration.TraceCarol");
try {
server = Server.getInstance();
server.start();
} catch (JonasAlreadyStartedException e) {
// if we get this exception this means that
// we are trying to restart the same JOnAS
System.err.println(i18n.getMessage("Server.main.alreadyStarted", SERVERNAME));
// rethrow JonasAlreadyStartedException
throw e;
} catch (Exception e) {
// These are not needed because bootstrap will also print out the
// stack trace
//System.err.println("JOnAS error: " + e);
//e.printStackTrace(System.err);
// We don't use here the trace system.
System.err.println(SERVERNAME + " halting");
try {
if (server != null) {
server.stop();
}
} catch (Exception he) {
System.err.println("Exception starting JOnAS: " + e);
e.printStackTrace(System.err);
System.err.println("Exception during server.stop: " + he.getMessage());
throw he;
}
throw e;
}
}
/**
* Associated Adm object
*/
private static Adm adm = null;
/**
* J2EE Management domain
*/
private String domainName = null;
/**
* J2EEServer associate
*/
private J2EEServer j2EEServer = null;
/**
* J2EEDomain associated
*/
private J2EEDomain j2eeDomain = null;
/**
* File for log configuration
*/
private String logConfigFile;
/**
* JOnAS configuration properties
*/
private JProp props = null;
/**
* Current server name (the server instance name)
*/
private String serverName = null;
/**
* Current server's JONAS_BASE
*/
private String jonasBase = null;
/**
* The associated ServiceManager for JOnAS
*/
private ServiceManager sm = null;
/**
* Protocols list
*/
private String srvProtocols = "";
/**
* Private constructor to force only 1 instance.
* @throws Exception (for example if JProp can't read properties file)
*/
private Server() {
// read the JOnAS properties
props = JProp.getInstance();
// set configuration info into the Log System (monolog)
logConfigFile = props.getValue(LOG_CONFIGFILE, DEF_LOG_CONFIGFILE);
Log.configure(logConfigFile);
// get a logger for server traces
logger = Log.getLogger(Log.JONAS_SERVER_PREFIX);
// create the service manager
sm = ServiceManager.getInstance();
// Check if I am the master
ismaster = new Boolean(props.getValue(IS_MASTER, "false").trim()).booleanValue();
// get JONAS_BASE
jonasBase = props.getValue(JProp.JONAS_BASE);
// prints JVM infos
logger.log(BasicLevel.INFO, jvmInfos());
// called only once for a JVM
PolicyProvider.init();
}
/**
* Gets J2EEDomain
* @return J2EEDomain
*/
public J2EEDomain getJ2EEDomain() {
return j2eeDomain;
}
/**
* Initialize the MBean server
* @throws Exception if MBean server cannot be found/created
*/
private void initMBeanServer() throws Exception {
// Set domain name for creating MBeans
JonasObjectName.setDomain(domainName);
boolean existingMbeanServer = false;
// First, try to find an MBean Server
List mbeanServers = MBeanServerFactory.findMBeanServer(null);
if (mbeanServers.size() > 0) {
mbeanServer = (MBeanServer) mbeanServers.get(0);
existingMbeanServer = true;
} else {
// Need to create an MBean server
mbeanServer = MBeanServerFactory.createMBeanServer(domainName);
}
ObjectName mbeanServerDelegate = new ObjectName("JMImplementation:type=MBeanServerDelegate");
idMbeanServer = (String) mbeanServer.getAttribute(mbeanServerDelegate, "MBeanServerId");
if (existingMbeanServer) {
logger.log(BasicLevel.INFO, "Use an existing MBean server with id '" + idMbeanServer + "'.");
}
}
/**
* Initialize interception and carol
* @param props the JOnAS properties
* @param serverName the name of the server for creating mbeans
* @return list of protocols
* @throws Exception if carol init failed
*/
public String initCarol(JProp props, String serverName) throws Exception {
// Set carol mode in server mode (will use fixed port if set)
System.setProperty("carol.server.mode", "true");
// Intialize Carol
ConfigurationRepository.init(domainName, serverName);
// Initialize Interceptors
String sec = props.getValue(SECURITY_PROPAGATION, "false").trim();
String trans = props.getValue(TRANSACTION_PROPAGATION, "false").trim();
String csiv2 = props.getValue(CSIV2_PROPAGATION, "true").trim();
String secCheck = props.getValue(SEC_CHECK, "false").trim();
if (sec.equals("true")) {
// jrmp interceptors
ConfigurationRepository.addInterceptors("jrmp",
"org.ow2.jonas.security.interceptors.jrmp.SecurityInitializer");
// iiop interceptors flag
ConfigurationRepository.addInterceptors("iiop",
"org.ow2.jonas.security.interceptors.iiop.SecurityInitializer");
// Assert security context ?
if ("true".equals(secCheck)) {
ConfigurationRepository.addInterceptors("jrmp", Initializer.class.getName());
}
}
if (csiv2.equals("true")) {
ConfigurationRepository.addInterceptors("iiop", "org.ow2.jonas.security.iiop.Csiv2Initializer");
}
if (trans.equals("true")) {
// jrmp interceptors flag
ConfigurationRepository.addInterceptors("jrmp", "org.ow2.jotm.jta.rmi.JTAInterceptorInitializer");
// iiop interceptors flag
ConfigurationRepository.addInterceptors("iiop", "org.ow2.jotm.ots.OTSORBInitializer");
}
// Activate HA interceptors if HA service is configured
try {
ServiceManager.getInstance().getService("ha");
ConfigurationRepository.addInterceptors("iiop",
"org.ow2.jonas.lib.ejb21.ha.interceptors.iiop.HAInterceptorInitializer");
} catch (ServiceException se) {
// Discard exception
}
// get Carol configuration
// Should go as Carol MBean
String protocols = "";
String prefix = "rmi/";
String cmiPrefix = "cmi/";
ProtocolConfiguration[] protocolConfigurations = ConfigurationRepository.getConfigurations();
boolean cmiStarted = ConfigurationRepository.isCMIEnabled();
for (ProtocolConfiguration protocolConfiguration : protocolConfigurations) {
if (protocols == "") {
protocols = (cmiStarted && protocolConfiguration.isCmiEnabled() ? cmiPrefix : prefix)
+ protocolConfiguration.getName();
} else {
protocols += "," + (cmiStarted && protocolConfiguration.isCmiEnabled() ? cmiPrefix : prefix)
+ protocolConfiguration.getName();
}
}
return protocols;
}
/**
* Initialize the context handlers (JACC)
* @throws PolicyContextException if handlers can't be registered
*/
private void initJACCPolicyContextHandlers() throws PolicyContextException {
PolicyContextHandler policyContextHandler = new JPolicyContextHandler();
String[] keys = policyContextHandler.getKeys();
for (int k = 0; k < keys.length; k++) {
PolicyContext.registerHandler(keys[k], policyContextHandler, true);
}
}
/**
* Stop the server and stop the JVM (MBean method)
* @throws Exception if the server can't be destroyed
*/
public void kill() throws Exception {
if (adm != null) {
adm.killServer();
}
}
/**
* Start the server
* @throws Exception if server can't be started
*/
public void start() throws Exception {
// Server name
serverName = props.getValue(JProp.JONAS_NAME, JProp.JONAS_DEF_NAME);
// Domain name
domainName = props.getValue(JProp.DOMAIN_NAME, JProp.JONAS_DEF_NAME);
Thread srvThread = new Thread() {
public void run() {
try {
initMBeanServer();
// Initialize Context Interceptors and Carol
srvProtocols = initCarol(props, serverName);
// RMI Security Manager
boolean useSecurityManager = new Boolean(props.getValue(SECURITY_MANAGER, "true").trim()).booleanValue();
if (useSecurityManager) {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
} else {
logger.log(BasicLevel.INFO, "Security manager is not set.");
}
// Initialize Policy Context handlers (JACC)
try {
initJACCPolicyContextHandlers();
} catch (PolicyContextException pce) {
logger.log(BasicLevel.ERROR, "Could not register JOnAS Policy Context Handlers");
throw pce;
}
// First of all, start registry service
sm.startRegistry();
// then, start JMX service (start an MBean server and create RMI
// connector for it registered in JNDI).
sm.startJmx(idMbeanServer);
// jmx service will be necessary below to register some MBeans
jmx = (JmxService) ServiceManager.getInstance().getJmxService();
// Start the cleaner thread (deleting unused working files)
WorkCleaner.getInstance().start();
// Register MBeans
registerMBeans();
// Creates the Adm instance for remote administration
try {
adm = new Adm(props);
} catch (Exception e) {
e.printStackTrace();
throw new Exception("Cannot create Adm : " + e);
}
// start all other services
sm.startServices();
// TM Server or EJB Server ?
boolean isEJB = true;
try {
sm.getEjbService();
} catch (ServiceException se) {
isEJB = false;
}
adm.serverReady(isEJB);
/* Do recovery right before saying JOnAS has started, if the transaction
* service has been configured. This is done at the end of all the service
* startups, since by then the resource adapters loaded by the Resource
* service have been registered with JOTM and JOTM recovery can be done
* in a performant manner against all the resource adapters at once.
*/
TransactionService ts = null;
try {
ts = (TransactionService) sm.getTransactionService();
} catch (ServiceException se) {
}
if (ts != null) {
// Start recovery
try {
ts.startResourceManagerRecovery();
} catch (XAException ex) {
logger.log(BasicLevel.DEBUG, "JOTM startResourceManagerRecovery failed: ", ex);
throw new Exception("Cannot start JOTM resource manager recovery", ex);
}
}
} catch (Throwable e) {
e.printStackTrace();
startException = new Exception(e);
return;
}
System.out.println(i18n.getMessage("Server.start.serverIsReady", serverName, Version.getNumber()));
logger.log(BasicLevel.INFO, i18n.getMessage("Server.start.serverStarted", serverName, srvProtocols));
// Don't stop this thread to keep the server alive.
while (true) {
try {
Thread.sleep(SLEEP_VALUE);
} catch (Exception e) {
return;
}
}
}
};
logger.log(BasicLevel.DEBUG, "Current Thread classloader: " + Thread.currentThread().getContextClassLoader());
srvThread.setName(serverName + " Main");
srvThread.setContextClassLoader(Thread.currentThread().getContextClassLoader());
logger.log(BasicLevel.DEBUG, "New Thread classloader: " + srvThread.getContextClassLoader());
srvThread.start();
// Only exit when JOnAS has completely started
while (adm == null && srvThread.isAlive()) {
Thread.sleep(50);
}
if (adm != null && startException == null) {
while (startException == null && adm.getServerState() != Adm.READY) {
Thread.sleep(250);
}
}
if (startException != null) {
logger.log(BasicLevel.INFO, i18n.getMessage("Server.start.errorStarting", serverName, startException));
throw new Exception("Error in Server start", startException);
}
}
/**
* @return information on JVM currently used
*/
public static String jvmInfos() {
StringBuffer sb = new StringBuffer();
sb.append("JVM used is ");
sb.append(System.getProperty("java.version"));
sb.append(" version of ");
sb.append(System.getProperty("java.vm.name"));
sb.append("-");
sb.append(System.getProperty("java.vm.version"));
sb.append("/");
sb.append(System.getProperty("java.vendor"));
sb.append(" vendor on ");
sb.append(System.getProperty("os.name"));
sb.append(" ");
sb.append(System.getProperty("os.version"));
sb.append("/");
sb.append(System.getProperty("os.arch"));
sb.append(" OS.");
return sb.toString();
}
/**
* Stop the server without stopping the JVM
* @throws Exception if the server can't be stopped
*/
public void stop() throws Exception {
unregisterMBeans();
if (adm != null) {
System.out.println(i18n.getMessage("Server.stop.serverIsStopped", serverName));
logger.log(BasicLevel.INFO, i18n.getMessage("Server.stop.serverStopped", serverName));
adm.stopServer();
}
// Remove internal references to the MBeanServer.
releaseJmxServer();
}
/**
* Remove internal references to the MBeanServer.
*/
protected void releaseJmxServer() {
try {
MBeanServerFactory.releaseMBeanServer(mbeanServer);
} catch (java.lang.IllegalArgumentException ex) {
// The mbeanServer is not found.
logger.log(BasicLevel.ERROR, "Cannot find the MBeanServer" + ex);
}
}
/**
* @return Returns the status of the server started or not.
*/
public static boolean isStarted() {
return unique != null;
}
/**
* check the server state
* @param jonasName JOnAS instance name
* @return true if reachable
*/
private boolean checkServer(String jonasName) {
// Gets reference on Adm object
boolean reachable = false;
String admName = jonasName + Adm.ADMNAME_SUFFIX;
try {
InitialContext initialContext = new InitialContext();
AdmInterface admI = (AdmInterface) PortableRemoteObject.narrow(initialContext.lookup(admName), AdmInterface.class);
int state = admI.getServerState();
reachable = (state == Adm.READY);
} catch (Exception e) {
reachable = false;
}
return reachable;
}
/**
* @return true if the discovery service is present in the services list
*/
private boolean checkDiscoveryEnabled() {
boolean discoveryEnabled = false;
String[] services = JProp.getInstance().getValueAsArray("jonas.services");
for (int i = 0; i < services.length; i++) {
if ("discovery".equals(services[i])) {
discoveryEnabled = true;
}
}
return discoveryEnabled;
}
/**
* Create and register the following JSR77 Standard MBeans:
* - J2EEDomain
* - J2EEServer
* - JVM.
* Create the following JOnAS MBeans:
* - ReconfigManager (domainName:type=management,name=reconfigManager)
* - LogManagement (domainName:type=service,name=log,fname=fileName where
* fileName is the name of the JOnAS logging properties file, usually trace).
*/
private void registerMBeans() {
// Create and register the J2EEDomain MBean for the domain management
String domainON = J2eeObjectName.J2EEDomainName(domainName);
try {
j2eeDomain = new J2EEDomain(domainON);
j2eeDomain.setJmxService(jmx);
jmx.registerModelMBean(j2eeDomain, domainON);
} catch (Exception e) {
logger.log(BasicLevel.WARN, "Could not register J2EEDomain MBean: " + e);
}
// If this server is a master, the J2EEDomain MBean
// is set master, which enables domain monitoring
if (checkDiscoveryEnabled() && ismaster) {
j2eeDomain.setMaster(true, serverName);
} else {
j2eeDomain.setMaster(false, serverName);
}
// Create and register J2EEServer MBean
String serverON = J2eeObjectName.J2EEServerName(domainName, serverName);
ArrayList urls = null;
try {
// Get the VERSIONS file content
String versions = null;
try {
JProp.getInstance(JProp.JONAS_VERSIONS).getVersionFile();
} catch (RuntimeException e) {
logger.log(BasicLevel.WARN, "Cannot get VERSIONS file");
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, e);
}
}
j2EEServer = new J2EEServer(serverON, unique, serverName, Version.getNumber(), Version.VENDOR,
srvProtocols, versions);
j2EEServer.setJonasBase(jonasBase);
jmx.registerModelMBean(j2EEServer, serverON);
//Get the urls for the server to be added into the J2EEDomain mbean.
try {
JmxService jmxService = ((JmxService) sm.getJmxService());
JMXServiceURL[] connectorServerURLs = jmxService.getConnectorServerURLs();
urls = new ArrayList();
for (int i = 0; i < connectorServerURLs.length; i++) {
// The connectorServerURLs may contain null
// if the list of protocols in Carol contain
// other protocols than the standard ones (JRMP,
// IIOP, CMI)
if (connectorServerURLs[i] != null) {
urls.add(connectorServerURLs[i].toString());
}
}
} catch (ServiceException e) {
// if there was a problem getting the urls
urls = null;
}
// Set relation J2EEDomain -> J2EEServer
j2eeDomain.setMyJ2EEServerOn(serverON);
} catch (Exception e) {
logger.log(BasicLevel.WARN, "Could not create J2EEServer MBean : " + e.getMessage(), e);
}
// Create the MBean for the corresponding JVM
String jvmON = J2eeObjectName.JVMName(domainName, serverName, serverName);
try {
JavaVm oJvm = new JavaVm(jvmON, props);
jmx.registerModelMBean(oJvm, jvmON);
// Update J2EEServer MBean
j2EEServer.addJavaVM(jvmON);
} catch (Exception e) {
logger.log(BasicLevel.WARN, "Could not create JVM MBean : " + e.getMessage(), e);
}
// Add local server to the J2EEDomain. Another effect is to create the ServerProxy
// for the local (current) server.
j2eeDomain.addLocalServer(serverName, urls);
// Create and register a MBean allowing server reconfiguration
ReconfigManager reconfigManager = new ReconfigManager(props.getConfigFileEnv(), domainName, mbeanServer);
try {
jmx.registerMBean(reconfigManager, JonasObjectName.serverConfig(domainName));
} catch (Exception e) {
logger.log(BasicLevel.WARN, "Could not register ReconfigManager MBean: " + e);
}
// Create and register a MBean for the logging service management
LogManagement logMBean = LogManagement.getInstance();
try {
jmx.registerMBean(logMBean, JonasObjectName.logService(domainName, logConfigFile));
} catch (Exception e) {
logger.log(BasicLevel.WARN, "Could not create J2EEServer MBean : " + e.getMessage(), e);
}
// Create and register a MBean for viwing log message if there is a jmx handler in Monolog
Handler jmxHandler = Log.getJmxHandler();
if (jmxHandler != null) {
logger.log(BasicLevel.INFO, "Monolog JmxHandler present");
// Create LogBuffer MBean
LogBuffer logBufMBean = new LogBuffer("logBuffer");
String logBufName = jmxHandler.getName();
try {
jmx.registerMBean(logBufMBean, JonasObjectName.logBuffer(domainName, logBufName));
} catch (Exception e) {
logger.log(BasicLevel.WARN, "Could not create LogBuffer MBean : " + e.getMessage(), e);
}
}
}
/**
* Unregister the following JSR77 Standard MBeans:
* - J2EEDomain
* - J2EEServer
* - JVM.
* Unregister the following JOnAS MBeans:
* - ReconfigManager (domainName:type=management,name=reconfigManager)
* - LogManagement (domainName:type=service,name=log,fname=fileName where
* fileName is the name of the JOnAS logging properties file, usually trace).
*/
private void unregisterMBeans() {
// Unregister the J2EEDomain MBean
ObjectName on = J2eeObjectName.J2EEDomain(domainName);
jmx.unregisterModelMBean(on);
// Unregister the J2EEServer MBean
on = J2eeObjectName.J2EEServer(domainName, serverName);
jmx.unregisterModelMBean(on);
// Unregister the JVM MBean
on = J2eeObjectName.JVM(domainName, serverName, serverName);
jmx.unregisterModelMBean(on);
// Unregister the ReconfigManager MBean
on = JonasObjectName.serverConfig(domainName);
jmx.unregisterMBean(on);
// Unregister the logging service MBean
on = JonasObjectName.logService(domainName, logConfigFile);
jmx.unregisterMBean(on);
}
/**
* Returns the value of the related property. With default values.
* @param key the search key
* @param defaultVal if the key is not found return this default value
* @return property value
*/
public String getSystemProperty(String key, String defaultVal) {
return props.getValue(key, defaultVal);
}
/**
* Returns the value of the related property.
* The method returns null if the property is not found.
* @param key the wanted key
* @return property value, null if not exist
*/
public String getSystemProperty(String key) {
String ret = props.getValue(key);
if (ret == null) {
ret = System.getProperty(key);
}
if (ret == null && key.equals("jonas.root")) {
//usefull for windows users. Cause jonas.root should not be current user var but system var
//then jonas.base has been set to jonas.root when jonas started.
ret = System.getProperty("jonas.base");
}
logger.log(BasicLevel.DEBUG, "Get property : "+key+" retrieved "+ret);
return ret;
}
/**
* Returns the values of the related properties.
* The property value is set to Null if not found.
* @param key Collection of keys to find
* @return Collection of values for given keys, in the same order.
*/
public List getSystemProperties(final List keys) {
List ret = new ArrayList();
String prop = null;
for (int i = 0; i < keys.size(); i++) {
prop = props.getValue(keys.get(i).toString());
if (prop == null) {
prop = System.getProperty(keys.get(i).toString());
}
if (prop == null && keys.get(i).toString().equals("jonas.root")) {
//usefull for windows users. Cause jonas.root should not be current user var but system var
//then jonas.base has been set to jonas.root when jonas started.
prop = System.getProperty("jonas.base");
}
ret.add(prop);
}
return ret;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy