View Javadoc
1   /*
2    * Copyright 2012 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.channel;
17  
18  import java.net.SocketAddress;
19  
20  /**
21   * {@link ChannelHandler} which will get notified for IO-outbound-operations.
22   */
23  public interface ChannelOutboundHandler extends ChannelHandler {
24      /**
25       * Called once a bind operation is made.
26       *
27       * @param ctx           the {@link ChannelHandlerContext} for which the bind operation is made
28       * @param localAddress  the {@link SocketAddress} to which it should bound
29       * @param promise       the {@link ChannelPromise} to notify once the operation completes
30       * @throws Exception    thrown if an error occurs
31       */
32      void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception;
33  
34      /**
35       * Called once a connect operation is made.
36       *
37       * @param ctx               the {@link ChannelHandlerContext} for which the connect operation is made
38       * @param remoteAddress     the {@link SocketAddress} to which it should connect
39       * @param localAddress      the {@link SocketAddress} which is used as source on connect
40       * @param promise           the {@link ChannelPromise} to notify once the operation completes
41       * @throws Exception        thrown if an error occurs
42       */
43      void connect(
44              ChannelHandlerContext ctx, SocketAddress remoteAddress,
45              SocketAddress localAddress, ChannelPromise promise) throws Exception;
46  
47      /**
48       * Called once a disconnect operation is made.
49       *
50       * @param ctx               the {@link ChannelHandlerContext} for which the disconnect operation is made
51       * @param promise           the {@link ChannelPromise} to notify once the operation completes
52       * @throws Exception        thrown if an error occurs
53       */
54      void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;
55  
56      /**
57       * Called once a close operation is made.
58       *
59       * @param ctx               the {@link ChannelHandlerContext} for which the close operation is made
60       * @param promise           the {@link ChannelPromise} to notify once the operation completes
61       * @throws Exception        thrown if an error occurs
62       */
63      void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;
64  
65      /**
66       * Called once a deregister operation is made from the current registered {@link EventLoop}.
67       *
68       * @param ctx               the {@link ChannelHandlerContext} for which the close operation is made
69       * @param promise           the {@link ChannelPromise} to notify once the operation completes
70       * @throws Exception        thrown if an error occurs
71       */
72      void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;
73  
74      /**
75       * Intercepts {@link ChannelHandlerContext#read()}.
76       */
77      void read(ChannelHandlerContext ctx) throws Exception;
78  
79      /**
80      * Called once a write operation is made. The write operation will write the messages through the
81       * {@link ChannelPipeline}. Those are then ready to be flushed to the actual {@link Channel} once
82       * {@link Channel#flush()} is called
83       *
84       * @param ctx               the {@link ChannelHandlerContext} for which the write operation is made
85       * @param msg               the message to write
86       * @param promise           the {@link ChannelPromise} to notify once the operation completes
87       * @throws Exception        thrown if an error occurs
88       */
89      void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception;
90  
91      /**
92       * Called once a flush operation is made. The flush operation will try to flush out all previous written messages
93       * that are pending.
94       *
95       * @param ctx               the {@link ChannelHandlerContext} for which the flush operation is made
96       * @throws Exception        thrown if an error occurs
97       */
98      void flush(ChannelHandlerContext ctx) throws Exception;
99  }