1. /*
  2. * @(#)SocketOrChannelContactInfoImpl.java 1.59 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.transport;
  8. import com.sun.corba.se.pept.transport.Connection;
  9. import com.sun.corba.se.spi.ior.IOR ;
  10. import com.sun.corba.se.spi.orb.ORB;
  11. import com.sun.corba.se.spi.transport.CorbaContactInfoList;
  12. import com.sun.corba.se.spi.transport.CorbaTransportManager;
  13. import com.sun.corba.se.spi.transport.SocketInfo;
  14. import com.sun.corba.se.impl.orbutil.ORBUtility;
  15. import com.sun.corba.se.impl.transport.CorbaContactInfoBase;
  16. /**
  17. * @author Harold Carr
  18. */
  19. public class SocketOrChannelContactInfoImpl
  20. extends CorbaContactInfoBase
  21. implements SocketInfo
  22. {
  23. protected boolean isHashCodeCached = false;
  24. protected int cachedHashCode;
  25. protected String socketType;
  26. protected String hostname;
  27. protected int port;
  28. // XREVISIT
  29. // See SocketOrChannelAcceptorImpl.createMessageMediator
  30. // See SocketFactoryContactInfoImpl.constructor()
  31. // See SocketOrChannelContactInfoImpl.constructor()
  32. protected SocketOrChannelContactInfoImpl()
  33. {
  34. }
  35. protected SocketOrChannelContactInfoImpl(
  36. ORB orb,
  37. CorbaContactInfoList contactInfoList)
  38. {
  39. this.orb = orb;
  40. this.contactInfoList = contactInfoList;
  41. }
  42. public SocketOrChannelContactInfoImpl(
  43. ORB orb,
  44. CorbaContactInfoList contactInfoList,
  45. String socketType,
  46. String hostname,
  47. int port)
  48. {
  49. this(orb, contactInfoList);
  50. this.socketType = socketType;
  51. this.hostname = hostname;
  52. this.port = port;
  53. }
  54. // XREVISIT
  55. public SocketOrChannelContactInfoImpl(
  56. ORB orb,
  57. CorbaContactInfoList contactInfoList,
  58. IOR effectiveTargetIOR,
  59. short addressingDisposition,
  60. String socketType,
  61. String hostname,
  62. int port)
  63. {
  64. this(orb, contactInfoList, socketType, hostname, port);
  65. this.effectiveTargetIOR = effectiveTargetIOR;
  66. this.addressingDisposition = addressingDisposition;
  67. }
  68. ////////////////////////////////////////////////////
  69. //
  70. // pept.transport.ContactInfo
  71. //
  72. public boolean isConnectionBased()
  73. {
  74. return true;
  75. }
  76. public boolean shouldCacheConnection()
  77. {
  78. return true;
  79. }
  80. public String getConnectionCacheType()
  81. {
  82. return CorbaTransportManager.SOCKET_OR_CHANNEL_CONNECTION_CACHE;
  83. }
  84. public Connection createConnection()
  85. {
  86. Connection connection =
  87. new SocketOrChannelConnectionImpl(orb, this,
  88. socketType, hostname, port);
  89. return connection;
  90. }
  91. ////////////////////////////////////////////////////
  92. //
  93. // spi.transport.CorbaContactInfo
  94. //
  95. public String getMonitoringName()
  96. {
  97. return "SocketConnections";
  98. }
  99. ////////////////////////////////////////////////////
  100. //
  101. // pept.transport.ContactInfo
  102. //
  103. public String getType()
  104. {
  105. return socketType;
  106. }
  107. public String getHost()
  108. {
  109. return hostname;
  110. }
  111. public int getPort()
  112. {
  113. return port;
  114. }
  115. ////////////////////////////////////////////////////
  116. //
  117. // java.lang.Object
  118. //
  119. public int hashCode()
  120. {
  121. if (! isHashCodeCached) {
  122. cachedHashCode = socketType.hashCode() ^ hostname.hashCode() ^ port;
  123. isHashCodeCached = true;
  124. }
  125. return cachedHashCode;
  126. }
  127. public boolean equals(Object obj)
  128. {
  129. if (obj == null) {
  130. return false;
  131. } else if (!(obj instanceof SocketOrChannelContactInfoImpl)) {
  132. return false;
  133. }
  134. SocketOrChannelContactInfoImpl other =
  135. (SocketOrChannelContactInfoImpl) obj;
  136. if (port != other.port) {
  137. return false;
  138. }
  139. if (!hostname.equals(other.hostname)) {
  140. return false;
  141. }
  142. if (socketType == null) {
  143. if (other.socketType != null) {
  144. return false;
  145. }
  146. } else if (!socketType.equals(other.socketType)) {
  147. return false;
  148. }
  149. return true;
  150. }
  151. public String toString()
  152. {
  153. return
  154. "SocketOrChannelContactInfoImpl["
  155. + socketType + " "
  156. + hostname + " "
  157. + port
  158. + "]";
  159. }
  160. ////////////////////////////////////////////////////
  161. //
  162. // Implementation
  163. //
  164. protected void dprint(String msg)
  165. {
  166. ORBUtility.dprint("SocketOrChannelContactInfoImpl", msg);
  167. }
  168. }
  169. // End of file.