List of usage examples for io.netty.util.concurrent DefaultProgressivePromise DefaultProgressivePromise
public DefaultProgressivePromise(EventExecutor executor)
From source file:com.zextras.modules.chat.server.xmpp.netty.ChatXmppService.java
License:Open Source License
@SuppressWarnings("ConstantConditions") @Override//from w w w . j a v a 2 s.com public void start() throws ServiceStartException { mInitializationPromise = new DefaultProgressivePromise<Boolean>(ImmediateEventExecutor.INSTANCE); mThread = new Thread(this); mThread.start(); try { while (true) { if (mInitializationPromise.isDone()) { if (!mInitializationPromise.isSuccess()) { throw mInitializationPromise.cause(); } return; } Thread.yield(); } } catch (BindException ex) { throw new Service.ServiceStartException( "Cannot bind to ports 5222 and 5223: please make sure that no other process is bound to such ports in order to use any ZeXtras Chat XMPP feature.", ex); } catch (Throwable ex) { throw new Service.ServiceStartException(ex.getMessage(), ex); } }
From source file:com.zextras.modules.chat.server.xmpp.netty.TransparentProxy.java
License:Open Source License
public Future<Channel> connect() { final Promise<Channel> channelFuture = new DefaultProgressivePromise<Channel>( ImmediateEventExecutor.INSTANCE); if (mServerChannel == null) { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(mNettyService.getEventLoopGroup()).channel(NioSocketChannel.class) .remoteAddress(new InetSocketAddress(mAccount.getMailHost(), mPort)).handler(new Initializer()); ChannelFuture serverChannelFuture = bootstrap.connect(); serverChannelFuture.addListener(new ChannelFutureListener() { @Override/*ww w.j a v a 2s. c om*/ public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { ChatLog.log.info( "Proxy xmpp requests for " + mAccount.getName() + " to " + mAccount.getMailHost()); mServerChannel = future.channel(); mServerChannel.write(Unpooled.wrappedBuffer(mStreamInit.getBytes())); mServerChannel.writeAndFlush(Unpooled.wrappedBuffer(mInitialPayload.getBytes())); mServerChannel.pipeline().addLast("proxyToClient", new Proxy(mClientChannel)); mClientChannel.pipeline().addLast("proxyToServer", new Proxy(mServerChannel)); mServerChannel.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { mClientChannel.close(); } }); mClientChannel.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { mServerChannel.close(); } }); future.channel().closeFuture(); channelFuture.setSuccess(mServerChannel); } else { ChatLog.log.info("Cannot proxy xmpp requests for " + mAccount.getName() + " to " + mAccount.getMailHost() + ": " + Utils.exceptionToString(future.cause())); sendInternalError(mClientChannel); mClientChannel.flush().close(); channelFuture.setFailure(future.cause()); } } }); return channelFuture; } else { mServerChannel.pipeline().addLast("proxyToClient", new Proxy(mClientChannel)); mServerChannel.writeAndFlush(mInitialPayload.getBytes()); channelFuture.setSuccess(mServerChannel); return channelFuture; } }
From source file:com.zextras.modules.chat.services.LocalXmppService.java
License:Open Source License
@Override public void start() throws ServiceStartException { mInitializationPromise = new DefaultProgressivePromise<Void>(ImmediateEventExecutor.INSTANCE); mActivityManager.addActivity(this); try {//from w w w .j av a 2s . c o m while (true) { if (mInitializationPromise.isDone()) { if (!mInitializationPromise.isSuccess()) { throw mInitializationPromise.cause(); } return; } Thread.yield(); } } catch (Throwable ex) { throw new Service.ServiceStartException("Cannot bind to port " + DEFAULT_LOCAL_XMPP_PORT + ": please make sure that no other process is bound to such port.", ex); } }