205 lines
9.2 KiB
Java
205 lines
9.2 KiB
Java
/*
|
|
* Copyright 2012 The Netty Project
|
|
*
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
* with the License. You may obtain a copy of the License at:
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
* License for the specific language governing permissions and limitations
|
|
* under the License.
|
|
*/
|
|
package io.netty.channel;
|
|
|
|
import java.net.ConnectException;
|
|
import java.net.SocketAddress;
|
|
|
|
/**
|
|
* Interface which is shared by others which need to execute outbound logic.
|
|
*/
|
|
interface ChannelOutboundInvoker {
|
|
|
|
/**
|
|
* Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
* completes, either because the operation was successful or because of an error.
|
|
* <p>
|
|
* This will result in having the
|
|
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
|
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
* {@link Channel}.
|
|
*/
|
|
ChannelFuture bind(SocketAddress localAddress);
|
|
|
|
/**
|
|
* Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
* completes, either because the operation was successful or because of an error.
|
|
* <p>
|
|
* If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
|
* a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
|
* will be used.
|
|
* <p>
|
|
* This will result in having the
|
|
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
* {@link Channel}.
|
|
*/
|
|
ChannelFuture connect(SocketAddress remoteAddress);
|
|
|
|
/**
|
|
* Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
|
|
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
* an error.
|
|
* <p>
|
|
* This will result in having the
|
|
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
* {@link Channel}.
|
|
*/
|
|
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress);
|
|
|
|
/**
|
|
* Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,
|
|
* either because the operation was successful or because of an error.
|
|
* <p>
|
|
* This will result in having the
|
|
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
* {@link Channel}.
|
|
*/
|
|
ChannelFuture disconnect();
|
|
|
|
/**
|
|
* Request to close this ChannelOutboundInvoker and notify the {@link ChannelFuture} once the operation completes,
|
|
* either because the operation was successful or because of
|
|
* an error.
|
|
*
|
|
* After it is closed it is not possible to reuse it again.
|
|
* <p>
|
|
* This will result in having the
|
|
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)}
|
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
* {@link Channel}.
|
|
*/
|
|
ChannelFuture close();
|
|
|
|
/**
|
|
* Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
* completes, either because the operation was successful or because of an error.
|
|
*
|
|
* The given {@link ChannelPromise} will be notified.
|
|
* <p>
|
|
* This will result in having the
|
|
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
|
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
* {@link Channel}.
|
|
*/
|
|
ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise);
|
|
|
|
/**
|
|
* Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
|
* completes, either because the operation was successful or because of an error.
|
|
*
|
|
* The given {@link ChannelFuture} will be notified.
|
|
*
|
|
* <p>
|
|
* If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
|
* a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
|
* will be used.
|
|
* <p>
|
|
* This will result in having the
|
|
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
* {@link Channel}.
|
|
*/
|
|
ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise);
|
|
|
|
/**
|
|
* Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
|
|
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
|
* an error.
|
|
*
|
|
* The given {@link ChannelPromise} will be notified and also returned.
|
|
* <p>
|
|
* This will result in having the
|
|
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
* {@link Channel}.
|
|
*/
|
|
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise);
|
|
|
|
/**
|
|
* Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,
|
|
* either because the operation was successful or because of an error.
|
|
*
|
|
* The given {@link ChannelPromise} will be notified.
|
|
* <p>
|
|
* This will result in having the
|
|
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
* {@link Channel}.
|
|
*/
|
|
ChannelFuture disconnect(ChannelPromise promise);
|
|
|
|
/**
|
|
* Request to close this ChannelOutboundInvoker and notify the {@link ChannelFuture} once the operation completes,
|
|
* either because the operation was successful or because of
|
|
* an error.
|
|
*
|
|
* After it is closed it is not possible to reuse it again.
|
|
* The given {@link ChannelPromise} will be notified.
|
|
* <p>
|
|
* This will result in having the
|
|
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)}
|
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
* {@link Channel}.
|
|
*/
|
|
ChannelFuture close(ChannelPromise promise);
|
|
|
|
/**
|
|
* Request to Read data from the {@link Channel} into the first inbound buffer, triggers an
|
|
* {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)} event if data was
|
|
* read, and triggers a
|
|
* {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the
|
|
* handler can decide to continue reading. If there's a pending read operation already, this method does nothing.
|
|
* <p>
|
|
* This will result in having the
|
|
* {@link ChannelOutboundHandler#read(ChannelHandlerContext)}
|
|
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
|
|
* {@link Channel}.
|
|
*/
|
|
ChannelOutboundInvoker read();
|
|
|
|
/**
|
|
* Request to write a message via this ChannelOutboundInvoker through the {@link ChannelPipeline}.
|
|
* This method will not request to actual flush, so be sure to call {@link #flush()}
|
|
* once you want to request to flush all pending data to the actual transport.
|
|
*/
|
|
ChannelFuture write(Object msg);
|
|
|
|
/**
|
|
* Request to write a message via this ChannelOutboundInvoker through the {@link ChannelPipeline}.
|
|
* This method will not request to actual flush, so be sure to call {@link #flush()}
|
|
* once you want to request to flush all pending data to the actual transport.
|
|
*/
|
|
ChannelFuture write(Object msg, ChannelPromise promise);
|
|
|
|
/**
|
|
* Request to flush all pending messages via this ChannelOutboundInvoker.
|
|
*/
|
|
ChannelOutboundInvoker flush();
|
|
|
|
/**
|
|
* Shortcut for call {@link #write(Object, ChannelPromise)} and {@link #flush()}.
|
|
*/
|
|
ChannelFuture writeAndFlush(Object msg, ChannelPromise promise);
|
|
|
|
/**
|
|
* Shortcut for call {@link #write(Object)} and {@link #flush()}.
|
|
*/
|
|
ChannelFuture writeAndFlush(Object msg);
|
|
}
|