X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=bgp%2Frib-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fbgp%2Frib%2Fimpl%2FPeerExportGroupImpl.java;fp=bgp%2Frib-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fbgp%2Frib%2Fimpl%2FPeerExportGroupImpl.java;h=dd6dbc66d21c390562e65a9bc7382adb969ba977;hb=aa71d43f58dc8b5242553ecc75a196fb5c0ca5e6;hp=69ba399ce140a321f6d0538264f1a0aeb490e512;hpb=1900f3edb1aa1a8697f6140e463aa1e9c483f423;p=bgpcep.git diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/PeerExportGroupImpl.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/PeerExportGroupImpl.java index 69ba399ce1..dd6dbc66d2 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/PeerExportGroupImpl.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/PeerExportGroupImpl.java @@ -9,33 +9,74 @@ package org.opendaylight.protocol.bgp.rib.impl; import com.google.common.base.Preconditions; import java.util.Collection; +import java.util.HashMap; import java.util.Map; -import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup; +import java.util.function.BiConsumer; +import javax.annotation.concurrent.GuardedBy; +import org.opendaylight.protocol.bgp.rib.impl.spi.PeerExportGroupRegistry; +import org.opendaylight.protocol.concepts.AbstractRegistration; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -final class PeerExportGroupImpl implements PeerExportGroup { - private final Map peers; +final class PeerExportGroupImpl implements PeerExportGroupRegistry { + @GuardedBy("this") + private final Map peers = new HashMap<>(); private final AbstractExportPolicy policy; - public PeerExportGroupImpl(final Map peers, final AbstractExportPolicy policy) { - this.peers = Preconditions.checkNotNull(peers); + public PeerExportGroupImpl(final AbstractExportPolicy policy) { this.policy = Preconditions.checkNotNull(policy); } @Override public ContainerNode effectiveAttributes(final PeerRole role, final ContainerNode attributes) { - return attributes == null || role == null ? null : policy.effectiveAttributes(role, attributes); + return attributes == null || role == null ? null : this.policy.effectiveAttributes(role, attributes); } @Override public Collection> getPeers() { - return peers.entrySet(); + synchronized (this.peers) { + return this.peers.entrySet(); + } } @Override public boolean containsPeer(final PeerId routePeerId) { - return this.peers.containsKey(routePeerId); + synchronized (this.peers) { + return this.peers.containsKey(routePeerId); + } + } + + @Override + public void forEach(final BiConsumer action) { + synchronized (this.peers) { + for (final Map.Entry pid : this.peers.entrySet()) { + action.accept(pid.getKey(), pid.getValue().getYii()); + } + } + } + + @Override + public AbstractRegistration registerPeer(final PeerId peerId, final PeerExporTuple peerExporTuple) { + synchronized (this.peers) { + this.peers.put(peerId, peerExporTuple); + } + + return new AbstractRegistration() { + @Override + protected void removeRegistration() { + synchronized (PeerExportGroupImpl.this.peers) { + PeerExportGroupImpl.this.peers.remove(peerId); + } + } + }; + } + + @Override + public boolean isEmpty() { + synchronized (this.peers) { + return this.peers.isEmpty(); + } } } \ No newline at end of file