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.Objects;
14 import java.util.stream.Collectors;
15 import javax.annotation.concurrent.GuardedBy;
16 import javax.annotation.concurrent.ThreadSafe;
17 import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
18 import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
19 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBState;
20 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBStateConsumer;
21 import org.opendaylight.protocol.bgp.rib.spi.state.BGPStateConsumer;
22 import org.opendaylight.protocol.bgp.rib.spi.state.BGPStateProvider;
25 public class BGPStateCollectorImpl implements BGPStateProvider, BGPStateConsumer {
27 private final List<BGPRIBStateConsumer> bgpRibStates = new ArrayList<>();
29 private final List<BGPPeerStateConsumer> bgpPeerStates = new ArrayList<>();
32 public List<BGPRIBState> getRibStats() {
33 synchronized (this.bgpRibStates) {
34 return ImmutableList.copyOf(this.bgpRibStates
36 .map(BGPRIBStateConsumer::getRIBState)
37 .filter(Objects::nonNull)
38 .collect(Collectors.toList()));
43 public List<BGPPeerState> getPeerStats() {
44 synchronized (this.bgpPeerStates) {
45 return ImmutableList.copyOf(this.bgpPeerStates
47 .map(BGPPeerStateConsumer::getPeerState)
48 .filter(Objects::nonNull)
49 .collect(Collectors.toList()));
54 public void bind(final BGPRIBStateConsumer bgpState) {
55 if (bgpState == null) {
58 synchronized (this.bgpRibStates) {
59 this.bgpRibStates.add(bgpState);
64 public void unbind(final BGPRIBStateConsumer bgpState) {
65 if (bgpState == null) {
68 synchronized (this.bgpRibStates) {
69 this.bgpRibStates.remove(bgpState);
74 public void bind(final BGPPeerStateConsumer bgpState) {
75 if (bgpState == null) {
78 synchronized (this.bgpPeerStates) {
79 this.bgpPeerStates.add(bgpState);
84 public void unbind(final BGPPeerStateConsumer bgpState) {
85 if (bgpState == null) {
88 synchronized (this.bgpPeerStates) {
89 this.bgpPeerStates.remove(bgpState);