本文整理匯總了Java中io.netty.util.concurrent.Future.addListener方法的典型用法代碼示例。如果您正苦於以下問題:Java Future.addListener方法的具體用法?Java Future.addListener怎麽用?Java Future.addListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.util.concurrent.Future
的用法示例。
在下文中一共展示了Future.addListener方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
public static void main(String[] args) {
EventLoopGroup group = new NioEventLoopGroup();
final Bootstrap cb = new Bootstrap();
cb.group(group).channel(NioSocketChannel.class);
InetSocketAddress addr1 = new InetSocketAddress("10.0.0.10", 8888);
InetSocketAddress addr2 = new InetSocketAddress("10.0.0.11", 8888);
//連接池map
ChannelPoolMap<InetSocketAddress, SimpleChannelPool> poolMap = new AbstractChannelPoolMap<InetSocketAddress, SimpleChannelPool>() {
@Override
protected SimpleChannelPool newPool(InetSocketAddress key) {
return new SimpleChannelPool(cb.remoteAddress(key), new TestChannelPoolHandler());
}
};
final SimpleChannelPool pool1 = poolMap.get(addr1);//取出連接addr1地址的連接池
final SimpleChannelPool pool2 = poolMap.get(addr2);//取出連接addr2地址的連接池
Future<Channel> f1 = pool1.acquire();//獲取一個連接
f1.addListener(new FutureListener<Channel>() {
@Override
public void operationComplete(Future<Channel> f) {
if (f.isSuccess()) {
Channel ch = f.getNow();
//連接地址1的某個channel
//使用連接發送消息
// ch.write(msg)
//用完釋放
pool1.release(ch);
}
}
});
}
示例2: closeConnection
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
private static void closeConnection(Future<Channel> future)
{
future.addListener(ignored -> {
if (future.isSuccess()) {
Channel channel = future.getNow();
channel.close();
}
});
}
示例3: close
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public void close () throws Exception
{
synchronized ( this )
{
if ( this.channel != null )
{
this.channel.close ();
this.channel = null;
}
for ( final Module module : this.modules )
{
module.dispose ();
}
}
logger.debug ( "Shutting down main group" );
final Future<?> f = this.group.shutdownGracefully ();
f.addListener ( new GenericFutureListener<Future<Object>> () {
@Override
public void operationComplete ( final Future<Object> arg0 ) throws Exception
{
disposeExecutor ();
}
} );
}
示例4: shutdown
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public void shutdown() {
if (group != null) {
Future<?> futureShutdown = group.shutdownGracefully();
futureShutdown.addListener(future -> startListenerHandle(future, finishListener));
}
}
示例5: shutdown
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
public void shutdown() {
if (group != null) {
Future<?> futureShutdown = group.shutdownGracefully();
futureShutdown.addListener(future -> startListenerHandle(future, finishListener));
}
}
示例6: NettyCompletableFuture
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
private NettyCompletableFuture(Future<T> future) {
future.addListener(this);
}