Fix some rib-impl warnigs
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / state / BGPStateCollectorImpl.java
index c865a08eb42cf6cbf7b4ae6b20babcaee17d4552..5695650a1a4609f2aace136ad12680568a673256 100644 (file)
@@ -8,85 +8,51 @@
 package org.opendaylight.protocol.bgp.rib.impl.state;
 
 import com.google.common.collect.ImmutableList;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
-import java.util.stream.Collectors;
-import javax.annotation.concurrent.GuardedBy;
+import java.util.concurrent.CopyOnWriteArrayList;
 import javax.annotation.concurrent.ThreadSafe;
 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.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;
 
 @ThreadSafe
 public class BGPStateCollectorImpl implements BGPStateProvider, BGPStateConsumer {
-    @GuardedBy("this")
-    private final List<BGPRIBStateConsumer> bgpRibStates = new ArrayList<>();
-    @GuardedBy("this")
-    private final List<BGPPeerStateConsumer> bgpPeerStates = new ArrayList<>();
+    private final List<BGPRibStateConsumer> bgpRibStates = new CopyOnWriteArrayList<>();
+    private final List<BGPPeerStateConsumer> bgpPeerStates = new CopyOnWriteArrayList<>();
 
     @Override
-    public List<BGPRIBState> getRibStats() {
-        synchronized (this.bgpRibStates) {
-            return ImmutableList.copyOf(this.bgpRibStates
-                    .stream()
-                    .map(BGPRIBStateConsumer::getRIBState)
-                    .filter(Objects::nonNull)
-                    .collect(Collectors.toList()));
-        }
+    public List<BGPRibState> getRibStats() {
+        return this.bgpRibStates.stream().map(BGPRibStateConsumer::getRIBState).filter(Objects::nonNull)
+                .collect(ImmutableList.toImmutableList());
     }
 
     @Override
     public List<BGPPeerState> getPeerStats() {
-        synchronized (this.bgpPeerStates) {
-            return ImmutableList.copyOf(this.bgpPeerStates
-                    .stream()
-                    .map(BGPPeerStateConsumer::getPeerState)
-                    .filter(Objects::nonNull)
-                    .collect(Collectors.toList()));
-        }
+        return this.bgpPeerStates.stream().map(BGPPeerStateConsumer::getPeerState).filter(Objects::nonNull)
+                .collect(ImmutableList.toImmutableList());
     }
 
     @Override
-    public void bind(final BGPRIBStateConsumer bgpState) {
-        if (bgpState == null) {
-            return;
-        }
-        synchronized (this.bgpRibStates) {
-            this.bgpRibStates.add(bgpState);
-        }
+    public void bind(final BGPRibStateConsumer bgpState) {
+        this.bgpRibStates.add(bgpState);
     }
 
     @Override
-    public void unbind(final BGPRIBStateConsumer bgpState) {
-        if (bgpState == null) {
-            return;
-        }
-        synchronized (this.bgpRibStates) {
-            this.bgpRibStates.remove(bgpState);
-        }
+    public void bind(final BGPPeerStateConsumer bgpState) {
+        this.bgpPeerStates.add(bgpState);
     }
 
     @Override
-    public void bind(final BGPPeerStateConsumer bgpState) {
-        if (bgpState == null) {
-            return;
-        }
-        synchronized (this.bgpPeerStates) {
-            this.bgpPeerStates.add(bgpState);
-        }
+    public void unbind(final BGPRibStateConsumer bgpState) {
+        this.bgpRibStates.remove(bgpState);
     }
 
     @Override
     public void unbind(final BGPPeerStateConsumer bgpState) {
-        if (bgpState == null) {
-            return;
-        }
-        synchronized (this.bgpPeerStates) {
-            this.bgpPeerStates.remove(bgpState);
-        }
+        this.bgpPeerStates.remove(bgpState);
     }
 }