1 7 8 package com.sun.corba.se.impl.transport; 9 10 import java.net.ServerSocket ; 11 import java.util.ArrayList ; 12 import java.util.Collection ; 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 import java.util.Map ; 17 18 import org.omg.CORBA.INITIALIZE ; 19 import org.omg.CORBA.INTERNAL ; 20 import org.omg.CORBA.CompletionStatus ; 21 22 import com.sun.corba.se.pept.transport.Acceptor; 23 import com.sun.corba.se.pept.transport.ByteBufferPool; 24 import com.sun.corba.se.pept.transport.ContactInfo; 25 import com.sun.corba.se.pept.transport.InboundConnectionCache; 26 import com.sun.corba.se.pept.transport.OutboundConnectionCache; 27 import com.sun.corba.se.pept.transport.Selector; 28 29 import com.sun.corba.se.spi.ior.IORTemplate; 30 import com.sun.corba.se.spi.ior.ObjectAdapterId; 31 import com.sun.corba.se.spi.orb.ORB; 32 import com.sun.corba.se.spi.transport.CorbaAcceptor; 33 import com.sun.corba.se.spi.transport.CorbaTransportManager; 34 import com.sun.corba.se.pept.transport.Connection; 35 import com.sun.corba.se.pept.transport.ConnectionCache; 36 37 import com.sun.corba.se.impl.oa.poa.Policies; 39 import com.sun.corba.se.impl.orbutil.ORBUtility; 40 41 44 public class CorbaTransportManagerImpl 45 implements 46 CorbaTransportManager 47 { 48 protected ORB orb; 49 protected List acceptors; 50 protected Map outboundConnectionCaches; 51 protected Map inboundConnectionCaches; 52 protected Selector selector; 53 54 public CorbaTransportManagerImpl(ORB orb) 55 { 56 this.orb = orb; 57 acceptors = new ArrayList (); 58 outboundConnectionCaches = new HashMap (); 59 inboundConnectionCaches = new HashMap (); 60 selector = new SelectorImpl(orb); 61 } 62 63 68 public ByteBufferPool getByteBufferPool(int id) 69 { 70 throw new RuntimeException (); 71 } 72 73 public OutboundConnectionCache getOutboundConnectionCache( 74 ContactInfo contactInfo) 75 { 76 synchronized (contactInfo) { 77 if (contactInfo.getConnectionCache() == null) { 78 OutboundConnectionCache connectionCache = null; 79 synchronized (outboundConnectionCaches) { 80 connectionCache = (OutboundConnectionCache) 81 outboundConnectionCaches.get( 82 contactInfo.getConnectionCacheType()); 83 if (connectionCache == null) { 84 connectionCache = 87 new CorbaOutboundConnectionCacheImpl(orb, 88 contactInfo); 89 outboundConnectionCaches.put( 90 contactInfo.getConnectionCacheType(), 91 connectionCache); 92 } 93 } 94 contactInfo.setConnectionCache(connectionCache); 95 } 96 return contactInfo.getConnectionCache(); 97 } 98 } 99 100 public Collection getOutboundConnectionCaches() 101 { 102 return outboundConnectionCaches.values(); 103 } 104 105 public InboundConnectionCache getInboundConnectionCache( 106 Acceptor acceptor) 107 { 108 synchronized (acceptor) { 109 if (acceptor.getConnectionCache() == null) { 110 InboundConnectionCache connectionCache = null; 111 synchronized (inboundConnectionCaches) { 112 connectionCache = (InboundConnectionCache) 113 inboundConnectionCaches.get( 114 acceptor.getConnectionCacheType()); 115 if (connectionCache == null) { 116 connectionCache = 119 new CorbaInboundConnectionCacheImpl(orb, 120 acceptor); 121 inboundConnectionCaches.put( 122 acceptor.getConnectionCacheType(), 123 connectionCache); 124 } 125 } 126 acceptor.setConnectionCache(connectionCache); 127 } 128 return acceptor.getConnectionCache(); 129 } 130 } 131 132 public Collection getInboundConnectionCaches() 133 { 134 return inboundConnectionCaches.values(); 135 } 136 137 public Selector getSelector(int id) 138 { 139 return selector; 140 } 141 142 public synchronized void registerAcceptor(Acceptor acceptor) 143 { 144 if (orb.transportDebugFlag) { 145 dprint(".registerAcceptor->: " + acceptor); 146 } 147 acceptors.add(acceptor); 148 if (orb.transportDebugFlag) { 149 dprint(".registerAcceptor<-: " + acceptor); 150 } 151 } 152 153 public Collection getAcceptors() 154 { 155 return getAcceptors(null, null); 156 } 157 158 public synchronized void unregisterAcceptor(Acceptor acceptor) 159 { 160 acceptors.remove(acceptor); 161 } 162 163 public void close() 164 { 165 try { 166 if (orb.transportDebugFlag) { 167 dprint(".close->"); 168 } 169 getSelector(0).close(); 170 Collection c = getOutboundConnectionCaches(); 171 Iterator iter=c.iterator(); 172 173 for (;iter.hasNext();) { 174 CorbaConnectionCacheBase cc = (CorbaConnectionCacheBase)iter.next(); 175 Iterator iterator = cc.values().iterator(); 176 177 while (iterator.hasNext()) { 179 Connection conn = (Connection) iterator.next(); 180 if (!conn.isBusy()) { 181 try { 182 conn.close(); 183 iterator = cc.values().iterator(); 184 } catch (Exception ex) { if (orb.transportDebugFlag) { 186 dprint("Exception while closing connection" + conn); 187 } 190 } 191 } 192 } 193 } 194 195 } finally { 196 if (orb.transportDebugFlag) { 197 dprint(".close<-"); 198 } 199 } 200 } 201 202 207 public Collection getAcceptors(String objectAdapterManagerId, 208 ObjectAdapterId objectAdapterId) 209 { 210 212 Iterator iterator = acceptors.iterator(); 215 while (iterator.hasNext()) { 216 Acceptor acceptor = (Acceptor) iterator.next(); 217 if (acceptor.initialize()) { 218 if (acceptor.shouldRegisterAcceptEvent()) { 219 orb.getTransportManager().getSelector(0) 220 .registerForEvent(acceptor.getEventHandler()); 221 } 222 } 223 } 224 return acceptors; 225 } 226 227 public void addToIORTemplate(IORTemplate iorTemplate, 229 Policies policies, 230 String codebase, 231 String objectAdapterManagerId, 232 ObjectAdapterId objectAdapterId) 233 { 234 Iterator iterator = 235 getAcceptors(objectAdapterManagerId, objectAdapterId).iterator(); 236 while (iterator.hasNext()) { 237 CorbaAcceptor acceptor = (CorbaAcceptor) iterator.next(); 238 acceptor.addToIORTemplate(iorTemplate, policies, codebase); 239 } 240 } 241 242 243 248 protected void dprint(String msg) 249 { 250 ORBUtility.dprint("CorbaTransportManagerImpl", msg); 251 } 252 } 253 254 | Popular Tags |