Example usage for io.netty.channel ChannelFuture cause

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

Introduction

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

Prototype

Throwable cause();

Source Link

Document

Returns the cause of the failed I/O operation if the I/O operation has failed.

Usage

From source file:org.opendaylight.controller.netconf.client.NetconfClientSessionNegotiator.java

License:Open Source License

/**
 * Initiates exi communication by sending start-exi message and waiting for positive/negative response.
 *
 * @param startExiMessage//  w w  w  .j  a  v  a 2  s.c o m
 */
void tryToInitiateExi(final NetconfClientSession session, final NetconfStartExiMessage startExiMessage) {
    channel.pipeline().addAfter(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER,
            ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER,
            new ExiConfirmationInboundHandler(session, startExiMessage));

    session.sendMessage(startExiMessage).addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(final ChannelFuture f) {
            if (!f.isSuccess()) {
                LOG.warn("Failed to send start-exi message {} on session {}", startExiMessage, this, f.cause());
                channel.pipeline().remove(ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER);
            } else {
                LOG.trace("Start-exi message {} sent to socket on session {}", startExiMessage, this);
            }
        }
    });
}

From source file:org.opendaylight.netconf.nettyutil.AbstractNetconfSession.java

License:Open Source License

@Override
public ChannelFuture sendMessage(final NetconfMessage netconfMessage) {
    // From: https://github.com/netty/netty/issues/3887
    // Netty can provide "ordering" in the following situations:
    // 1. You are doing all writes from the EventLoop thread; OR
    // 2. You are doing no writes from the EventLoop thread (i.e. all writes are being done in other thread(s)).
    ////from   w w  w  . j a  v a 2s .co  m
    // Restconf writes to a netconf mountpoint execute multiple messages
    // and one of these was executed from a restconf thread thus breaking ordering so
    // we need to execute all messages from an EventLoop thread.
    final DefaultChannelPromise proxyFuture = new DefaultChannelPromise(channel);
    channel.eventLoop().execute(new Runnable() {
        @Override
        public void run() {
            final ChannelFuture future = channel.writeAndFlush(netconfMessage);
            future.addListener(new FutureListener<Void>() {
                @Override
                public void operationComplete(Future<Void> future) throws Exception {
                    if (future.isSuccess()) {
                        proxyFuture.setSuccess();
                    } else {
                        proxyFuture.setFailure(future.cause());
                    }
                }
            });
            if (delayedEncoder != null) {
                replaceMessageEncoder(delayedEncoder);
                delayedEncoder = null;
            }
        }
    });

    return proxyFuture;
}

From source file:org.opendaylight.protocol.bgp.rib.impl.AbstractBGPSessionNegotiator.java

License:Open Source License

private void sendMessage(final Notification msg) {
    this.channel.writeAndFlush(msg).addListener(new ChannelFutureListener() {
        @Override/*w ww.  j a  v  a 2  s.  c  o m*/
        public void operationComplete(final ChannelFuture f) {
            if (!f.isSuccess()) {
                LOG.warn("Failed to send message {} to channel {}", msg,
                        AbstractBGPSessionNegotiator.this.channel, f.cause());
                negotiationFailedCloseChannel(f.cause());
            } else {
                LOG.trace("Message {} sent to channel {}", msg, AbstractBGPSessionNegotiator.this.channel);
            }
        }
    });
}

From source file:org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImplTest.java

License:Open Source License

private Channel createServer(final InetSocketAddress serverAddress) throws InterruptedException {
    this.serverListener = new SimpleSessionListener();
    this.registry.addPeer(new IpAddress(new Ipv4Address(serverAddress.getAddress().getHostAddress())),
            this.serverListener, createPreferences(serverAddress));
    LoggerFactory.getLogger(BGPDispatcherImplTest.class).info("createServer");
    final ChannelFuture future = this.serverDispatcher.createServer(this.registry, serverAddress);
    future.addListener(new GenericFutureListener<Future<Void>>() {
        @Override/*w  w w .j a  v a  2s.  co  m*/
        public void operationComplete(final Future<Void> future) {
            Preconditions.checkArgument(future.isSuccess(), "Unable to start bgp server on %s", future.cause());
        }
    });
    waitFutureSuccess(future);
    return future.channel();
}

From source file:org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl.java

License:Open Source License

@GuardedBy("this")
private ChannelFuture writeEpilogue(final ChannelFuture future, final Notification msg) {
    future.addListener(new ChannelFutureListener() {
        @Override/* w w  w .j  a  v  a2 s  .  co  m*/
        public void operationComplete(final ChannelFuture f) {
            if (!f.isSuccess()) {
                LOG.warn("Failed to send message {} to socket {}", msg, BGPSessionImpl.this.channel, f.cause());
            } else {
                LOG.trace("Message {} sent to socket {}", msg, BGPSessionImpl.this.channel);
            }
        }
    });
    this.lastMessageSentAt = System.nanoTime();
    this.sessionStats.updateSentMsg(msg);
    return future;
}

From source file:org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl.java

License:Open Source License

private synchronized void closeWithoutMessage() {
    if (this.state == State.IDLE) {
        return;/*from  w  w  w .  ja  v a  2 s.co m*/
    }
    LOG.info("Closing session: {}", this);
    removePeerSession();
    this.channel.close().addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(final ChannelFuture future) throws Exception {
            Preconditions.checkArgument(future.isSuccess(), "Channel failed to close: %s", future.cause());
        }
    });
    this.state = State.IDLE;
}

From source file:org.opendaylight.protocol.framework.AbstractSessionNegotiator.java

License:Open Source License

/**
 * Send a message to peer and fail negotiation if it does not reach
 * the peer./*from  www  .  ja v a2 s  . c  o  m*/
 *
 * @param msg Message which should be sent.
 */
protected final void sendMessage(final M msg) {
    this.channel.writeAndFlush(msg).addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(final ChannelFuture f) {
            if (!f.isSuccess()) {
                LOG.info("Failed to send message {}", msg, f.cause());
                negotiationFailed(f.cause());
            } else {
                LOG.trace("Message {} sent to socket", msg);
            }
        }
    });
}

From source file:org.opendaylight.protocol.pcep.impl.AbstractSessionNegotiator.java

License:Open Source License

protected final void sendMessage(final Message msg) {
    this.channel.writeAndFlush(msg).addListener(new ChannelFutureListener() {
        @Override/* ww w  .j  a va  2s  .  c o m*/
        public void operationComplete(final ChannelFuture f) {
            if (!f.isSuccess()) {
                LOG.info("Failed to send message {}", msg, f.cause());
                negotiationFailed(f.cause());
            } else {
                LOG.trace("Message {} sent to socket", msg);
            }

        }
    });
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPByteToMessageDecoder.java

License:Open Source License

@Override
protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) {
    if (!in.isReadable()) {
        LOG.debug("No more content in incoming buffer.");
        return;/* w w w .j  av  a2  s  . c o m*/
    }

    in.markReaderIndex();
    LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));

    final List<Message> errors = new ArrayList<>();

    try {
        out.add(parse(in, errors));
    } catch (final PCEPDeserializerException e) {
        LOG.debug("Failed to decode protocol message", e);
    }
    in.discardReadBytes();

    if (!errors.isEmpty()) {
        // We have a bunch of messages, send them out
        for (final Object e : errors) {
            ctx.channel().writeAndFlush(e).addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(final ChannelFuture f) {
                    if (!f.isSuccess()) {
                        LOG.warn("Failed to send message {} to socket {}", e, ctx.channel(), f.cause());
                    } else {
                        LOG.trace("Message {} sent to socket {}", e, ctx.channel());
                    }
                }
            });
        }
    }
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPSessionImpl.java

License:Open Source License

/**
 * Sends message to serialization.//from  w ww  .  j a v a2 s. co m
 *
 * @param msg to be sent
 */
@Override
public Future<Void> sendMessage(final Message msg) {
    final ChannelFuture f = this.channel.writeAndFlush(msg);
    this.lastMessageSentAt = System.nanoTime();
    this.sessionState.updateLastSentMsg();
    if (!(msg instanceof KeepaliveMessage)) {
        LOG.debug("PCEP Message enqueued: {}", msg);
    }
    if (msg instanceof PcerrMessage) {
        this.sessionState.setLastSentError(msg);
    }

    f.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(final ChannelFuture arg) {
            if (arg.isSuccess()) {
                LOG.trace("Message sent to socket: {}", msg);
            } else {
                LOG.debug("Message not sent: {}", msg, arg.cause());
            }
        }
    });

    return f;
}