Example usage for io.netty.channel ChannelFuture isSuccess

List of usage examples for io.netty.channel ChannelFuture isSuccess

Introduction

In this page you can find the example usage for io.netty.channel ChannelFuture isSuccess.

Prototype

boolean isSuccess();

Source Link

Document

Returns true if and only if the I/O operation was completed successfully.

Usage

From source file:com.friz.update.network.UpdateSessionContext.java

License:Open Source License

public void writeSuccess(int status) {
    channel.writeAndFlush(new UpdateResponseEvent(status)).addListener(new ChannelFutureListener() {
        @Override//from  www  .  ja  v a 2 s . c  om
        public void operationComplete(ChannelFuture future) throws Exception {
            if (future.isSuccess()) {
                ChannelPipeline p = future.channel().pipeline();
                p.remove(UpdateInitDecoder.class);
                p.remove(UpdateInitEncoder.class);

                p.addFirst(XorEncoder.class.getName(), new XorEncoder());
                p.addFirst(UpdateEncoder.class.getName(), new UpdateEncoder());
                p.addFirst(UpdateDecoder.class.getName(), new UpdateDecoder());

                handshakeComplete = true;
            }
        }
    });
}

From source file:com.github.lburgazzoli.quickfixj.transport.netty.NettyChannel.java

License:Apache License

/**
 *
 *//*from   w w  w.  j  a  va2 s  .  c  om*/
@Override
public boolean disconnect() {
    if (m_channel != null) {
        m_channel.disconnect().awaitUninterruptibly(5000L);

        ChannelFuture future = m_channel.close();
        future.awaitUninterruptibly();

        return future.isSuccess();
    }

    return true;
}

From source file:com.github.lburgazzoli.quickfixj.transport.netty.NettySocketInitiator.java

License:Apache License

/**
 *
 *///from w  w w .j  a va  2 s.  c  o m
private void doConnect() {
    ChannelFuture future = m_boot.connect();
    future.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) {
            if (future.isDone() && future.isSuccess()) {
                setChannel(new NettyChannel(future.channel()));
            } else if (!future.isSuccess() && !future.isCancelled()) {
                LOGGER.warn("Error", future.cause());
                doReconnect();
            }
        }
    });
}

From source file:com.github.mrstampy.gameboot.netty.NettyConnectionRegistry.java

License:Open Source License

private void log(ChannelFuture f, Object key) {
    if (f.isSuccess()) {
        log.debug("Successful send to {} on {}", key, f.channel());
    } else {/* w  w w.  j  a va 2 s  .co m*/
        log.error("Failed sending to {} on {}", key, f.channel(), f.cause());
    }
}

From source file:com.github.mrstampy.gameboot.otp.netty.OtpNettyTest.java

License:Open Source License

private void createClearChannel() throws InterruptedException {
    CountDownLatch cdl = new CountDownLatch(1);
    clientHandler.setResponseLatch(cdl);

    ChannelFuture cf = clearClient.connect(HOST, CLEAR_SERVER_PORT);
    cdl.await(5, TimeUnit.SECONDS);

    assertTrue(cf.isSuccess());
    clearChannel = cf.channel();//from  www. j av a  2  s  .  co  m

    assertNotNull(clientHandler.getSystemId());
    assertEquals(clearChannel, clientHandler.getClearChannel());
}

From source file:com.github.mrstampy.gameboot.otp.netty.OtpNettyTest.java

License:Open Source License

private void createEncryptedChannel() throws InterruptedException {
    ChannelFuture cf = encClient.connect(HOST, ENC_SERVER_PORT);
    cf.await(1, TimeUnit.SECONDS);

    assertTrue(cf.isSuccess());
    encChannel = cf.channel();/*from w w  w  .  ja v a 2s.  c  om*/
}

From source file:com.github.mrstampy.kitchensync.netty.Bootstrapper.java

License:Open Source License

/**
 * Returns a channel using the bootstrap for the specified port. Should none
 * exist then the default bootstrap is used.
 *
 * @param <CHANNEL>//from   ww  w  .j a va2 s  . c o  m
 *          the generic type
 * @param port
 *          the port
 * @return the channel
 */
@SuppressWarnings("unchecked")
public <CHANNEL extends DatagramChannel> CHANNEL bind(int port) {
    boolean contains = containsBootstrap(port);
    if (!contains && !hasDefaultBootstrap()) {
        log.error("Bootstrap for port {} not initialized", port);
        return null;
    }

    Bootstrap b = channelBootstraps.get(contains ? port : DEFAULT_BOOTSTRAP_KEY);

    ChannelFuture cf = b.bind(port);

    CountDownLatch latch = new CountDownLatch(1);
    cf.addListener(getBindListener(port, latch));

    await(latch, "Channel creation timed out");

    return cf.isSuccess() ? (CHANNEL) cf.channel() : null;
}

From source file:com.github.mrstampy.kitchensync.netty.Bootstrapper.java

License:Open Source License

/**
 * Bind to the specified multicast address.
 *
 * @param <CHANNEL>/*from w ww .  j a v  a  2  s .  co m*/
 *          the generic type
 * @param multicast
 *          the multicast
 * @return the channel
 */
@SuppressWarnings("unchecked")
public <CHANNEL extends DatagramChannel> CHANNEL multicastBind(InetSocketAddress multicast) {
    String key = createMulticastKey(multicast);
    if (!containsMulticastBootstrap(key)) {
        log.error("Multicast bootstrap for {} not initialized", multicast);
        return null;
    }

    Bootstrap b = multicastBootstraps.get(key);

    ChannelFuture cf = b.bind();

    CountDownLatch latch = new CountDownLatch(1);
    cf.addListener(getMulticastBindListener(multicast, latch));

    await(latch, "Multicast channel creation timed out");

    return cf.isSuccess() ? (CHANNEL) cf.channel() : null;
}

From source file:com.github.mrstampy.kitchensync.netty.Bootstrapper.java

License:Open Source License

private GenericFutureListener<ChannelFuture> getBindListener(final int port, final CountDownLatch latch) {
    return new GenericFutureListener<ChannelFuture>() {

        @Override//w w w  .  j a  v  a2 s .co  m
        public void operationComplete(ChannelFuture future) throws Exception {
            try {
                if (future.isSuccess()) {
                    log.debug("Channel creation successful for {}", future.channel());
                } else {
                    Throwable cause = future.cause();
                    if (cause == null) {
                        log.error("Could not create channel for {}", port);
                    } else {
                        log.error("Could not create channel for {}", port, cause);
                    }
                }
            } finally {
                latch.countDown();
            }
        }
    };
}

From source file:com.github.mrstampy.kitchensync.netty.Bootstrapper.java

License:Open Source License

private GenericFutureListener<ChannelFuture> getMulticastBindListener(final InetSocketAddress multicast,
        final CountDownLatch latch) {
    return new GenericFutureListener<ChannelFuture>() {

        @Override//from  ww w .  j  ava 2s.c om
        public void operationComplete(ChannelFuture future) throws Exception {
            try {
                if (future.isSuccess()) {
                    log.debug("Multicast channel creation successful for {}", multicast);
                } else {
                    Throwable cause = future.cause();
                    if (cause == null) {
                        log.error("Could not create multicast channel for {}", multicast);
                    } else {
                        log.error("Could not create multicast channel for {}", multicast, cause);
                    }
                }
            } finally {
                latch.countDown();
            }
        }
    };
}