import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
import org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistryListener;
+import org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
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.IetfInetUtil;
private final Map<IpAddress, BGPSessionPreferences> peerPreferences = Maps.newHashMap();
@GuardedBy("this")
private final Set<PeerRegistryListener> listeners = new HashSet<>();
+ @GuardedBy("this")
+ private final Set<PeerRegistrySessionListener> sessionListeners = new HashSet<>();
public static BGPPeerRegistry instance() {
return GLOBAL;
public synchronized void removePeerSession(final IpAddress ip) {
Preconditions.checkNotNull(ip);
this.sessionIds.remove(ip);
+ for (final PeerRegistrySessionListener peerRegistrySessionListener : this.sessionListeners) {
+ peerRegistrySessionListener.onSessionRemoved(ip);
+ }
}
@Override
// Map session id to peer IP address
this.sessionIds.put(ip, currentConnection);
+ for (final PeerRegistrySessionListener peerRegistrySessionListener : this.sessionListeners) {
+ peerRegistrySessionListener.onSessionCreated(ip);
+ }
return p;
}
}
};
}
-}
\ No newline at end of file
+
+ @Override
+ public synchronized AutoCloseable registerPeerSessionListener(final PeerRegistrySessionListener listener) {
+ this.sessionListeners.add(listener);
+ for (final IpAddress ipAddress : this.sessionIds.keySet()) {
+ listener.onSessionCreated(ipAddress);
+ }
+ return new AbstractRegistration() {
+ @Override
+ protected void removeRegistration() {
+ synchronized (StrictBGPPeerRegistry.this) {
+ StrictBGPPeerRegistry.this.sessionListeners.remove(listener);
+ }
+ }
+ };
+ }
+}