当前位置: 首页>>代码示例>>Java>>正文


Java Future.addListener方法代码示例

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

	}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:34,代码来源:PoolTest.java

示例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();
        }
    });
}
 
开发者ID:airlift,项目名称:drift,代码行数:10,代码来源:ConnectionPool.java

示例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 ();
        }
    } );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:28,代码来源:Client.java

示例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));
    }
}
 
开发者ID:bitkylin,项目名称:ClusterDeviceControlPlatform,代码行数:8,代码来源:NettyServer.java

示例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));
    }
}
 
开发者ID:bitkylin,项目名称:ClusterDeviceControlPlatform,代码行数:7,代码来源:NettyClient.java

示例6: NettyCompletableFuture

import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
private NettyCompletableFuture(Future<T> future) {
  future.addListener(this);
}
 
开发者ID:HubSpot,项目名称:NioImapClient,代码行数:4,代码来源:NettyCompletableFuture.java


注:本文中的io.netty.util.concurrent.Future.addListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。