1. /*
  2. * @(#)Connection.java 1.21 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.pept.transport;
  8. import java.io.IOException;
  9. import com.sun.corba.se.pept.encoding.InputObject;
  10. import com.sun.corba.se.pept.encoding.OutputObject;
  11. import com.sun.corba.se.pept.protocol.MessageMediator;
  12. import com.sun.corba.se.pept.transport.EventHandler;
  13. /**
  14. * <p><code>Connection</code> represents a <em>transport</em> in the
  15. * PEPt architecture.</p>
  16. *
  17. * @author Harold Carr
  18. */
  19. public interface Connection
  20. {
  21. /**
  22. * Used to determine if the <code>Connection</code> should register
  23. * with the
  24. * {@link com.sun.corba.se.pept.transport.TransportManager
  25. * TransportManager}
  26. * {@link com.sun.corba.se.pept.transport.Selector Selector}
  27. * to handle read events.
  28. *
  29. * For example, an HTTP transport would not register since the requesting
  30. * thread would just block on read when waiting for the reply.
  31. *
  32. * @return <code>true</code> if it should be registered.
  33. */
  34. public boolean shouldRegisterReadEvent();
  35. /**
  36. * Used to determine if the <code>Connection</code> should register
  37. * with the
  38. * {@link com.sun.corba.se.pept.transport.TransportManager
  39. * TransportManager}
  40. * {@link com.sun.corba.se.pept.transport.Selector Selector}
  41. * to handle read events.
  42. *
  43. * For example, an HTTP transport would not register since the requesting
  44. * thread would just block on read when waiting for the reply.
  45. *
  46. * @return <code>true</code> if it should be registered.
  47. */
  48. public boolean shouldRegisterServerReadEvent(); // REVISIT - why special?
  49. /**
  50. * Called to read incoming messages.
  51. *
  52. * @return <code>true</code> if the thread calling read can be released.
  53. */
  54. public boolean read();
  55. /**
  56. * Close the <code>Connection</code>.
  57. *
  58. */
  59. public void close();
  60. // REVISIT: replace next two with PlugInFactory (implemented by ContactInfo
  61. // and Acceptor).
  62. /**
  63. * Get the
  64. * {@link com.sun.corba.se.pept.transport.Acceptor Acceptor}
  65. * that created this <code>Connection</code>.
  66. *
  67. * @return
  68. * {@link com.sun.corba.se.pept.transport.Acceptor Acceptor}
  69. */
  70. public Acceptor getAcceptor();
  71. /**
  72. * Get the
  73. * {@link com.sun.corba.se.pept.transport.ContactInfo ContactInfo}
  74. * that created this <code>Connection</code>.
  75. *
  76. * @return
  77. * {@link com.sun.corba.se.pept.transport.ContactInfo ContactInfo}
  78. */
  79. public ContactInfo getContactInfo();
  80. /**
  81. * Get the
  82. * {@link com.sun.corba.se.pept.transport.EventHandler EventHandler}
  83. * associated with this <code>Acceptor</code>.
  84. *
  85. * @return
  86. * {@link com.sun.corba.se.pept.transport.EventHandler EventHandler}
  87. */
  88. public EventHandler getEventHandler();
  89. /**
  90. * Indicates whether a
  91. * {@link com.sun.corba.se.pept.transport.ContactInfo ContactInfo}
  92. * or a
  93. * {@link com.sun.corba.se.pept.transport.Acceptor Acceptor}
  94. * created the
  95. * <code>Connection</code>.
  96. *
  97. * @return <code>true</code> if <code>Connection</code> an
  98. * {@link com.sun.corba.se.pept.transport.Acceptor Acceptor}
  99. * created the <code>Connection</code>.
  100. */
  101. public boolean isServer();
  102. /**
  103. * Indicates if the <code>Connection</code> is in the process of
  104. * sending or receiving a message.
  105. *
  106. * @return <code>true</code> if the <code>Connection</code> is busy.
  107. */
  108. public boolean isBusy();
  109. /**
  110. * Timestamps are used for connection management, in particular, for
  111. * reclaiming idle <code>Connection</code>s.
  112. *
  113. * @return the "time" the <code>Connection</code> was last used.
  114. */
  115. public long getTimeStamp();
  116. /**
  117. * Timestamps are used for connection management, in particular, for
  118. * reclaiming idle <code>Connection</code>s.
  119. *
  120. * @param time - the "time" the <code>Connection</code> was last used.
  121. */
  122. public void setTimeStamp(long time);
  123. /**
  124. * The "state" of the <code>Connection</code>.
  125. *
  126. * param state
  127. */
  128. public void setState(String state);
  129. /**
  130. * Grab a write lock on the <code>Connection</code>.
  131. *
  132. * If another thread already has a write lock then the calling
  133. * thread will block until the lock is released. The calling
  134. * thread must call
  135. * {@link #writeUnlock}
  136. * when it is done.
  137. */
  138. public void writeLock();
  139. /**
  140. * Release a write lock on the <code>Connection</code>.
  141. */
  142. public void writeUnlock();
  143. /*
  144. * Send the data encoded in
  145. * {@link com.sun.corba.se.pept.encoding.OutputObject OutputObject}
  146. * on the <code>Connection</code>.
  147. *
  148. * @param outputObject
  149. */
  150. public void sendWithoutLock(OutputObject outputObject);
  151. /**
  152. * Register an invocation's
  153. * {@link com.sun.corba.se.pept.protocol.MessageMediator MessageMediator}
  154. * with the <code>Connection</code>.
  155. *
  156. * This is useful in protocols which support fragmentation.
  157. *
  158. * @param messageMediator
  159. */
  160. public void registerWaiter(MessageMediator messageMediator);
  161. /**
  162. * If a message expect's a response then this method is called.
  163. *
  164. * This method might block on a read (e.g., HTTP), put the calling
  165. * thread to sleep while another thread read's the response (e.g., GIOP),
  166. * or it may use the calling thread to perform the server-side work
  167. * (e.g., Solaris Doors).
  168. *
  169. * @param messageMediator
  170. */
  171. public InputObject waitForResponse(MessageMediator messageMediator);
  172. /**
  173. * Unregister an invocation's
  174. * {@link com.sun.corba.se.pept.protocol.MessageMediator MessageMediator}
  175. * with the <code>Connection</code>.
  176. *
  177. * @param messageMediator
  178. */
  179. public void unregisterWaiter(MessageMediator messageMediator);
  180. public void setConnectionCache(ConnectionCache connectionCache);
  181. public ConnectionCache getConnectionCache();
  182. }
  183. // End of file.