📄 jmsserver.java
字号:
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Exoffice Technologies. For written permission,
* please contact info@exolab.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Exoffice Technologies. Exolab is a registered
* trademark of Exoffice Technologies.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.exolab.org/).
*
* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2000-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
*
* $Id: JmsServer.java,v 1.48.2.1 2004/05/06 11:35:09 tanderson Exp $
*/
package org.exolab.jms.server;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import javax.naming.Context;
import javax.naming.NamingException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.xml.DOMConfigurator;
import org.exolab.core.service.ServiceException;
import org.exolab.core.service.ServiceManager;
import org.exolab.core.util.RmiRegistryService;
import org.exolab.jms.authentication.AuthenticationMgr;
import org.exolab.jms.config.Configuration;
import org.exolab.jms.config.ConfigurationManager;
import org.exolab.jms.config.Connector;
import org.exolab.jms.config.ConnectorHelper;
import org.exolab.jms.config.ConnectorResource;
import org.exolab.jms.config.LoggerConfiguration;
import org.exolab.jms.config.types.SchemeType;
import org.exolab.jms.events.BasicEventManager;
import org.exolab.jms.gc.GarbageCollectionService;
import org.exolab.jms.jndi.JndiServerIfc;
import org.exolab.jms.lease.LeaseManager;
import org.exolab.jms.messagemgr.DestinationManager;
import org.exolab.jms.messagemgr.MessageMgr;
import org.exolab.jms.persistence.DatabaseService;
import org.exolab.jms.scheduler.Scheduler;
import org.exolab.jms.threads.ThreadPoolManager;
import org.exolab.jms.util.CommandLine;
import org.exolab.jms.util.Version;
/**
* This class contains the main line for instantiating the JMS Server. It
* dynamically detemrines, from the configuration information which of the
* servers to implement and then calls the init method on them.
*
* @version $Revision: 1.48.2.1 $ $Date: 2004/05/06 11:35:09 $
* @author <a href="mailto:jima@exoffice.com">Jim Alateras</a>
* @author <a href="mailto:tima@intalio.com">Tim Anderson</a>
* @see ConfigurationManager
*/
public class JmsServer {
/**
* The service manager
*/
protected ServiceManager _services = null;
/**
* The interfaces to this server. One interface is constructed for
* each configured connector.
*/
private JmsServerIfc[] _interfaces = null;
/**
* The JNDI providers, when using embedded JNDI. One server is
* constructed for each configured connector.
*/
private JndiServerIfc[] _jndiInterfaces = null;
/**
* The configuration of this server
*/
private Configuration _config;
/**
* The logger
*/
private static final Log _log = LogFactory.getLog(JmsServer.class);
/**
* Construct a new <code>JmsServer</code>
*
* @param config the server configuration
* @throws ServerException if the server cannot be created
*/
public JmsServer(Configuration config) throws ServerException {
version();
ConfigurationManager.setConfig(config);
_config = config;
}
/**
* Construct a new <code>JmsServer</code>, configured from the specified
* configuration file.
*
* @param file configuration file name
* @throws ServerException if the server cannot be created
*/
public JmsServer(String file) throws ServerException {
version();
try {
// initialise the configuration manager
ConfigurationManager.setConfig(file);
_config = ConfigurationManager.getConfig();
} catch (Exception exception) {
throw new FailedToCreateServerException(
"Failed to read configuration: " + file, exception);
}
}
/**
* Initialise the server
*
* @throws NamingException if administered objects cannot be bound in JNDI
* @throws ServerException if the server cannot be initialised
*/
public void init() throws NamingException, ServerException {
// initialise the logger
LoggerConfiguration log = _config.getLoggerConfiguration();
// @todo - need to do this in main(), to allow pluggable log factories
// when embedding OpenJMS
DOMConfigurator.configure(log.getFile());
// initialise the service manager
_services = ServiceManager.instance();
// initialise the embedded JNDI server if required
if (_config.getServerConfiguration().getEmbeddedJNDI()) {
EmbeddedNameService.getInstance();
}
// create the embedded RMI registry, if it is configured
if (hasConnector(SchemeType.RMI) &&
_config.getRmiConfiguration().getEmbeddedRegistry()) {
createRegistry();
}
// initialise the services, and start them
try {
registerServices();
_services.startAll();
} catch (ServiceException exception) {
throw new ServerException("Failed to start services", exception);
}
// create and bind administered destinations
DestinationManager.instance().registerConfiguredAdministeredDestinations();
Context context = NamingHelper.getInitialContext(_config);
// create the server interfaces
initConnectors(context);
// create the JNDI provider interfaces if required
if (_config.getServerConfiguration().getEmbeddedJNDI()) {
initJNDIConnectors(context);
}
}
/**
* This is the main line for the JMS Server. It processes the command line
* argument, instantiates an instance of the server class and calls the
* init routine on it.
*/
public static void main(String[] args) {
try {
CommandLine cmdline = new CommandLine(args);
boolean helpSet = cmdline.exists("help");
boolean versionSet = cmdline.exists("version");
boolean configSet = cmdline.exists("config");
if (helpSet) {
usage();
} else if (versionSet) {
version();
} else if (!configSet && args.length != 0) {
// invalid argument specified
usage();
} else {
String config = cmdline.value(
"config", getOpenJMSHome() + "/config/openjms.xml");
JmsServer server = new JmsServer(config);
server.init();
}
} catch (Exception exception) {
exception.printStackTrace();
// force termination of any threads
System.exit(-1);
}
}
public static void version() {
System.err.println(Version.TITLE + " " + Version.VERSION);
System.err.println(Version.COPYRIGHT);
System.err.println(Version.VENDOR_URL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -