KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > net > nio > ChannelManager


1 package org.sapia.ubik.net.nio;
2
3 import java.io.IOException JavaDoc;
4 import java.nio.ByteBuffer JavaDoc;
5 import java.nio.channels.Channel JavaDoc;
6 import java.nio.channels.SelectionKey JavaDoc;
7 import java.nio.channels.Selector JavaDoc;
8
9 /**
10  * This interface specifies the behavior necessary for managing
11  * <code>Channel</code>s. This allows abstracting the core framework from the
12  * specific channels that might be used.
13  *
14  * @author Yanick Duchesne
15  *
16  * <dl>
17  * <dt><b>Copyright: </b>
18  * <dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open
19  * Source Software </a>. All Rights Reserved.</dd>
20  * </dt>
21  * <dt><b>License: </b>
22  * <dd>Read the license.txt file of the jar or visit the <a
23  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
24  * OSS web site</dd>
25  * </dt>
26  * </dl>
27  */

28 public interface ChannelManager {
29
30   /**
31    * This method creates a non-blocking <code>Channel</code> and returns it.
32    *
33    * @throws IOException
34    * if a problem occurs while creating the channel.
35    */

36   public Channel JavaDoc create() throws IOException JavaDoc;
37
38   /**
39    * This is a blocking method that is server oriented: to passed in channel is
40    * expected to be a server that accepts client connections and returns the
41    * channels corresponding to these client connections.
42    *
43    * @param server
44    * the server <code>Channel</code>.
45    * @return the <code>Channel</code> that represents a newly connected
46    * client.
47    * @throws IOException
48    * if an error occurs while accepting connections.
49    */

50   public Channel JavaDoc accept(Channel JavaDoc server) throws IOException JavaDoc,
51       UnsupportedOperationException JavaDoc;
52   
53   /**
54    * @return the address object of the passed in server.
55    */

56   public Object JavaDoc getAddress(Channel JavaDoc server) throws UnsupportedOperationException JavaDoc;
57
58   /**
59    * Performs the registration operation on the given selector.
60    *
61    * @param channel
62    * the <code>Channel</code> to register.
63    * @param selector
64    * the <code>Selector</code> with which the channel is to be
65    * registered.
66    * @param ops
67    * the selection operation register for.
68    * @param attachment
69    * an <code>Object</code> to attach to the
70    * <code>SelectionKey</code> that will be returned.
71    * @return a <code>SelectionKey</code>.
72    * @throws IOException
73    * if a problem occurs performing the registration.
74    */

75   public SelectionKey JavaDoc register(Channel JavaDoc channel, Selector JavaDoc selector, int ops,
76       Object JavaDoc attachment) throws IOException JavaDoc;
77
78   /**
79    * Reads data from the given channel and puts the data into the given buffer.
80    *
81    * @param from
82    * a <code>Channel</code> to read from.
83    * @param to
84    * a <code>ByteBuffer</code> to write to.
85    * @return the number of bytes that were read.
86    * @throws IOException
87    * if a problem occurs while reading.
88    */

89   public int read(Channel JavaDoc from, ByteBuffer JavaDoc to) throws IOException JavaDoc;
90
91   /**
92    * Writes the data contained in the given buffer to the given channel.
93    *
94    * @param to
95    * a <code>ByteBuffer</code>.
96    * @param from
97    * a <code>Channel</code>.
98    * @return the number of bytes that were written.
99    * @throws IOException
100    * if a problem occurs while writing.
101    */

102   public int write(Channel JavaDoc to, ByteBuffer JavaDoc from) throws IOException JavaDoc;
103
104   /**
105    * Implementation of this interface are expected to work in conjunction with
106    * <code>ChannelHandlerFactory</code> instances to implement this method.
107    *
108    * @return a <code>ChannelHandler</code>.
109    */

110   public ChannelHandler createHandler();
111 }
112
Popular Tags