Example usage for io.netty.channel ChannelFutureListener ChannelFutureListener

List of usage examples for io.netty.channel ChannelFutureListener ChannelFutureListener

Introduction

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

Prototype

ChannelFutureListener

Source Link

Usage

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//from  w ww. jav a2s  . co  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.BGPSessionImpl.java

License:Open Source License

@GuardedBy("this")
private ChannelFuture writeEpilogue(final ChannelFuture future, final Notification msg) {
    future.addListener(new ChannelFutureListener() {
        @Override/*from  w ww .jav a 2  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  .  j  av  a2s .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.bmp.impl.app.BmpMonitoringStationImpl.java

License:Open Source License

@Override
public void close() throws Exception {
    this.channel.close().addListener(new ChannelFutureListener() {
        @Override/*from ww  w  .  j  a  va  2s.c om*/
        public void operationComplete(final ChannelFuture channelFuture) throws Exception {
            BmpMonitoringStationImpl.this.sessionManager.close();
        }
    }).await();

    final DOMDataWriteTransaction wTx = this.domDataBroker.newWriteOnlyTransaction();
    wTx.delete(LogicalDatastoreType.OPERATIONAL, this.yangMonitorId);
    wTx.submit().checkedGet();
    LOG.info("BMP monitoring station {} closed.", this.monitorId.getValue());
}

From source file:org.opendaylight.protocol.bmp.mock.BmpMockSession.java

License:Open Source License

@Override
public void channelActive(final ChannelHandlerContext ctx) {
    this.channel = ctx.channel();
    this.channel.closeFuture().addListener(new ChannelFutureListener() {
        @Override//w  w  w  . j a  va2 s  .c o  m
        public void operationComplete(final ChannelFuture future) throws Exception {
            LOG.info("BMP session {} final successfully established.", BmpMockSession.this.channel);
        }
    });
    LOG.info("BMP session {} successfully established.", this.channel);
    final InetSocketAddress localAddress = (InetSocketAddress) this.channel.localAddress();
    this.remoteAddress = (InetSocketAddress) this.channel.remoteAddress();
    advertizePeers(this.channel, localAddress);
}

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   w w w  .j a v a 2 s.com*/
 *
 * @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.AbstractPCEPSessionNegotiator.java

License:Open Source License

@Override
protected final void startNegotiation() {
    Preconditions.checkState(this.state == State.IDLE);
    if (this.tlsConfiguration != null) {
        this.sendMessage(
                new StarttlsBuilder().setStartTlsMessage(new StartTlsMessageBuilder().build()).build());
        this.state = State.START_TLS_WAIT;
        scheduleFailTimer();/*from  w  w  w. ja  va 2  s  .  c  om*/
        LOG.info("Started TLS connection negotiation with peer {}", this.channel);
    } else {
        startNegotiationWithOpen();
    }
    this.channel.closeFuture().addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(final ChannelFuture f) {
            cancelTimers();
        }
    });
}

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//w  ww.j  av  a 2 s .  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;/*from  w  ww .  j  a  v a  2  s.  c om*/
    }

    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  ww  w. ja v a  2  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;
}