📄 rmijmsserver.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-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
*
* $Id: RmiJmsServer.java,v 1.23 2003/08/07 13:33:10 tanderson Exp $
*
* Date Author Changes
* 2/28/2000 jima Created
*/
package org.exolab.jms.server.rmi;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Hashtable;
import javax.jms.JMSException;
import javax.naming.Context;
import javax.naming.NamingException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.exolab.jms.client.rmi.RmiJmsConstants;
import org.exolab.jms.config.ConfigHelper;
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;
import org.exolab.jms.server.ConnectionFactoryHelper;
import org.exolab.jms.server.JmsServerConnection;
import org.exolab.jms.server.JmsServerConnectionManager;
import org.exolab.jms.server.JmsServerIfc;
import org.exolab.jms.server.ServerException;
/**
* This class implements the JmsServerIfc and provides an RMI-based JMS Server.
* When then client calls init control is passed to this class instance until
* the server terminates (normally or abnormally).
*
* @version $Revision: 1.23 $ $Date: 2003/08/07 13:33:10 $
* @author <a href="mailto:jima@intalio.com">Jim Alateras</a>
* @see ConfigurationManager
*/
public class RmiJmsServer
extends UnicastRemoteObject
implements JmsServerIfc, RemoteJmsServerIfc {
/**
* The logger
*/
private static final Log _log = LogFactory.getLog(RmiJmsServer.class);
/**
* The default constructor determines whether or not to run the RMI
* registry in embedded mode or not. If embedded mode is specified then
* register this service with the ServiceManager.
*/
public RmiJmsServer() throws RemoteException {
}
/**
* This routine binds this service with the rmiregistry.
* When a client needs to use the server it will be automatically
* activated by the rmiregistry to handle the request(s). It does expect
* that the registry is active when this routine is called.
*
* @throws ServerException if the service cannot be bound
*/
public void init() throws ServerException {
try {
// set the RMISecurityManager as the security manager for the VM
System.setSecurityManager(new RMISecurityManager());
Configuration config = ConfigurationManager.getConfig();
// bind the server to the registry
String serverBinding = ConfigHelper.getServerURL(
SchemeType.RMI, config);
Naming.rebind(serverBinding, (RemoteJmsServerIfc) this);
_log.info("JMS Server is bound to " + serverBinding);
// create and bind the JMS admin server to the naming registry
String adminBinding = ConfigHelper.getAdminURL(
SchemeType.RMI, config);
Naming.rebind(adminBinding, new RmiJmsAdminServer());
_log.info("JMS Admin Server is bound to " + adminBinding);
} catch (Exception exception) {
throw new ServerException(
"Failed to initialise the RMI server interface", exception);
}
}
/**
* Bind any factory object specified in the configuration file to the
* specified JNDI context.
*
* @param context context to bind factory objects
* @throws NamingException if a naming error occurs
*/
public void bindConnectionFactories(Context context)
throws NamingException {
Configuration config = ConfigurationManager.getConfig();
// we need to put together a list of parameters that the
// RMI connection factories will need to use to connect
// to this server
Hashtable env = new Hashtable();
String url = ConfigHelper.getServerURL(SchemeType.RMI, config);
env.put(RmiJmsConstants.SERVER_URL, url);
env.put(RmiJmsConstants.RMI_CLIENT_PING_INTERVAL,
Integer.toString(getClientPingInterval()));
Connector connector = ConfigurationManager.getConnector(
SchemeType.RMI);
ConnectionFactoryHelper.bind(
context, connector.getConnectionFactories(),
org.exolab.jms.client.rmi.RmiJmsServerStub.class, env);
}
/**
* Create a connection to the specified server. This will create an
* instance of a JmsServerConnection and then return a remote reference
* to it.
*
* @param id client identity
* @param username the client's user name
* @param password the client's password
* @return a new connection
* @throws JMSException if the connection cannot be created
* @throws RemoteException if the connection cannot be created
*/
public RemoteJmsServerConnectionIfc createConnection(
String id, String username, String password)
throws JMSException, RemoteException {
JmsServerConnection connection =
JmsServerConnectionManager.instance().createConnection(
id, username, password);
return new RmiJmsServerConnection(connection, getClientPingInterval());
}
/**
* Return the client ping interval for this server. This interval is used
* to determine when clients are no longer available.
*
* @reutrn the ping interval in seconds
*/
protected int getClientPingInterval() {
Configuration config = ConfigurationManager.getConfig();
return config.getRmiConfiguration().getClientPingInterval();
}
} //-- RmiJmsServer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -