1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2000-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: RmiJmsServer.java,v 1.23 2003/08/07 13:33:10 tanderson Exp $
44 *
45 * Date Author Changes
46 * 2/28/2000 jima Created
47 */
48 package org.exolab.jms.server.rmi;
49
50 import java.rmi.Naming;
51 import java.rmi.RMISecurityManager;
52 import java.rmi.RemoteException;
53 import java.rmi.server.UnicastRemoteObject;
54 import java.util.Hashtable;
55
56 import javax.jms.JMSException;
57 import javax.naming.Context;
58 import javax.naming.NamingException;
59
60 import org.apache.commons.logging.Log;
61 import org.apache.commons.logging.LogFactory;
62
63 import org.exolab.jms.client.rmi.RmiJmsConstants;
64 import org.exolab.jms.config.ConfigHelper;
65 import org.exolab.jms.config.Configuration;
66 import org.exolab.jms.config.ConfigurationManager;
67 import org.exolab.jms.config.Connector;
68 import org.exolab.jms.config.types.SchemeType;
69 import org.exolab.jms.server.ConnectionFactoryHelper;
70 import org.exolab.jms.server.JmsServerConnection;
71 import org.exolab.jms.server.JmsServerConnectionManager;
72 import org.exolab.jms.server.JmsServerIfc;
73 import org.exolab.jms.server.ServerException;
74
75
76 /***
77 * This class implements the JmsServerIfc and provides an RMI-based JMS Server.
78 * When then client calls init control is passed to this class instance until
79 * the server terminates (normally or abnormally).
80 *
81 * @version $Revision: 1.23 $ $Date: 2003/08/07 13:33:10 $
82 * @author <a href="mailto:jima@intalio.com">Jim Alateras</a>
83 * @see ConfigurationManager
84 */
85 public class RmiJmsServer
86 extends UnicastRemoteObject
87 implements JmsServerIfc, RemoteJmsServerIfc {
88
89 /***
90 * The logger
91 */
92 private static final Log _log = LogFactory.getLog(RmiJmsServer.class);
93
94
95 /***
96 * The default constructor determines whether or not to run the RMI
97 * registry in embedded mode or not. If embedded mode is specified then
98 * register this service with the ServiceManager.
99 */
100 public RmiJmsServer() throws RemoteException {
101 }
102
103 /***
104 * This routine binds this service with the rmiregistry.
105 * When a client needs to use the server it will be automatically
106 * activated by the rmiregistry to handle the request(s). It does expect
107 * that the registry is active when this routine is called.
108 *
109 * @throws ServerException if the service cannot be bound
110 */
111 public void init() throws ServerException {
112 try {
113 // set the RMISecurityManager as the security manager for the VM
114 System.setSecurityManager(new RMISecurityManager());
115
116 Configuration config = ConfigurationManager.getConfig();
117
118 // bind the server to the registry
119 String serverBinding = ConfigHelper.getServerURL(
120 SchemeType.RMI, config);
121 Naming.rebind(serverBinding, (RemoteJmsServerIfc) this);
122 _log.info("JMS Server is bound to " + serverBinding);
123
124 // create and bind the JMS admin server to the naming registry
125 String adminBinding = ConfigHelper.getAdminURL(
126 SchemeType.RMI, config);
127 Naming.rebind(adminBinding, new RmiJmsAdminServer());
128 _log.info("JMS Admin Server is bound to " + adminBinding);
129 } catch (Exception exception) {
130 throw new ServerException(
131 "Failed to initialise the RMI server interface", exception);
132 }
133 }
134
135 /***
136 * Bind any factory object specified in the configuration file to the
137 * specified JNDI context.
138 *
139 * @param context context to bind factory objects
140 * @throws NamingException if a naming error occurs
141 */
142 public void bindConnectionFactories(Context context)
143 throws NamingException {
144 Configuration config = ConfigurationManager.getConfig();
145
146 // we need to put together a list of parameters that the
147 // RMI connection factories will need to use to connect
148 // to this server
149 Hashtable env = new Hashtable();
150 String url = ConfigHelper.getServerURL(SchemeType.RMI, config);
151 env.put(RmiJmsConstants.SERVER_URL, url);
152 env.put(RmiJmsConstants.RMI_CLIENT_PING_INTERVAL,
153 Integer.toString(getClientPingInterval()));
154
155 Connector connector = ConfigurationManager.getConnector(
156 SchemeType.RMI);
157 ConnectionFactoryHelper.bind(
158 context, connector.getConnectionFactories(),
159 org.exolab.jms.client.rmi.RmiJmsServerStub.class, env);
160 }
161
162 /***
163 * Create a connection to the specified server. This will create an
164 * instance of a JmsServerConnection and then return a remote reference
165 * to it.
166 *
167 * @param id client identity
168 * @param username the client's user name
169 * @param password the client's password
170 * @return a new connection
171 * @throws JMSException if the connection cannot be created
172 * @throws RemoteException if the connection cannot be created
173 */
174 public RemoteJmsServerConnectionIfc createConnection(
175 String id, String username, String password)
176 throws JMSException, RemoteException {
177 JmsServerConnection connection =
178 JmsServerConnectionManager.instance().createConnection(
179 id, username, password);
180
181 return new RmiJmsServerConnection(connection, getClientPingInterval());
182 }
183
184 /***
185 * Return the client ping interval for this server. This interval is used
186 * to determine when clients are no longer available.
187 *
188 * @reutrn the ping interval in seconds
189 */
190 protected int getClientPingInterval() {
191 Configuration config = ConfigurationManager.getConfig();
192 return config.getRmiConfiguration().getClientPingInterval();
193 }
194
195 } //-- RmiJmsServer
This page was automatically generated by Maven