import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
-class BGPSessionImpl extends AbstractProtocolSession<BGPMessage> implements BGPSession {
+@VisibleForTesting
+public class BGPSessionImpl extends AbstractProtocolSession<BGPMessage> implements BGPSession {
private static final Logger logger = LoggerFactory.getLogger(BGPSessionImpl.class);
private final Set<BGPTableType> tableTypes;
- BGPSessionImpl(final Timer timer, final BGPSessionListener listener, final Channel channel, final short keepAlive, final BGPOpenMessage remoteOpen) {
+ BGPSessionImpl(final Timer timer, final BGPSessionListener listener, final Channel channel, final short keepAlive,
+ final BGPOpenMessage remoteOpen) {
this.listener = Preconditions.checkNotNull(listener);
this.stateTimer = Preconditions.checkNotNull(timer);
this.channel = Preconditions.checkNotNull(channel);
@Override
public synchronized void close() {
logger.debug("Closing session: {}", this);
- if (!closed) {
+ if (!this.closed) {
this.sendMessage(new BGPNotificationMessage(BGPError.CEASE));
- channel.close();
- closed = true;
+ this.channel.close();
+ this.closed = true;
}
}
@Override
public synchronized void endOfInput() {
- if (!closed) {
+ if (!this.closed) {
this.listener.onSessionDown(this, new IOException("End of input detected. Close the session."));
}
}
private synchronized void closeWithoutMessage() {
logger.debug("Closing session: {}", this);
- channel.close();
- closed = true;
+ this.channel.close();
+ this.closed = true;
}
/**
final long nextHold = this.lastMessageReceivedAt + TimeUnit.SECONDS.toNanos(HOLD_TIMER_VALUE);
- if (!closed) {
+ if (!this.closed) {
if (ct >= nextHold) {
logger.debug("HoldTimer expired. " + new Date());
this.terminate(BGPError.HOLD_TIMER_EXPIRED);
long nextKeepalive = this.lastMessageSentAt + TimeUnit.SECONDS.toNanos(this.keepAlive);
- if (!closed) {
+ if (!this.closed) {
if (ct >= nextKeepalive) {
this.sendMessage(new BGPKeepAliveMessage());
nextKeepalive = this.lastMessageSentAt + TimeUnit.SECONDS.toNanos(this.keepAlive);
}
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- toStringHelper.add("channel", channel);
- toStringHelper.add("closed", closed);
+ toStringHelper.add("channel", this.channel);
+ toStringHelper.add("closed", this.closed);
return toStringHelper;
}
@Override
protected void sessionUp() {
- listener.onSessionUp(this);
+ this.listener.onSessionUp(this);
}
}