本文整理汇总了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);
}