1 45 package org.exolab.jms.server.net; 46 47 import java.rmi.RemoteException ; 48 import java.util.Hashtable ; 49 import java.util.Map ; 50 import javax.naming.Context ; 51 import javax.naming.NamingException ; 52 53 import org.apache.commons.logging.Log; 54 import org.apache.commons.logging.LogFactory; 55 import org.codehaus.spice.jndikit.NamingProvider; 56 57 import org.exolab.jms.authentication.AuthenticationMgr; 58 import org.exolab.jms.client.net.JmsServerStubImpl; 59 import org.exolab.jms.config.Configuration; 60 import org.exolab.jms.config.types.SchemeType; 61 import org.exolab.jms.net.orb.ORB; 62 import org.exolab.jms.net.orb.ORBFactory; 63 import org.exolab.jms.net.registry.LocalRegistry; 64 import org.exolab.jms.server.EmbeddedNameService; 65 import org.exolab.jms.server.ServerConnector; 66 import org.exolab.jms.server.ServerException; 67 68 69 76 public class RemoteServerConnector implements ServerConnector { 77 78 81 private final Configuration _config; 82 83 86 private final ConnectorCfg _connector; 87 88 92 private final String _exportURI; 93 94 98 private final String _connectURI; 99 100 103 private ORB _orb; 104 105 108 private static final Log _log = LogFactory.getLog( 109 RemoteServerConnector.class); 110 111 112 118 public RemoteServerConnector(SchemeType scheme, Configuration config) { 119 if (scheme == null) { 120 throw new IllegalArgumentException ("Argument 'scheme' is null"); 121 } 122 if (config == null) { 123 throw new IllegalArgumentException ("Argument 'config' is null"); 124 } 125 _connector = ConnectorCfgFactory.create(scheme, config); 126 _config = config; 127 _exportURI = _connector.getExportURI(); 128 _connectURI = _connector.getConnectURI(); 129 } 130 131 136 public void init() throws ServerException { 137 try { 138 Map properties = _connector.getAcceptProperties(); 139 _orb = ORBFactory.createORB(AuthenticationMgr.instance(), 140 properties); 141 if (!_connectURI.equals(_exportURI)) { 142 _orb.addRoute(_exportURI, _connectURI); 143 } 144 } catch (RemoteException exception) { 145 throw new ServerException( 146 "Failed to create ORB for URI:" + _exportURI, exception); 147 } 148 try { 149 LocalRegistry registry = _orb.getRegistry(); 150 151 RemoteServerConnectionFactory server = 152 new RemoteServerConnectionFactory(_orb, _exportURI); 153 registry.bind("server", server.getProxy()); 154 if (_log.isInfoEnabled()) { 155 _log.info("Server accepting connections on " + _exportURI); 156 } 157 158 if (_config.getServerConfiguration().getEmbeddedJNDI()) { 159 NamingProvider provider = 160 EmbeddedNameService.getInstance().getNamingProvider(); 161 RemoteNamingProvider jndi = new RemoteNamingProvider( 162 provider, _orb, _connector.getJNDIExportURI()); 163 registry.bind("jndi", jndi.getProxy()); 164 if (_log.isInfoEnabled()) { 165 _log.info("JNDI service accepting connections on " 166 + _connector.getJNDIExportURI()); 167 } 168 } 169 170 JmsAdminServerImpl admin = new JmsAdminServerImpl( 171 _orb, _connector.getAdminExportURI()); 172 registry.bind("admin", admin.getProxy()); 173 if (_log.isInfoEnabled()) { 174 _log.info("Admin service accepting connections on " 175 + _connector.getAdminExportURI()); 176 } 177 178 registry.setReadOnly(true); 179 } catch (Exception exception) { 180 throw new ServerException( 181 "Failed to initialise the server interface", exception); 182 } 183 } 184 185 192 public void bindConnectionFactories(Context context) 193 throws NamingException { 194 Map properties = _connector.getConnectProperties(); 197 Hashtable env = new Hashtable (); 198 env.putAll(properties); 199 ConnectionFactoryHelper.bind(context, 200 _connector.getConnectionFactories(), 201 JmsServerStubImpl.class, env); 202 } 203 204 209 public void close() throws ServerException { 210 try { 211 _orb.shutdown(); 212 } catch (RemoteException exception) { 213 throw new ServerException(exception.getMessage(), exception); 214 } 215 } 216 217 } 218 | Popular Tags |