1. /*
  2. * @(#)LegacyServerSocketManagerImpl.java 1.94 04/06/21
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.legacy.connection;
  8. import java.net.ServerSocket;
  9. import java.util.ArrayList;
  10. import java.util.Collection;
  11. import java.util.Iterator;
  12. import org.omg.CORBA.INITIALIZE;
  13. import org.omg.CORBA.INTERNAL;
  14. import org.omg.CORBA.CompletionStatus;
  15. import com.sun.corba.se.pept.transport.Acceptor;
  16. import com.sun.corba.se.pept.transport.ByteBufferPool;
  17. import com.sun.corba.se.pept.transport.ContactInfo;
  18. import com.sun.corba.se.pept.transport.Selector;
  19. import com.sun.corba.se.spi.ior.IOR;
  20. import com.sun.corba.se.spi.ior.iiop.IIOPProfile ;
  21. import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
  22. import com.sun.corba.se.spi.ior.ObjectId ;
  23. import com.sun.corba.se.spi.orb.ORB;
  24. import com.sun.corba.se.spi.transport.CorbaTransportManager;
  25. import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo;
  26. import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager;
  27. import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor;
  28. import com.sun.corba.se.spi.logging.CORBALogDomains;
  29. import com.sun.corba.se.impl.encoding.EncapsOutputStream;
  30. import com.sun.corba.se.impl.legacy.connection.SocketFactoryAcceptorImpl;
  31. import com.sun.corba.se.impl.legacy.connection.USLPort;
  32. import com.sun.corba.se.impl.orbutil.ORBUtility;
  33. import com.sun.corba.se.impl.transport.SocketOrChannelAcceptorImpl;
  34. import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  35. public class LegacyServerSocketManagerImpl
  36. implements
  37. LegacyServerSocketManager
  38. {
  39. protected ORB orb;
  40. private ORBUtilSystemException wrapper ;
  41. public LegacyServerSocketManagerImpl(ORB orb)
  42. {
  43. this.orb = orb;
  44. wrapper = ORBUtilSystemException.get( orb,
  45. CORBALogDomains.RPC_TRANSPORT ) ;
  46. }
  47. ////////////////////////////////////////////////////
  48. //
  49. // LegacyServerSocketManager
  50. //
  51. // Only used in ServerManagerImpl.
  52. public int legacyGetTransientServerPort(String type)
  53. {
  54. return legacyGetServerPort(type, false);
  55. }
  56. // Only used by POAPolicyMediatorBase.
  57. public synchronized int legacyGetPersistentServerPort(String socketType)
  58. {
  59. if (orb.getORBData().getServerIsORBActivated()) {
  60. // this server is activated by orbd
  61. return legacyGetServerPort(socketType, true);
  62. } else if (orb.getORBData().getPersistentPortInitialized()) {
  63. // this is a user-activated server
  64. return orb.getORBData().getPersistentServerPort();
  65. } else {
  66. throw wrapper.persistentServerportNotSet(
  67. CompletionStatus.COMPLETED_MAYBE);
  68. }
  69. }
  70. // Only used by PI IORInfoImpl.
  71. public synchronized int legacyGetTransientOrPersistentServerPort(
  72. String socketType)
  73. {
  74. return legacyGetServerPort(socketType,
  75. orb.getORBData()
  76. .getServerIsORBActivated());
  77. }
  78. // Used in RepositoryImpl, ServerManagerImpl, POAImpl,
  79. // POAPolicyMediatorBase, TOAImpl.
  80. // To get either default or bootnaming endpoint.
  81. public synchronized LegacyServerSocketEndPointInfo legacyGetEndpoint(
  82. String name)
  83. {
  84. Iterator iterator = getAcceptorIterator();
  85. while (iterator.hasNext()) {
  86. LegacyServerSocketEndPointInfo endPoint = cast(iterator.next());
  87. if (endPoint != null && name.equals(endPoint.getName())) {
  88. return endPoint;
  89. }
  90. }
  91. throw new INTERNAL("No acceptor for: " + name);
  92. }
  93. // Check to see if the given port is equal to any of the ORB Server Ports.
  94. // XXX Does this need to change for the multi-homed case?
  95. // Used in IIOPProfileImpl, ORBImpl.
  96. public boolean legacyIsLocalServerPort(int port)
  97. {
  98. Iterator iterator = getAcceptorIterator();
  99. while (iterator.hasNext()) {
  100. LegacyServerSocketEndPointInfo endPoint = cast(iterator.next());
  101. if (endPoint != null && endPoint.getPort() == port) {
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. ////////////////////////////////////////////////////
  108. //
  109. // Implementation.
  110. //
  111. private int legacyGetServerPort (String socketType, boolean isPersistent)
  112. {
  113. Iterator endpoints = getAcceptorIterator();
  114. while (endpoints.hasNext()) {
  115. LegacyServerSocketEndPointInfo ep = cast(endpoints.next());
  116. if (ep != null && ep.getType().equals(socketType)) {
  117. if (isPersistent) {
  118. return ep.getLocatorPort();
  119. } else {
  120. return ep.getPort();
  121. }
  122. }
  123. }
  124. return -1;
  125. }
  126. private Iterator getAcceptorIterator()
  127. {
  128. Collection acceptors =
  129. orb.getCorbaTransportManager().getAcceptors(null, null);
  130. if (acceptors != null) {
  131. return acceptors.iterator();
  132. }
  133. throw wrapper.getServerPortCalledBeforeEndpointsInitialized() ;
  134. }
  135. private LegacyServerSocketEndPointInfo cast(Object o)
  136. {
  137. if (o instanceof LegacyServerSocketEndPointInfo) {
  138. return (LegacyServerSocketEndPointInfo) o;
  139. }
  140. return null;
  141. }
  142. protected void dprint(String msg)
  143. {
  144. ORBUtility.dprint("LegacyServerSocketManagerImpl", msg);
  145. }
  146. }
  147. // End of file.