--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.rib.impl.state;
+
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import java.util.Objects;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPRibState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPRibStateConsumer;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPStateConsumer;
+
+abstract class AbstractBGPStateConsumer implements BGPStateConsumer {
+ @Override
+ public final List<BGPRibState> getRibStats() {
+ return bgpRibStates().stream()
+ .map(BGPRibStateConsumer::getRIBState)
+ .filter(Objects::nonNull)
+ .collect(ImmutableList.toImmutableList());
+ }
+
+ @Override
+ public final List<BGPPeerState> getPeerStats() {
+ return bgpPeerStates().stream()
+ .map(BGPPeerStateConsumer::getPeerState)
+ .filter(Objects::nonNull)
+ .collect(ImmutableList.toImmutableList());
+ }
+
+ abstract List<BGPRibStateConsumer> bgpRibStates();
+
+ abstract List<BGPPeerStateConsumer> bgpPeerStates();
+}
*/
package org.opendaylight.protocol.bgp.rib.impl.state;
-import com.google.common.collect.ImmutableList;
import java.util.List;
-import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
-import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
-import org.opendaylight.protocol.bgp.rib.spi.state.BGPRibState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPRibStateConsumer;
-import org.opendaylight.protocol.bgp.rib.spi.state.BGPStateConsumer;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPStateProvider;
+@Singleton
// This class is thread-safe
-public class BGPStateCollectorImpl implements BGPStateProvider, BGPStateConsumer {
+public final class BGPStateCollectorImpl extends AbstractBGPStateConsumer implements BGPStateProvider {
private final List<BGPRibStateConsumer> bgpRibStates = new CopyOnWriteArrayList<>();
private final List<BGPPeerStateConsumer> bgpPeerStates = new CopyOnWriteArrayList<>();
- @Override
- public List<BGPRibState> getRibStats() {
- return this.bgpRibStates.stream().map(BGPRibStateConsumer::getRIBState).filter(Objects::nonNull)
- .collect(ImmutableList.toImmutableList());
- }
-
- @Override
- public List<BGPPeerState> getPeerStats() {
- return this.bgpPeerStates.stream().map(BGPPeerStateConsumer::getPeerState).filter(Objects::nonNull)
- .collect(ImmutableList.toImmutableList());
+ @Inject
+ public BGPStateCollectorImpl() {
+ // Exposed for DI
}
@Override
public void bind(final BGPRibStateConsumer bgpState) {
- this.bgpRibStates.add(bgpState);
+ bgpRibStates.add(bgpState);
}
@Override
public void bind(final BGPPeerStateConsumer bgpState) {
- this.bgpPeerStates.add(bgpState);
+ bgpPeerStates.add(bgpState);
}
@Override
public void unbind(final BGPRibStateConsumer bgpState) {
- this.bgpRibStates.remove(bgpState);
+ bgpRibStates.remove(bgpState);
}
@Override
public void unbind(final BGPPeerStateConsumer bgpState) {
- this.bgpPeerStates.remove(bgpState);
+ bgpPeerStates.remove(bgpState);
+ }
+
+ @Override
+ List<BGPRibStateConsumer> bgpRibStates() {
+ return bgpRibStates;
+ }
+
+ @Override
+ List<BGPPeerStateConsumer> bgpPeerStates() {
+ return bgpPeerStates;
}
}
--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.rib.impl.state;
+
+import java.util.List;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPRibStateConsumer;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPStateConsumer;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferencePolicyOption;
+
+@Component(immediate = true, service = BGPStateConsumer.class)
+public final class OSGiBGPStateConsumer extends AbstractBGPStateConsumer {
+ @Reference(policyOption = ReferencePolicyOption.GREEDY)
+ volatile List<BGPRibStateConsumer> ribStates;
+ @Reference(policyOption = ReferencePolicyOption.GREEDY)
+ volatile List<BGPPeerStateConsumer> peerStates;
+
+ @Override
+ List<BGPRibStateConsumer> bgpRibStates() {
+ return ribStates;
+ }
+
+ @Override
+ List<BGPPeerStateConsumer> bgpPeerStates() {
+ return peerStates;
+ }
+}
</bean>
<bean id="appPeer" class="org.opendaylight.protocol.bgp.rib.impl.config.AppPeer" scope="prototype"/>
-
- <bean id="bgpStateCollector" class="org.opendaylight.protocol.bgp.rib.impl.state.BGPStateCollectorImpl"/>
- <service ref="bgpStateCollector" interface="org.opendaylight.protocol.bgp.rib.spi.state.BGPStateConsumer"/>
-
- <reference-list id="ribStatsListener" interface="org.opendaylight.protocol.bgp.rib.spi.state.BGPRibStateConsumer"
- availability="optional">
- <reference-listener bind-method="bind" unbind-method="unbind">
- <ref component-id="bgpStateCollector"/>
- </reference-listener>
- </reference-list>
-
- <reference-list id="peersStatsListener" interface="org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer"
- availability="optional">
- <reference-listener bind-method="bind" unbind-method="unbind">
- <ref component-id="bgpStateCollector"/>
- </reference-listener>
- </reference-list>
</blueprint>