5695650a1a4609f2aace136ad12680568a673256
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / state / BGPStateCollectorImpl.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 package org.opendaylight.protocol.bgp.rib.impl.state;
9
10 import com.google.common.collect.ImmutableList;
11 import java.util.List;
12 import java.util.Objects;
13 import java.util.concurrent.CopyOnWriteArrayList;
14 import javax.annotation.concurrent.ThreadSafe;
15 import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
16 import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
17 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRibState;
18 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRibStateConsumer;
19 import org.opendaylight.protocol.bgp.rib.spi.state.BGPStateConsumer;
20 import org.opendaylight.protocol.bgp.rib.spi.state.BGPStateProvider;
21
22 @ThreadSafe
23 public class BGPStateCollectorImpl implements BGPStateProvider, BGPStateConsumer {
24     private final List<BGPRibStateConsumer> bgpRibStates = new CopyOnWriteArrayList<>();
25     private final List<BGPPeerStateConsumer> bgpPeerStates = new CopyOnWriteArrayList<>();
26
27     @Override
28     public List<BGPRibState> getRibStats() {
29         return this.bgpRibStates.stream().map(BGPRibStateConsumer::getRIBState).filter(Objects::nonNull)
30                 .collect(ImmutableList.toImmutableList());
31     }
32
33     @Override
34     public List<BGPPeerState> getPeerStats() {
35         return this.bgpPeerStates.stream().map(BGPPeerStateConsumer::getPeerState).filter(Objects::nonNull)
36                 .collect(ImmutableList.toImmutableList());
37     }
38
39     @Override
40     public void bind(final BGPRibStateConsumer bgpState) {
41         this.bgpRibStates.add(bgpState);
42     }
43
44     @Override
45     public void bind(final BGPPeerStateConsumer bgpState) {
46         this.bgpPeerStates.add(bgpState);
47     }
48
49     @Override
50     public void unbind(final BGPRibStateConsumer bgpState) {
51         this.bgpRibStates.remove(bgpState);
52     }
53
54     @Override
55     public void unbind(final BGPPeerStateConsumer bgpState) {
56         this.bgpPeerStates.remove(bgpState);
57     }
58 }