*/
package org.opendaylight.netconf.api;
+import java.io.EOFException;
+
// FIXME: NETCONF-554: rework this interface
public interface NetconfSessionListener<S extends NetconfSession> {
/**
* session.
*
* @param session that went down
- * @param cause Exception that was thrown as the cause of session being down
+ * @param cause Exception that was thrown as the cause of session being down. A common cause is
+ * {@link EOFException}, which indicates the remote end has shut down the communication channel.
*/
void onSessionDown(S session, Exception cause);
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
-import java.io.IOException;
+import java.io.EOFException;
import org.opendaylight.netconf.api.NetconfExiSession;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.NetconfSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class AbstractNetconfSession<S extends NetconfSession,L extends NetconfSessionListener<S>>
+public abstract class AbstractNetconfSession<S extends NetconfSession, L extends NetconfSessionListener<S>>
extends SimpleChannelInboundHandler<Object> implements NetconfSession, NetconfExiSession {
-
private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfSession.class);
+
+
private final L sessionListener;
private final long sessionId;
private boolean up = false;
}
protected void endOfInput() {
- LOG.debug("Session {} end of input detected while session was in state {}", this, isUp() ? "up"
- : "initialized");
- if (isUp()) {
- this.sessionListener.onSessionDown(thisInstance(),
- new IOException("End of input detected. Close the session."));
+ LOG.debug("Session {} end of input detected while session was in state {}", this, up ? "up" : "initialized");
+ if (up) {
+ this.sessionListener.onSessionDown(thisInstance(), new EOFException("End of input"));
}
}
import io.netty.channel.EventLoop;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
+import java.io.EOFException;
import java.util.Collections;
import java.util.Optional;
import org.junit.Before;
verifyNoMoreInteractions(listener);
testingNetconfSession.sessionUp();
testingNetconfSession.endOfInput();
- verify(listener).onSessionDown(any(TestingNetconfSession.class), any(Exception.class));
+ verify(listener).onSessionDown(any(TestingNetconfSession.class), any(EOFException.class));
}
@Test
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import io.netty.util.concurrent.Future;
+import java.io.EOFException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
public void onSessionDown(final NetconfClientSession session, final Exception exception) {
// If session is already in closing, no need to call tearDown again.
if (startClosing()) {
- LOG.warn("{}: Session went down", id, exception);
+ if (exception instanceof EOFException) {
+ LOG.info("{}: Session went down: {}", id, exception.getMessage());
+ } else {
+ LOG.warn("{}: Session went down", id, exception);
+ }
tearDown(null);
}
}