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


Java ChannelGroupFuture类代码示例

本文整理汇总了Java中io.netty.channel.group.ChannelGroupFuture的典型用法代码示例。如果您正苦于以下问题:Java ChannelGroupFuture类的具体用法?Java ChannelGroupFuture怎么用?Java ChannelGroupFuture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChannelGroupFuture类属于io.netty.channel.group包,在下文中一共展示了ChannelGroupFuture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doStop

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
@Override
protected void doStop() {
    try {
        ChannelGroupFuture f = allChannels.close();
        f.addListener(new ChannelGroupFutureListener() {
            @Override
            public void operationComplete(ChannelGroupFuture future) throws Exception {
                if (future.isSuccess()) {
                    notifyStopped();
                } else {
                    notifyFailed(future.cause());
                }
            }
        });
    } catch (Throwable t) {
        notifyFailed(t);
        Throwables.propagate(t);
    }
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:20,代码来源:RpcServer.java

示例2: close

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
@Override
public ChannelGroupFuture close() {
    this.lock.writeLock().lock();
    try {
        if (!this.closed.getAndSet(true)) {
            // First time close() is called.
            return super.close();
        } else {
            // FIXME DefaultChannelGroupFuture is package protected
            // Collection<ChannelFuture> futures = new ArrayList<>();
            // logger.debug("CleanupChannelGroup already closed");
            // return new DefaultChannelGroupFuture(ChannelGroup.class.cast(this), futures,
            // GlobalEventExecutor.INSTANCE);
            throw new UnsupportedOperationException("CleanupChannelGroup already closed");
        }
    } finally {
        this.lock.writeLock().unlock();
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:20,代码来源:CleanupChannelGroup.java

示例3: closeAllChannels

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
/**
 * Closes all channels opened by this proxy server.
 *
 * @param graceful when false, attempts to shutdown all channels immediately and ignores any channel-closing exceptions
 */
protected void closeAllChannels(boolean graceful) {
    LOG.info("Closing all channels " + (graceful ? "(graceful)" : "(non-graceful)"));

    ChannelGroupFuture future = allChannels.close();

    // if this is a graceful shutdown, log any channel closing failures. if this isn't a graceful shutdown, ignore them.
    if (graceful) {
        try {
            future.await(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();

            LOG.warn("Interrupted while waiting for channels to shut down gracefully.");
        }

        if (!future.isSuccess()) {
            for (ChannelFuture cf : future) {
                if (!cf.isSuccess()) {
                    LOG.info("Unable to close channel.  Cause of failure for {} is {}", cf.channel(), cf.cause());
                }
            }
        }
    }
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:30,代码来源:DefaultHttpProxyServer.java

示例4: stop

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
/**
 * Stop proxy server
 * */
public void stop() {
  ChannelGroupFuture future = _allChannels.close().awaitUninterruptibly();
  if (!future.isSuccess()) {
    final Iterator<ChannelFuture> iter = future.iterator();
    while (iter.hasNext()) {
      final ChannelFuture cf = iter.next();
      if (!cf.isSuccess()) {
        LOG.warn(String.format("Failed to close channel %s because %s", cf.channel(), cf.cause()));
      }
    }
  }
  _acceptorGroup.shutdownGracefully();
  _upstreamWorkerGroup.shutdownGracefully();
  _downstreamWorkerGroup.shutdownGracefully();
}
 
开发者ID:linkedin,项目名称:flashback,代码行数:19,代码来源:ProxyServer.java

示例5: close

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
public ChannelGroupFuture close() {
  EventLoopGroup eventLoopGroup = null;
  for (Channel channel : openChannels) {
    if (channel instanceof ServerChannel) {
      eventLoopGroup = channel.eventLoop().parent();
      break;
    }
  }

  ChannelGroupFuture future;
  try {
    future = openChannels.close();
  }
  finally {
    assert eventLoopGroup != null;
    eventLoopGroup.shutdownGracefully(0, 15, TimeUnit.SECONDS);
  }
  return future;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ExternalJavacManager.java

示例6: doStop

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
@Override
protected void doStop() throws Exception {
    LOG.debug("Stopping producer at address: {}", configuration.getAddress());
    // close all channels
    LOG.trace("Closing {} channels", allChannels.size());
    ChannelGroupFuture future = allChannels.close();
    future.awaitUninterruptibly();

    // and then shutdown the thread pools
    if (workerGroup != null) {
        workerGroup.shutdownGracefully();
        workerGroup = null;
    }

    if (pool != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Stopping producer with channel pool[active={}, idle={}]", pool.getNumActive(), pool.getNumIdle());
        }
        pool.close();
        pool = null;
    }

    super.doStop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:NettyProducer.java

示例7: sendToGroup

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
/**
 * Send to group.
 *
 * @param groupName
 *          the group key
 * @param message
 *          the message
 * @param matcher
 *          the matcher
 * @param listeners
 *          the listeners
 */
public void sendToGroup(String groupName, byte[] message, ChannelMatcher matcher,
    ChannelFutureListener... listeners) {
  groupCheck(groupName);
  checkMessage(message);

  if (!groups.containsKey(groupName)) {
    log.warn("No group {} to send message {}", groupName, message);
    return;
  }

  ChannelGroup group = groups.get(groupName);

  ChannelFutureListener[] all = utils.prependArray(f -> log((ChannelGroupFuture) f, groupName), listeners);
  ChannelGroupFuture cf = group.writeAndFlush(message, matcher);
  cf.addListeners(all);
}
 
开发者ID:mrstampy,项目名称:gameboot,代码行数:29,代码来源:NettyConnectionRegistry.java

示例8: pause

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
@Override
public synchronized void pause() {
   if (paused) {
      return;
   }

   if (channelClazz == null) {
      return;
   }

   // We *pause* the acceptor so no new connections are made
   if (serverChannelGroup != null) {
      ChannelGroupFuture future = serverChannelGroup.close().awaitUninterruptibly();
      if (!future.isSuccess()) {
         ActiveMQServerLogger.LOGGER.nettyChannelGroupBindError();
         for (Channel channel : future.group()) {
            if (channel.isActive()) {
               ActiveMQServerLogger.LOGGER.nettyChannelStillBound(channel, channel.remoteAddress());
            }
         }
      }
   }
   paused = true;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:25,代码来源:NettyAcceptor.java

示例9: completable

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
public static CompletableFuture<Void> completable(ChannelGroupFuture future) {
  CompletableFuture<Void> cf = new CompletableFuture<>();
  future.addListener(
      (ChannelGroupFutureListener)
          future1 -> {
            if (future1.isSuccess()) {
              cf.complete(null);
            } else {
              cf.completeExceptionally(future1.cause());
            }
          });
  return cf;
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:14,代码来源:ChannelUtils.java

示例10: shutdownAsync

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
public ChannelGroupFuture shutdownAsync() {
    for (Channel channel : channels) {
        RedisConnection connection = RedisConnection.getFrom(channel);
        if (connection != null) {
            connection.setClosed(true);
        }
    }
    return channels.close();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:10,代码来源:RedisClient.java

示例11: closeAllChannels

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
/**
 * 关闭所有channel
 * 
 * @return
 */
public ChannelGroupFuture closeAllChannels() {
	if (channels != null && channels.size() > 0) {
		return channels.close();
	}
	return null;
}
 
开发者ID:maofw,项目名称:netty_push_server,代码行数:12,代码来源:ApplicationContext.java

示例12: main

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        final Bootstrap bootstrap = new Bootstrap();
        bootstrap.option(ChannelOption.TCP_NODELAY,true);
		bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000);
        bootstrap.handler(new ChannelInitializer<Channel>() {
			@Override
			protected void initChannel(Channel ch) throws Exception {
				ChannelPipeline p = ch.pipeline();
				 p.addLast("handshaker", new ServerHandshakeHandler());
			     p.addLast("decoder", new RtmpDecoder());
			     p.addLast("encoder", new RtmpEncoder());
			     p.addLast("handler", new ServerHandler());
			}
		});
        
        
        
        final InetSocketAddress socketAddress = new InetSocketAddress(RtmpConfig.SERVER_PORT);
        bootstrap.bind(socketAddress);
        logger.info("server started, listening on: {}", socketAddress);

        final Thread monitor = new StopMonitor(RtmpConfig.SERVER_STOP_PORT);
        monitor.start();        
        monitor.join();
        TIMER.stop();
        final ChannelGroupFuture future = CHANNELS.close();
        logger.info("closing channels");
        future.awaitUninterruptibly();
        logger.info("releasing resources");
        logger.info("server stopped");

    }
 
开发者ID:diohpix,项目名称:flazr-fork,代码行数:34,代码来源:RtmpServer.java

示例13: close

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
/**
 * Closes all channels and releases all resources.
 */
@Override
public void close() {

  LOG.log(Level.FINE, "Closing netty transport socket address: {0}", this.localAddress);

  final ChannelGroupFuture clientChannelGroupFuture = this.clientChannelGroup.close();
  final ChannelGroupFuture serverChannelGroupFuture = this.serverChannelGroup.close();
  final ChannelFuture acceptorFuture = this.acceptor.close();

  final ArrayList<Future> eventLoopGroupFutures = new ArrayList<>(3);
  eventLoopGroupFutures.add(this.clientWorkerGroup.shutdownGracefully());
  eventLoopGroupFutures.add(this.serverBossGroup.shutdownGracefully());
  eventLoopGroupFutures.add(this.serverWorkerGroup.shutdownGracefully());

  clientChannelGroupFuture.awaitUninterruptibly();
  serverChannelGroupFuture.awaitUninterruptibly();

  try {
    acceptorFuture.sync();
  } catch (final Exception ex) {
    LOG.log(Level.SEVERE, "Error closing the acceptor channel for " + this.localAddress, ex);
  }

  for (final Future eventLoopGroupFuture : eventLoopGroupFutures) {
    eventLoopGroupFuture.awaitUninterruptibly();
  }

  LOG.log(Level.FINE, "Closing netty transport socket address: {0} done", this.localAddress);
}
 
开发者ID:apache,项目名称:reef,代码行数:33,代码来源:NettyMessagingTransport.java

示例14: shutdown

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
/**
 * Shutdown this channel creator. This means that no TCP or UDP connection can be established.
 * 
 * @return The shutdown future.
 */
public FutureDone<Void> shutdown() {
    // set shutdown flag for UDP and TCP, if we acquire a write lock, all read locks are blocked as well
    writeUDP.lock();
    writeTCP.lock();
    try {
        if (shutdownTCP || shutdownUDP) {
            shutdownFuture().setFailed("already shutting down");
            return shutdownFuture();
        }
        shutdownUDP = true;
        shutdownTCP = true;
    } finally {
        writeTCP.unlock();
        writeUDP.unlock();
    }

    recipients.close().addListener(new GenericFutureListener<ChannelGroupFuture>() {
        @Override
        public void operationComplete(final ChannelGroupFuture future) throws Exception {
            if (!semaphoreUPD.tryAcquire(maxPermitsUDP)) {
                LOG.error("Cannot shutdown, as connections (UDP) are still alive");
                shutdownFuture().setFailed("Cannot shutdown, as connections (UDP) are still alive");
                throw new RuntimeException("Cannot shutdown, as connections (UDP) are still alive");
            }
            if (!semaphoreTCP.tryAcquire(maxPermitsTCP)) {
                LOG.error("Cannot shutdown, as connections (TCP) are still alive");
                shutdownFuture().setFailed("Cannot shutdown, as connections (TCP) are still alive");
                throw new RuntimeException("Cannot shutdown, as connections (TCP) are still alive");
            }
            shutdownFuture().setDone();
        }
    });
    return shutdownFuture();
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:40,代码来源:ChannelCreator.java

示例15: writeGroup

import io.netty.channel.group.ChannelGroupFuture; //导入依赖的package包/类
public ChannelGroupFuture writeGroup(OutMessage message) {
    message.setH(handlerName);
    if (chanelGroup != null) {
        return chanelGroup.write(message);
    }
    return null;
}
 
开发者ID:bupt1987,项目名称:JgFramework,代码行数:8,代码来源:BaseHandlerChannel.java


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