1 package org.jacorb.orb.giop; 2 3 22 23 import java.io.*; 24 import java.net.*; 25 import java.util.*; 26 import java.lang.reflect.Constructor ; 27 28 import org.apache.avalon.framework.logger.Logger; 29 import org.apache.avalon.framework.configuration.Configurable; 30 import org.apache.avalon.framework.configuration.Configuration; 31 import org.apache.avalon.framework.configuration.DefaultConfiguration; 32 import org.apache.avalon.framework.configuration.ConfigurationException; 33 34 import org.omg.ETF.Factories; 35 36 import org.jacorb.orb.*; 37 import org.jacorb.orb.factory.*; 38 import org.jacorb.orb.iiop.*; 39 import org.jacorb.util.ObjectUtil; 40 41 48 49 public class ClientConnectionManager 50 implements Configurable 51 { 52 private org.jacorb.orb.ORB orb = null; 53 54 55 private Map connections = new HashMap(); 56 57 private SocketFactory socket_factory = null; 58 private SocketFactory ssl_socket_factory = null; 59 60 private RequestListener request_listener = null; 61 62 private MessageReceptorPool receptor_pool = null; 63 64 private TransportManager transport_manager = null; 65 private GIOPConnectionManager giop_connection_manager = null; 66 67 68 private org.jacorb.config.Configuration configuration = null; 69 private Logger logger = null; 70 71 public ClientConnectionManager( ORB orb, 72 TransportManager transport_manager, 73 GIOPConnectionManager giop_connection_manager ) 74 { 75 this.orb = orb; 76 this.transport_manager = transport_manager; 77 this.giop_connection_manager = giop_connection_manager; 78 } 79 80 83 84 public void configure(Configuration myConfiguration) 85 throws ConfigurationException 86 { 87 receptor_pool = MessageReceptorPool.getInstance(myConfiguration); 89 90 this.configuration = (org.jacorb.config.Configuration)myConfiguration; 91 logger = configuration.getNamedLogger("jacorb.orb.giop"); 92 93 request_listener = new NoBiDirClientRequestListener(logger); 94 95 socket_factory = 96 transport_manager.getSocketFactoryManager().getSocketFactory(); 97 98 if (configuration.getAttribute("jacorb.security.support_ssl","off").equals("on") ) 99 { 100 String s = configuration.getAttribute("jacorb.ssl.socket_factory",""); 101 if ( s.length() == 0) 102 { 103 throw new RuntimeException ( "SSL support is on, but the property \"jacorb.ssl.socket_factory\" is not set!" ); 104 } 105 106 try 107 { 108 Class ssl = ObjectUtil.classForName(s); 109 110 Constructor constr = 111 ssl.getConstructor( new Class []{ ORB.class }); 112 113 ssl_socket_factory = 114 (SocketFactory)constr.newInstance( new Object []{ orb }); 115 } 116 catch (Exception e) 117 { 118 throw new RuntimeException ( "SSL support is on, but the ssl socket factory can't be instantiated ("+e.getMessage()+")!" ); 119 } 120 } 121 122 123 } 124 125 126 public void setRequestListener( RequestListener listener ) 127 { 128 request_listener = listener; 129 } 130 131 public synchronized ClientConnection getConnection 132 (org.omg.ETF.Profile profile) 133 { 134 135 136 ClientConnection c = 137 (ClientConnection)connections.get( profile ); 138 139 if (c == null) 140 { 141 int tag = profile.tag(); 142 Factories factories = transport_manager.getFactories (tag); 143 if (factories == null) 144 { 145 throw new RuntimeException 146 ("No transport plugin for profile tag " + tag); 147 } 148 GIOPConnection connection = 149 giop_connection_manager.createClientGIOPConnection( 150 profile, 151 factories.create_connection (null), 152 request_listener, 153 null ); 154 155 c = new ClientConnection( connection, orb, this, 156 profile, true ); 157 158 if( logger.isInfoEnabled()) 159 { 160 logger.info("ClientConnectionManager: created new conn to target " + 161 c.getInfo() ); 162 } 163 164 connections.put( profile, c ); 165 receptor_pool.connectionCreated( connection ); 166 } 167 else 168 { 169 if( logger.isInfoEnabled()) 170 { 171 logger.info("ClientConnectionManager: found conn to target " + 172 c.getInfo()); 173 } 174 } 175 176 c.incClients(); 177 178 return c; 179 } 180 181 184 public synchronized void releaseConnection( ClientConnection c ) 185 { 186 if ( c.decClients() ) 188 { 189 c.close(); 190 connections.remove(c.getRegisteredProfile()); 191 } 192 } 193 194 198 public synchronized void removeConnection(ClientConnection c) 199 { 200 connections.remove( c.getRegisteredProfile() ); 201 } 202 203 public synchronized void addConnection( GIOPConnection connection ) 204 { 205 addConnection(connection, 206 connection.getTransport().get_server_profile() ); 207 } 208 209 public synchronized void addConnection( GIOPConnection connection, 210 org.omg.ETF.Profile profile ) 211 { 212 if( !connections.containsKey( profile )) 213 { 214 ClientConnection c = new ClientConnection 215 ( 216 connection, orb, this, 217 profile, 218 false 219 ); 220 221 227 c.incClients(); 228 229 connections.put( profile, c ); 230 } 231 } 232 233 public void shutdown() 234 { 235 236 237 for( Iterator i = connections.values().iterator(); i.hasNext(); ) 238 { 239 ((ClientConnection) i.next()).close(); 240 } 241 242 if( logger.isDebugEnabled()) 243 { 244 logger.debug("ClientConnectionManager shut down (all connections released)"); 245 } 246 247 connections.clear(); 248 } 249 } 250 | Popular Tags |