KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > net > mplex > MultiplexSocketConnector


1 package org.sapia.ubik.net.mplex;
2
3 import java.io.IOException JavaDoc;
4
5 import java.net.InetAddress JavaDoc;
6 import java.net.Socket JavaDoc;
7 import java.net.SocketAddress JavaDoc;
8 import java.net.SocketException JavaDoc;
9
10
11 /**
12  * The <code>MultiplexSocketConnector</code> class is the access point to get client
13  * socket connections in the multiplex logic. Its functionality is similar to the
14  * traditional server socket, which gives you the next socket connection upon calling
15  * the <code>accept()</code> method.<p>
16  *
17  * A connector instance can be created using the <code>createSocketConnector()</code>
18  * method of the class <code>MultiplexServerSocket</code>, providing a <code>StreamSelector</code>
19  * object. Upon this call, the server socket will create a new connector instance that will
20  * be associated to the server socket. The selector passed in will be used to determine
21  * if this connector will handle or not a new client socket connection. After you need to call
22  * the <code>accept()</code> to get the next client socket connection (blocking call). Finally
23  * when you are done with this socket connector a call to the <code>close()</code> method is
24  * required to release all the resource used by this socket connector. Note that closing the
25  * socket connector will not close the underlying server socket.<p>
26  *
27  * All the accessor methods that returns a state delegates the call to the underlying
28  * server socket. For example a call to get the port number on which is connector is bound
29  * to, using the <code>getLocalPort()</code> method, will pass the request to the server
30  * socket that is associated with this socket connector.
31  *
32  * @see MultiplexServerSocket
33  * @see StreamSelector
34  * @author <a HREF="mailto:jc@sapia-oss.org">Jean-Cedric Desrochers</a>
35  * <dl>
36  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2004 <a HREF="http://www.sapia-oss.org">
37  * Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
38  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
39  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a>
40  * at the Sapia OSS web site</dd></dt>
41  * </dl>
42  */

43 public interface MultiplexSocketConnector {
44   /**
45    * Returns the port on which this socket is listening.
46    *
47    * @return The port number to which this socket is listening or
48    * -1 if the socket is not bound yet.
49    */

50   public int getLocalPort();
51
52   /**
53    * Returns the local address of this server socket.
54    *
55    * @return The address to which this socket is bound, or
56    * <code>null</code> if the socket is unbound.
57    */

58   public InetAddress JavaDoc getInetAddress();
59
60   /**
61    * Returns the address of the endpoint this socket is bound to, or
62    * <code>null</code> if it is not bound yet.
63    *
64    * @return A <code>SocketAddress</code> representing the local endpoint of this
65    * socket, or <code>null</code> if it is not bound yet.
66    */

67   public SocketAddress JavaDoc getLocalSocketAddress();
68
69   /**
70    * Gets the value of the SO_RCVBUF option for this socket interceptor
71    * that is the proposed buffer size that will be used for Sockets accepted
72    * from this socket interceptor.
73    *
74    * @return the value of the SO_RCVBUF option for this Socket.
75    * @exception SocketException if there is an error in the underlying protocol.
76    */

77   public int getReceiveBufferSize() throws SocketException JavaDoc;
78
79   /**
80    * Tests if SO_REUSEADDR is enabled.
81    *
82    * @return A <code>boolean</code> indicating whether or not SO_REUSEADDR is enabled.
83    * @exception SocketException if there is an error in the underlying protocol.
84    */

85   public boolean getReuseAddress() throws SocketException JavaDoc;
86
87   /**
88    * Retrieve setting for SO_TIMEOUT. Zero returns implies that the option is disabled
89    * (i.e., timeout of infinity).
90    *
91    * @return the SO_TIMEOUT value
92    * @exception IOException if an I/O error occurs
93    */

94   public int getSoTimeout() throws IOException JavaDoc;
95
96   /**
97    * Returns the binding state of the socket.
98    *
99    * @return True if the socket succesfuly bound to an address.
100    */

101   public boolean isBound();
102
103   /**
104    * Returns the closed state of the socket.
105    *
106    * @return True if the socket has been closed.
107    */

108   public boolean isClosed();
109
110   /**
111    * Listens for a connection to be made to this socket and accepts
112    * it. The method blocks until a connection is made.
113    *
114    * @return The new Socket
115    * @exception IOException If an I/O error occurs when waiting for a connection.
116    */

117   public Socket JavaDoc accept() throws IOException JavaDoc;
118
119   /**
120    * Closes this multiplex socket handler.
121    *
122    * @exception IOException if an I/O error occurs when closing the socket.
123    */

124   public void close() throws IOException JavaDoc;
125 }
126
Popular Tags