99
1010import java .util .Set ;
1111import java .util .concurrent .Executor ;
12- import java .util .concurrent .Future ;
1312
1413import org .ros .internal .transport .tcp .ChannelGroup ;
1514
15+ /**
16+ * This is the ChannelHandlerContext that links the underlying TCP Socket 'channel' to the {@link ChannelPipeline} and the {@link ChannelGroup}
17+ * and provides access to the {@link Executor} to spin up event dispatcher.
18+ * @author jg (C) NeoCoreTechs 2017
19+ *
20+ */
1621public interface ChannelHandlerContext {
17- /**
18- * Return the {@link Channel } which is bound to the {@link ChannelHandlerContext}.
22+ /**
23+ * Return the {@link Socket } which is bound to the {@link ChannelHandlerContext}.
1924 */
2025 Socket channel ();
2126
@@ -33,99 +38,59 @@ public interface ChannelHandlerContext {
3338 String name ();
3439
3540 /**
36- * Request to bind to the given {@link SocketAddress} and notify the {@link Future} once the operation
37- * completes, either because the operation was successful or because of an error.
41+ * Request to bind to the given {@link SocketAddress}
3842 * <p>
39- * This will result in having the
40- * {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, CompletionHandler)} method
41- * called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
42- * {@link Channel}.
43+ * This will result in having the socket bound to the local address.
4344 */
4445 void bind (SocketAddress localAddress ) throws IOException ;
4546
4647 /**
47- * Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
48- * completes, either because the operation was successful or because of an error.
49- * <p>
50- * If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
51- * a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
52- * will be used.
48+ * Request to connect to the given {@link SocketAddress}.
5349 * <p>
54- * This will result in having the
55- * {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, CompletionHandler)}
56- * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
57- * {@link Channel}.
50+ * If the connection fails because of a connection timeout, the exception will be thrown
51+ * This will result in having the socket connected and the input and output streams initialized.
5852 * @throws IOException
5953 */
6054 void connect (SocketAddress remoteAddress ) throws IOException ;
6155
6256 /**
63- * Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
64- * {@link Future} once the operation completes, either because the operation was successful or because of
65- * an error.
66- * <p>
67- * This will result in having the
68- * {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, CompletionHandler)}
69- * method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
70- * {@link Channel}.
57+ * Request to connect to the given remote {@link SocketAddress} while bind to the localAddress.
58+ * This will result in having the socket bound and streams ready.
7159 * @throws IOException
7260 */
7361 void connect (SocketAddress remoteAddress , SocketAddress localAddress ) throws IOException ;
7462
75-
76-
7763 /**
78- * Request to disconnect from the remote peer and notify the {@link Future} once the operation completes,
79- * either because the operation was successful or because of an error.
80- * <p>
81- * This will result in having the
82- * {@link ChannelHandler#disconnect(ChannelHandlerContext, CompletionHandler)}
83- * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
84- * {@link Channel}.
64+ * Request to disconnect from the remote peer.
65+ * This will result in having the Socket closed.
8566 * @throws IOException
8667 */
8768 void disconnect () throws IOException ;
8869
8970 /**
90- * Request to close the {@link Channel} and notify the {@link Future} once the operation completes,
91- * either because the operation was successful or because of
92- * an error.
93- *
71+ * Request to close the {@link Channel}.
9472 * After it is closed it is not possible to reuse it again.
95- * <p>
96- * This will result in having the
97- * {@link ChannelHandler#close(ChannelHandlerContext, CompletionHandler)}
98- * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
99- * {@link Channel}.
73+ * This will result in having the {@link Socket} closed.
10074 * @throws IOException
10175 */
10276 void close () throws IOException ;
10377
104-
10578 /**
106- * Request to Read data from the {@link Channel} into the first inbound buffer, triggers an
107- * {@link ChannelHandler#channelRead(ChannelHandlerContext, Object)} event if data was
108- * read, and triggers a
109- * {@link ChannelHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the
110- * handler can decide to continue reading. If there's a pending read operation already, this method does nothing.
111- * <p>
112- * This will result in having the
113- * {@link ChannelHandler#read(ChannelHandlerContext)}
114- * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
115- * {@link Channel}.
116- * @throws IOException
79+ * Request to Read data from the {@link InputStream} into the first inbound buffer.
80+ * It is up to the client, i.e. {@link AsynchTCPWorker}, to trigger a read event if data was
81+ * read, and it does this through the pipeline {@link ChannelPipeline#fireChannelRead(Object)} and
82+ * triggers an event through the pipeline via the {@link ChannelPipeline#fireChannelReadComplete()}
83+ * if successful. If there's a pending read operation already, this method does nothing.
84+ * @throws IOException Generates {@link ChannelPipeline#fireExceptionCaught(Throwable)}
11785 */
11886 Object read () throws IOException ;
11987
12088 /**
12189 * Request to write a message via this {@link ChannelHandlerContext} through the {@link ChannelPipeline}.
122- * This method will not request to actual flush, so be sure to call {@link #flush()}
123- * once you want to request to flush all pending data to the actual transport.
12490 * @throws IOException
12591 */
12692 void write (Object msg ) throws IOException ;
12793
128-
12994 /**
13095 * Return the assigned {@link ChannelPipeline}
13196 */
@@ -164,10 +129,20 @@ public interface ChannelHandlerContext {
164129 */
165130 Set <String > getMessageTypes ();
166131
132+ /**
133+ * Write with the named {@link CompletionHandler}
134+ * @param msg
135+ * @param handler
136+ */
167137 void write (Object msg , CompletionHandler <Integer , Void > handler );
168138
139+ /**
140+ * Request to Read data from the {@link InputStream} into the first inbound buffer.
141+ * <p>
142+ * This will result in having the Socket read and {@link CompletionHandler#completed(Object, Object)}
143+ * On IOException {@link CompletionHandler#failed(Throwable, Object)}
144+ */
169145 Object read (CompletionHandler <Integer , Void > handler );
170146
171147
172-
173148}
0 commit comments