List of usage examples for io.netty.channel ChannelFuture awaitUninterruptibly
@Override ChannelFuture awaitUninterruptibly();
From source file:snapchatproto.servers.management.OutboundMgmtWorker.java
License:Apache License
@Override public void run() { while (true) { if (!forever && ManagementQueue.outbound.size() == 0) break; try {//from w w w.j a v a2 s.c o m // block until a message is enqueued ManagementQueueEntry msg = ManagementQueue.outbound.take(); if (logger.isDebugEnabled()) logger.debug( "Outbound management message routing to node " + msg.req.getRaftHeader().getToNode()); if (msg.channel.isWritable()) { boolean rtn = false; if (msg.channel != null && msg.channel.isOpen() && msg.channel.isWritable()) { ChannelFuture cf = msg.channel.write(msg); // blocks on write - use listener to be async cf.awaitUninterruptibly(); rtn = cf.isSuccess(); if (!rtn) ManagementQueue.outbound.putFirst(msg); } } else { logger.info("channel to node " + msg.req.getRaftHeader().getToNode() + " is not writable"); ManagementQueue.outbound.putFirst(msg); } } catch (InterruptedException ie) { break; } catch (Exception e) { logger.error("Unexpected management communcation failure", e); break; } } if (!forever) { logger.info("management outbound queue closing"); } }
From source file:snapchatproto.servers.queue.OutboundAppWorker.java
License:Apache License
@Override public void run() { while (true) { if (!forever && DiscreteQueue.outbound.size() == 0) break; try {/*from www .j a v a2 s . c o m*/ // block until a message is enqueued OneQueueEntry msg = DiscreteQueue.outbound.take(); if (msg.channel.isWritable()) { boolean rtn = false; if (msg.channel != null && msg.channel.isOpen() && msg.channel.isWritable()) { ChannelFuture cf = msg.channel.writeAndFlush(msg); // blocks on write - use listener to be async cf.awaitUninterruptibly(); rtn = cf.isSuccess(); if (!rtn) DiscreteQueue.outbound.putFirst(msg); } } else DiscreteQueue.outbound.putFirst(msg); } catch (InterruptedException ie) { break; } catch (Exception e) { logger.error("Unexpected communcation failure", e); break; } } if (!forever) { logger.info("connection queue closing"); } }
From source file:subterranean.crimson.permajar.stage1.network.Communications.java
License:Open Source License
public static synchronized boolean connect(final String HOST, final int PORT, final boolean SSL) { if (SSL) {/* w ww. j a va 2 s. c o m*/ Logger.add("Making SSL Connection attempt"); } else { Logger.add("Making Connection attempt"); } handler = new Handler(); if (SSL) { try { sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE); } catch (SSLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { sslCtx = null; } EventLoopGroup group = new NioEventLoopGroup(); Bootstrap b = new Bootstrap(); b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Environment.reportTimeout); b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) { if (sslCtx != null) { ch.pipeline().addLast(sslCtx.newHandler(ch.alloc(), HOST, PORT)); } ch.pipeline().addLast(new ObjectEncoder(), new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)), handler); } }); ChannelFuture future = b.connect(new InetSocketAddress(HOST, PORT)); if (!future.awaitUninterruptibly().isSuccess()) { group.shutdownGracefully(); return false; } c = future.channel(); try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return c.isWritable(); }
From source file:tk.jomp16.rcon.internal.RconServer.java
License:Open Source License
/** * Starts the RconServer instance/*from w w w. ja v a2 s. co m*/ */ public void startServer() { if (!this.canStartServer) { log.error("Cannot start Source RCON server!"); return; } new Thread(() -> { log.info("Starting Source RCON server..."); final ChannelFuture channelFuture = this.serverBootstrap.bind(this.host, this.port); channelFuture.awaitUninterruptibly(); if (channelFuture.isDone()) { if (channelFuture.isSuccess()) { log.info("Source RCON server started on ip " + this.host + " port " + this.port + "!"); channelFuture.channel().closeFuture().awaitUninterruptibly(); } else { log.error("Error starting Source RCON server!", channelFuture.cause()); this.bossGroup.shutdownGracefully(); this.workerGroup.shutdownGracefully(); } } }).start(); }