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