2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import static java.util.Objects.requireNonNull;
12 import java.util.HashMap;
14 import java.util.function.BiConsumer;
15 import javax.annotation.concurrent.GuardedBy;
16 import org.opendaylight.protocol.bgp.rib.impl.spi.PeerExportGroupRegistry;
17 import org.opendaylight.protocol.concepts.AbstractRegistration;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
23 final class PeerExportGroupImpl implements PeerExportGroupRegistry {
25 private final Map<PeerId, PeerExporTuple> peers = new HashMap<>();
26 private final AbstractExportPolicy policy;
28 public PeerExportGroupImpl(final AbstractExportPolicy policy) {
29 this.policy = requireNonNull(policy);
33 public ContainerNode effectiveAttributes(final PeerRole role, final ContainerNode attributes) {
34 return attributes == null || role == null ? null : this.policy.effectiveAttributes(role, attributes);
38 public boolean containsPeer(final PeerId routePeerId) {
39 synchronized (this.peers) {
40 return this.peers.containsKey(routePeerId);
45 public void forEach(final BiConsumer<PeerId, YangInstanceIdentifier> action) {
46 synchronized (this.peers) {
47 for (final Map.Entry<PeerId, PeerExporTuple> pid : this.peers.entrySet()) {
48 action.accept(pid.getKey(), pid.getValue().getYii());
54 public AbstractRegistration registerPeer(final PeerId peerId, final PeerExporTuple peerExporTuple) {
55 synchronized (this.peers) {
56 this.peers.put(peerId, peerExporTuple);
59 return new AbstractRegistration() {
61 protected void removeRegistration() {
62 synchronized (PeerExportGroupImpl.this.peers) {
63 PeerExportGroupImpl.this.peers.remove(peerId);
70 public boolean isEmpty() {
71 synchronized (this.peers) {
72 return this.peers.isEmpty();