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.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;
23 public class BGPStateCollectorImpl implements BGPStateProvider, BGPStateConsumer {
24 private final List<BGPRibStateConsumer> bgpRibStates = new CopyOnWriteArrayList<>();
25 private final List<BGPPeerStateConsumer> bgpPeerStates = new CopyOnWriteArrayList<>();
28 public List<BGPRibState> getRibStats() {
29 return this.bgpRibStates.stream().map(BGPRibStateConsumer::getRIBState).filter(Objects::nonNull)
30 .collect(ImmutableList.toImmutableList());
34 public List<BGPPeerState> getPeerStats() {
35 return this.bgpPeerStates.stream().map(BGPPeerStateConsumer::getPeerState).filter(Objects::nonNull)
36 .collect(ImmutableList.toImmutableList());
40 public void bind(final BGPRibStateConsumer bgpState) {
41 this.bgpRibStates.add(bgpState);
45 public void bind(final BGPPeerStateConsumer bgpState) {
46 this.bgpPeerStates.add(bgpState);
50 public void unbind(final BGPRibStateConsumer bgpState) {
51 this.bgpRibStates.remove(bgpState);
55 public void unbind(final BGPPeerStateConsumer bgpState) {
56 this.bgpPeerStates.remove(bgpState);