當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。