BUG-7976: Race between peer removal and routes update
[bgpcep.git] / bgp / rib-spi / src / main / java / org / opendaylight / protocol / bgp / rib / spi / PeerExportGroup.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.rib.spi;
10
11 import java.util.Collection;
12 import java.util.Map;
13 import java.util.function.BiConsumer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
18
19 /**
20  * A collection of peers sharing the same export policy.
21  */
22 public interface PeerExportGroup {
23     final class PeerExporTuple {
24         private final YangInstanceIdentifier yii;
25         private final PeerRole role;
26
27         public PeerExporTuple(final YangInstanceIdentifier yii, final PeerRole role) {
28             this.yii = yii;
29             this.role = role;
30         }
31
32         public YangInstanceIdentifier getYii() {
33             return this.yii;
34         }
35
36         public PeerRole getRole() {
37             return this.role;
38         }
39     }
40
41     /**
42      * Transform outgoing attributes according to policy per Peer
43      *
44      * @param role root Peer role
45      * @param attributes attributes container
46      * @return return attributes container after apply policy
47      */
48     ContainerNode effectiveAttributes(PeerRole role, ContainerNode attributes);
49
50     /**
51      * @return map of peer
52      * @deprecated Use {@link #forEach}
53      */
54     @Deprecated
55     Collection<Map.Entry<PeerId, PeerExporTuple>> getPeers();
56
57     /**
58      *
59      * @param routePeerId PeerId
60      * @return true if peer is present on this export group
61      */
62     boolean containsPeer(PeerId routePeerId);
63
64     /**
65      * Applies the given action for each entry in this PeerExportGroup on synchronized mode
66      *
67      * @param action action to be applied
68      */
69     void forEach(BiConsumer<PeerId, YangInstanceIdentifier> action);
70 }