1. /*
  2. * @(#)CorbaTransportManagerImpl.java 1.13 03/12/19
  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.transport;
  8. import java.net.ServerSocket;
  9. import java.util.ArrayList;
  10. import java.util.Collection;
  11. import java.util.HashMap;
  12. import java.util.Iterator;
  13. import java.util.List;
  14. import java.util.Map;
  15. import org.omg.CORBA.INITIALIZE;
  16. import org.omg.CORBA.INTERNAL;
  17. import org.omg.CORBA.CompletionStatus;
  18. import com.sun.corba.se.pept.transport.Acceptor;
  19. import com.sun.corba.se.pept.transport.ByteBufferPool;
  20. import com.sun.corba.se.pept.transport.ContactInfo;
  21. import com.sun.corba.se.pept.transport.InboundConnectionCache;
  22. import com.sun.corba.se.pept.transport.OutboundConnectionCache;
  23. import com.sun.corba.se.pept.transport.Selector;
  24. import com.sun.corba.se.spi.ior.IORTemplate;
  25. import com.sun.corba.se.spi.ior.ObjectAdapterId;
  26. import com.sun.corba.se.spi.orb.ORB;
  27. import com.sun.corba.se.spi.transport.CorbaAcceptor;
  28. import com.sun.corba.se.spi.transport.CorbaTransportManager;
  29. // REVISIT - impl/poa specific:
  30. import com.sun.corba.se.impl.oa.poa.Policies;
  31. import com.sun.corba.se.impl.orbutil.ORBUtility;
  32. /**
  33. * @author Harold Carr
  34. */
  35. public class CorbaTransportManagerImpl
  36. implements
  37. CorbaTransportManager
  38. {
  39. protected ORB orb;
  40. protected List acceptors;
  41. protected Map outboundConnectionCaches;
  42. protected Map inboundConnectionCaches;
  43. protected Selector selector;
  44. public CorbaTransportManagerImpl(ORB orb)
  45. {
  46. this.orb = orb;
  47. acceptors = new ArrayList();
  48. outboundConnectionCaches = new HashMap();
  49. inboundConnectionCaches = new HashMap();
  50. selector = new SelectorImpl(orb);
  51. }
  52. ////////////////////////////////////////////////////
  53. //
  54. // pept TransportManager
  55. //
  56. public ByteBufferPool getByteBufferPool(int id)
  57. {
  58. throw new RuntimeException();
  59. }
  60. public OutboundConnectionCache getOutboundConnectionCache(
  61. ContactInfo contactInfo)
  62. {
  63. synchronized (contactInfo) {
  64. if (contactInfo.getConnectionCache() == null) {
  65. OutboundConnectionCache connectionCache = null;
  66. synchronized (outboundConnectionCaches) {
  67. connectionCache = (OutboundConnectionCache)
  68. outboundConnectionCaches.get(
  69. contactInfo.getConnectionCacheType());
  70. if (connectionCache == null) {
  71. // REVISIT: Would like to be able to configure
  72. // the connection cache type used.
  73. connectionCache =
  74. new CorbaOutboundConnectionCacheImpl(orb,
  75. contactInfo);
  76. outboundConnectionCaches.put(
  77. contactInfo.getConnectionCacheType(),
  78. connectionCache);
  79. }
  80. }
  81. contactInfo.setConnectionCache(connectionCache);
  82. }
  83. return contactInfo.getConnectionCache();
  84. }
  85. }
  86. public Collection getOutboundConnectionCaches()
  87. {
  88. return outboundConnectionCaches.values();
  89. }
  90. public InboundConnectionCache getInboundConnectionCache(
  91. Acceptor acceptor)
  92. {
  93. synchronized (acceptor) {
  94. if (acceptor.getConnectionCache() == null) {
  95. InboundConnectionCache connectionCache = null;
  96. synchronized (inboundConnectionCaches) {
  97. connectionCache = (InboundConnectionCache)
  98. inboundConnectionCaches.get(
  99. acceptor.getConnectionCacheType());
  100. if (connectionCache == null) {
  101. // REVISIT: Would like to be able to configure
  102. // the connection cache type used.
  103. connectionCache =
  104. new CorbaInboundConnectionCacheImpl(orb,
  105. acceptor);
  106. inboundConnectionCaches.put(
  107. acceptor.getConnectionCacheType(),
  108. connectionCache);
  109. }
  110. }
  111. acceptor.setConnectionCache(connectionCache);
  112. }
  113. return acceptor.getConnectionCache();
  114. }
  115. }
  116. public Collection getInboundConnectionCaches()
  117. {
  118. return inboundConnectionCaches.values();
  119. }
  120. public Selector getSelector(int id)
  121. {
  122. return selector;
  123. }
  124. public synchronized void registerAcceptor(Acceptor acceptor)
  125. {
  126. if (orb.transportDebugFlag) {
  127. dprint(".registerAcceptor->: " + acceptor);
  128. }
  129. acceptors.add(acceptor);
  130. if (orb.transportDebugFlag) {
  131. dprint(".registerAcceptor<-: " + acceptor);
  132. }
  133. }
  134. public Collection getAcceptors()
  135. {
  136. return getAcceptors(null, null);
  137. }
  138. public synchronized void unregisterAcceptor(Acceptor acceptor)
  139. {
  140. acceptors.remove(acceptor);
  141. }
  142. public void close()
  143. {
  144. try {
  145. if (orb.transportDebugFlag) {
  146. dprint(".close->");
  147. }
  148. getSelector(0).close();
  149. } finally {
  150. if (orb.transportDebugFlag) {
  151. dprint(".close<-");
  152. }
  153. }
  154. }
  155. ////////////////////////////////////////////////////
  156. //
  157. // CorbaTransportManager
  158. //
  159. public Collection getAcceptors(String objectAdapterManagerId,
  160. ObjectAdapterId objectAdapterId)
  161. {
  162. // REVISIT - need to filter based on arguments.
  163. // REVISIT - initialization will be moved to OA.
  164. // Lazy initialization of acceptors.
  165. Iterator iterator = acceptors.iterator();
  166. while (iterator.hasNext()) {
  167. Acceptor acceptor = (Acceptor) iterator.next();
  168. if (acceptor.initialize()) {
  169. if (acceptor.shouldRegisterAcceptEvent()) {
  170. orb.getTransportManager().getSelector(0)
  171. .registerForEvent(acceptor.getEventHandler());
  172. }
  173. }
  174. }
  175. return acceptors;
  176. }
  177. // REVISIT - POA specific policies
  178. public void addToIORTemplate(IORTemplate iorTemplate,
  179. Policies policies,
  180. String codebase,
  181. String objectAdapterManagerId,
  182. ObjectAdapterId objectAdapterId)
  183. {
  184. Iterator iterator =
  185. getAcceptors(objectAdapterManagerId, objectAdapterId).iterator();
  186. while (iterator.hasNext()) {
  187. CorbaAcceptor acceptor = (CorbaAcceptor) iterator.next();
  188. acceptor.addToIORTemplate(iorTemplate, policies, codebase);
  189. }
  190. }
  191. ////////////////////////////////////////////////////
  192. //
  193. // implemenation
  194. //
  195. protected void dprint(String msg)
  196. {
  197. ORBUtility.dprint("CorbaTransportManagerImpl", msg);
  198. }
  199. }
  200. // End of file.