📄 openjmsprovider.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 2001,2003 (C) Exoffice Technologies Inc. All Rights Reserved.
*
* $Id: OpenJMSProvider.java,v 1.7 2003/06/15 22:51:59 tanderson Exp $
*
* Date Author Changes
* 09/06/2001 jima Created from Tim Andersons work on Compliance
* Test Suite.
*/
package org.exolab.testharness.jms.util;
import javax.jms.JMSException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.exolab.jms.config.Configuration;
import org.exolab.jms.config.ConfigurationManager;
import org.exolab.jms.config.Connector;
import org.exolab.jms.config.types.SchemeType;
/**
* This class enables OpenJMS test cases to be run against different OpenJMS
* configurations.
* <p>
* The {@link #setPath} method must be invoked prior to {@link #initialise}
* being invoked.
*
* @version $Revision: 1.7 $ $Date: 2003/06/15 22:51:59 $
* @author <a href="mailto:tima@intalio.com">Tim Anderson</a>
*/
public class OpenJMSProvider {
/**
* The configuration file path
*/
private String _path = null;
/**
* The server adapter, used for starting and stopping the OpenJMS server
*/
private ServerAdapter _server = null;
/**
* The logger
*/
private static final Log _log = LogFactory.getLog(OpenJMSProvider.class);
/**
* Construct an instance of the interface to the OpenJMS provider
*/
public OpenJMSProvider() {
}
/**
* Sets the configuration file path. This must be done prior to invoking
* {@link #initialise}
*
* @param path the configuration file path
*/
public void setPath(String path) {
_path = path;
}
/**
* Returns the configuration file path.
*
* @return the configuration file path, or null, if it is not set
*/
public String getPath() {
return _path;
}
/**
* Reads the configuration file specified by the arguments passed at
* construction and optionally starts the OpenJMS provider.
*
* @param start if true, starts the OpenJMS provider
* @throws JMSException if the configuration file is invalid, or the
* OpenJMS provider cannot be started.
*/
public void initialise(boolean start) throws JMSException {
if (_path == null) {
throw new JMSException("Path property not set");
}
Configuration config = null;
try {
ConfigurationManager.setConfig(_path);
config = ConfigurationManager.getConfig();
} catch (Exception exception) {
_log.debug(exception.getMessage(), exception);
throw new JMSException(exception.getMessage());
}
if (start) {
_log.debug("Starting OpenJMS server");
Connector connector = ConfigurationManager.getConnector(
SchemeType.EMBEDDED);
if (connector != null) {
// if the embedded connector is configured, start an
// embedded server
_server = new EmbeddedServerAdapter(_path);
} else {
_server = new RemoteServerAdapter(_path);
}
_server.start();
}
}
/**
* Release any resources used by the provider
*
* @param stop if true, stops the OpenJMS provider
* @throws JMSException if the provider cannot be stopped
*/
public void cleanup(boolean stop) throws JMSException {
if (stop && _server != null) {
_log.debug("Shutting down OpenJMS server");
_server.stop();
}
}
} //-- OpenJMSProvider
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -