import io.netty.channel.ChannelPipeline;
import io.netty.channel.SimpleChannelInboundHandler;
import java.io.IOException;
+import java.nio.channels.NonWritableChannelException;
import java.util.Date;
import java.util.List;
import java.util.Set;
import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.KeepaliveBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Notify;
@Override
public synchronized void close() {
- if (this.state != State.IDLE && this.channel.isActive()) {
- this.writeAndFlush(new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).setErrorSubcode(
- BGPError.CEASE.getSubcode()).build());
+ if (this.state != State.IDLE) {
+ this.writeAndFlush(new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).setErrorSubcode(BGPError.CEASE.getSubcode()).build());
}
this.closeWithoutMessage();
}
*
* @param msg incoming message
*/
- public synchronized void handleMessage(final Notification msg) throws BGPDocumentedException {
+ synchronized void handleMessage(final Notification msg) throws BGPDocumentedException {
// Update last reception time
this.lastMessageReceivedAt = System.nanoTime();
this.sessionStats.updateReceivedMsgTotal();
}
}
- public synchronized void endOfInput() {
+ synchronized void endOfInput() {
if (this.state == State.UP) {
LOG.info(END_OF_INPUT);
this.listener.onSessionDown(this, new IOException(END_OF_INPUT));
@GuardedBy("this")
private ChannelFuture writeEpilogue(final ChannelFuture future, final Notification msg) {
future.addListener(
- new ChannelFutureListener() {
- @Override
- public void operationComplete(final ChannelFuture f) {
- if (!f.isSuccess()) {
- LOG.warn("Failed to send message {} to socket {}", msg, f.cause(), BGPSessionImpl.this.channel);
- } else {
- LOG.trace("Message {} sent to socket {}", msg, BGPSessionImpl.this.channel);
- }
+ new ChannelFutureListener() {
+ @Override
+ 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.updateSentMsgTotal();
if (msg instanceof Update) {
}
synchronized ChannelFuture writeAndFlush(final Notification msg) {
- return writeEpilogue(this.channel.writeAndFlush(msg), msg);
+ if (isWritable()) {
+ return writeEpilogue(this.channel.writeAndFlush(msg), msg);
+ }
+ return this.channel.newFailedFuture(new NonWritableChannelException());
}
private synchronized void closeWithoutMessage() {
LOG.info("Closing session: {}", this);
removePeerSession();
- this.channel.close();
+ 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;
}
}
@Override
- public synchronized BgpSessionState getBgpSesionState() {
+ public synchronized BgpSessionState getBgpSessionState() {
return this.sessionStats.getBgpSessionState(this.state);
}
this.sessionStats.resetStats();
}
- ChannelOutputLimiter getLimiter() {
+ public ChannelOutputLimiter getLimiter() {
return this.limiter;
}