1 7 8 package com.sun.corba.se.impl.legacy.connection; 9 10 import java.net.ServerSocket ; 11 import java.util.ArrayList ; 12 import java.util.Collection ; 13 import java.util.Iterator ; 14 15 import org.omg.CORBA.INITIALIZE ; 16 import org.omg.CORBA.INTERNAL ; 17 import org.omg.CORBA.CompletionStatus ; 18 19 import com.sun.corba.se.pept.transport.Acceptor; 20 import com.sun.corba.se.pept.transport.ByteBufferPool; 21 import com.sun.corba.se.pept.transport.ContactInfo; 22 import com.sun.corba.se.pept.transport.Selector; 23 24 import com.sun.corba.se.spi.ior.IOR; 25 import com.sun.corba.se.spi.ior.iiop.IIOPProfile ; 26 import com.sun.corba.se.spi.ior.ObjectKeyTemplate; 27 import com.sun.corba.se.spi.ior.ObjectId ; 28 import com.sun.corba.se.spi.orb.ORB; 29 import com.sun.corba.se.spi.transport.CorbaTransportManager; 30 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo; 31 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager; 32 import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor; 33 import com.sun.corba.se.spi.logging.CORBALogDomains; 34 35 import com.sun.corba.se.impl.encoding.EncapsOutputStream; 36 import com.sun.corba.se.impl.legacy.connection.SocketFactoryAcceptorImpl; 37 import com.sun.corba.se.impl.legacy.connection.USLPort; 38 import com.sun.corba.se.impl.orbutil.ORBUtility; 39 import com.sun.corba.se.impl.transport.SocketOrChannelAcceptorImpl; 40 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 41 42 public class LegacyServerSocketManagerImpl 43 implements 44 LegacyServerSocketManager 45 { 46 protected ORB orb; 47 private ORBUtilSystemException wrapper ; 48 49 public LegacyServerSocketManagerImpl(ORB orb) 50 { 51 this.orb = orb; 52 wrapper = ORBUtilSystemException.get( orb, 53 CORBALogDomains.RPC_TRANSPORT ) ; 54 } 55 56 61 public int legacyGetTransientServerPort(String type) 63 { 64 return legacyGetServerPort(type, false); 65 } 66 67 public synchronized int legacyGetPersistentServerPort(String socketType) 69 { 70 if (orb.getORBData().getServerIsORBActivated()) { 71 return legacyGetServerPort(socketType, true); 73 } else if (orb.getORBData().getPersistentPortInitialized()) { 74 return orb.getORBData().getPersistentServerPort(); 76 } else { 77 throw wrapper.persistentServerportNotSet( 78 CompletionStatus.COMPLETED_MAYBE); 79 } 80 } 81 82 public synchronized int legacyGetTransientOrPersistentServerPort( 84 String socketType) 85 { 86 return legacyGetServerPort(socketType, 87 orb.getORBData() 88 .getServerIsORBActivated()); 89 } 90 91 public synchronized LegacyServerSocketEndPointInfo legacyGetEndpoint( 95 String name) 96 { 97 Iterator iterator = getAcceptorIterator(); 98 while (iterator.hasNext()) { 99 LegacyServerSocketEndPointInfo endPoint = cast(iterator.next()); 100 if (endPoint != null && name.equals(endPoint.getName())) { 101 return endPoint; 102 } 103 } 104 throw new INTERNAL ("No acceptor for: " + name); 105 } 106 107 public boolean legacyIsLocalServerPort(int port) 111 { 112 Iterator iterator = getAcceptorIterator(); 113 while (iterator.hasNext()) { 114 LegacyServerSocketEndPointInfo endPoint = cast(iterator.next()); 115 if (endPoint != null && endPoint.getPort() == port) { 116 return true; 117 } 118 } 119 return false; 120 } 121 122 127 private int legacyGetServerPort (String socketType, boolean isPersistent) 128 { 129 Iterator endpoints = getAcceptorIterator(); 130 while (endpoints.hasNext()) { 131 LegacyServerSocketEndPointInfo ep = cast(endpoints.next()); 132 if (ep != null && ep.getType().equals(socketType)) { 133 if (isPersistent) { 134 return ep.getLocatorPort(); 135 } else { 136 return ep.getPort(); 137 } 138 } 139 } 140 return -1; 141 } 142 143 private Iterator getAcceptorIterator() 144 { 145 Collection acceptors = 146 orb.getCorbaTransportManager().getAcceptors(null, null); 147 if (acceptors != null) { 148 return acceptors.iterator(); 149 } 150 151 throw wrapper.getServerPortCalledBeforeEndpointsInitialized() ; 152 } 153 154 private LegacyServerSocketEndPointInfo cast(Object o) 155 { 156 if (o instanceof LegacyServerSocketEndPointInfo) { 157 return (LegacyServerSocketEndPointInfo) o; 158 } 159 return null; 160 } 161 162 protected void dprint(String msg) 163 { 164 ORBUtility.dprint("LegacyServerSocketManagerImpl", msg); 165 } 166 } 167 168 170 171 | Popular Tags |