Move releaseConnection from ReusableBGPPeer to BGPSessionListener
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / SimpleSessionListener.java
index 732a5b7dbfa80cf6dc7f8b8804b0e32f5a222603..c7e3d3aaca2c454a82bb39d4622b212244dd4020 100644 (file)
@@ -9,9 +9,10 @@ package org.opendaylight.protocol.bgp.rib.impl;
 
 import com.google.common.collect.Lists;
 import java.util.List;
-import org.opendaylight.protocol.bgp.parser.BGPSession;
-import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
-import org.opendaylight.protocol.bgp.rib.impl.spi.ReusableBGPPeer;
+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.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -19,7 +20,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Listener for the client.
  */
-public class SimpleSessionListener implements ReusableBGPPeer {
+public class SimpleSessionListener implements BGPSessionListener {
 
     private final List<Notification> listMsg = Lists.newArrayList();
 
@@ -29,6 +30,11 @@ public class SimpleSessionListener implements ReusableBGPPeer {
 
     public boolean down = false;
 
+    private BGPSession session;
+
+    public SimpleSessionListener() {
+    }
+
     public List<Notification> getListMsg() {
         return this.listMsg;
     }
@@ -42,6 +48,7 @@ public class SimpleSessionListener implements ReusableBGPPeer {
     @Override
     public void onSessionUp(final BGPSession session) {
         LOG.debug("Session Up");
+        this.session = session;
         this.up = true;
     }
 
@@ -59,5 +66,23 @@ public class SimpleSessionListener implements ReusableBGPPeer {
     @Override
     public void releaseConnection() {
         LOG.debug("Releasing connection");
+        if (this.session != null) {
+            try {
+                this.session.close();
+            } catch (final Exception e) {
+                LOG.warn("Error closing session", e);
+            }
+            this.session = null;
+        }
+    }
+
+    @Override
+    public boolean isSessionActive() {
+        return true;
+    }
+
+    @Override
+    public void markUptodate(final TablesKey tablesKey) {
+        LOG.debug("Table marked as up-to-date {}", tablesKey);
     }
 }