2 * Copyright (c) 2016 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.state;
10 import com.google.common.collect.ImmutableList;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.stream.Collectors;
14 import javax.annotation.concurrent.GuardedBy;
15 import javax.annotation.concurrent.ThreadSafe;
16 import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
17 import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
18 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBState;
19 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBStateConsumer;
20 import org.opendaylight.protocol.bgp.rib.spi.state.BGPStateConsumer;
21 import org.opendaylight.protocol.bgp.rib.spi.state.BGPStateProvider;
24 public class BGPStateCollectorImpl implements BGPStateProvider, BGPStateConsumer {
26 private final List<BGPRIBStateConsumer> bgpRibStates = new ArrayList<>();
28 private final List<BGPPeerStateConsumer> bgpPeerStates = new ArrayList<>();
31 public List<BGPRIBState> getRibStats() {
32 synchronized (this.bgpRibStates) {
33 return ImmutableList.copyOf(this.bgpRibStates.stream().map(BGPRIBStateConsumer::getRIBState)
34 .collect(Collectors.toList()));
39 public List<BGPPeerState> getPeerStats() {
40 synchronized (this.bgpPeerStates) {
41 return ImmutableList.copyOf(this.bgpPeerStates.stream().map(BGPPeerStateConsumer::getPeerState)
42 .collect(Collectors.toList()));
47 public void bind(final BGPRIBStateConsumer bgpState) {
48 if (bgpState == null) {
51 synchronized (this.bgpRibStates) {
52 this.bgpRibStates.add(bgpState);
57 public void unbind(final BGPRIBStateConsumer bgpState) {
58 if (bgpState == null) {
61 synchronized (this.bgpRibStates) {
62 this.bgpRibStates.remove(bgpState);
67 public void bind(final BGPPeerStateConsumer bgpState) {
68 if (bgpState == null) {
71 synchronized (this.bgpPeerStates) {
72 this.bgpPeerStates.add(bgpState);
77 public void unbind(final BGPPeerStateConsumer bgpState) {
78 if (bgpState == null) {
81 synchronized (this.bgpPeerStates) {
82 this.bgpPeerStates.remove(bgpState);