import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import com.google.common.util.concurrent.FluentFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collections;
import java.util.List;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.ExtCommunitySets;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.ext.community.sets.ExtCommunitySet;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.ext.community.sets.ExtCommunitySetKey;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.ext.community.sets.ext.community.set.ExtCommunityMember;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.RoutingPolicy;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.DefinedSets;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunities;
justification = "https://github.com/spotbugs/spotbugs/issues/811")
private List<ExtendedCommunities> loadCommunitySet(final String key)
throws ExecutionException, InterruptedException {
- final ReadTransaction tr = this.databroker.newReadOnlyTransaction();
- final Optional<ExtCommunitySet> result =
- tr.read(LogicalDatastoreType.CONFIGURATION, EXT_COMMUNITY_SETS_IID
- .child(ExtCommunitySet.class, new ExtCommunitySetKey(key))).get();
- if (!result.isPresent()) {
- return Collections.emptyList();
+ final FluentFuture<Optional<ExtCommunitySet>> future;
+ try (ReadTransaction tr = this.databroker.newReadOnlyTransaction()) {
+ future = tr.read(LogicalDatastoreType.CONFIGURATION,
+ EXT_COMMUNITY_SETS_IID.child(ExtCommunitySet.class, new ExtCommunitySetKey(key)));
}
- return result.get().getExtCommunityMember()
- .stream().map(ge -> new ExtendedCommunitiesBuilder().setExtendedCommunity(ge.getExtendedCommunity())
- .setTransitive(ge.getTransitive()).build()).collect(Collectors.toList());
+ final Optional<ExtCommunitySet> result = future.get();
+ return result.map(AbstractExtCommunityHandler::toExtendedCommunitiesList).orElse(Collections.emptyList());
+ }
+
+ private static List<ExtendedCommunities> toExtendedCommunitiesList(ExtCommunitySet extCommunitySets) {
+ return extCommunitySets.getExtCommunityMember().stream()
+ .map(AbstractExtCommunityHandler::toExtendedCommunities).collect(Collectors.toList());
+ }
+
+ private static ExtendedCommunities toExtendedCommunities(final ExtCommunityMember ge) {
+ return new ExtendedCommunitiesBuilder().setExtendedCommunity(ge.getExtendedCommunity())
+ .setTransitive(ge.getTransitive()).build();
}
}
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import com.google.common.util.concurrent.FluentFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collection;
import java.util.Collections;
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
justification = "https://github.com/spotbugs/spotbugs/issues/811")
private AsPathSet loadSets(final String key) throws ExecutionException, InterruptedException {
- final ReadTransaction tr = this.dataBroker.newReadOnlyTransaction();
- final Optional<AsPathSet> result = tr.read(LogicalDatastoreType.CONFIGURATION,
- AS_PATHS_SETS_IID.child(AsPathSet.class, new AsPathSetKey(key))).get();
- return result.orElse(null);
+ final FluentFuture<Optional<AsPathSet>> future;
+ try (ReadTransaction tr = this.dataBroker.newReadOnlyTransaction()) {
+ future = tr.read(LogicalDatastoreType.CONFIGURATION,
+ AS_PATHS_SETS_IID.child(AsPathSet.class, new AsPathSetKey(key)));
+ }
+ return future.get().orElse(null);
}
@Override
//(matchSetOptions.equals(MatchSetOptionsType.INVERT))
return noneInCommon;
}
-}
\ No newline at end of file
+}
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import com.google.common.util.concurrent.FluentFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
.child(NeighborSets.class);
private final DataBroker dataBroker;
private final LoadingCache<String, List<PeerId>> peerSets = CacheBuilder.newBuilder()
- .build(new CacheLoader<String, List<PeerId>>() {
+ .build(new CacheLoader<>() {
@Override
public List<PeerId> load(final String key) throws ExecutionException, InterruptedException {
return loadRoleSets(key);
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
justification = "https://github.com/spotbugs/spotbugs/issues/811")
private List<PeerId> loadRoleSets(final String key) throws ExecutionException, InterruptedException {
- final ReadTransaction tr = this.dataBroker.newReadOnlyTransaction();
- final Optional<NeighborSet> result = tr.read(LogicalDatastoreType.CONFIGURATION,
- NEIGHBOR_SET_IID.child(NeighborSet.class, new NeighborSetKey(key))).get();
- if (!result.isPresent()) {
- return Collections.emptyList();
+ final FluentFuture<Optional<NeighborSet>> future;
+ try (ReadTransaction tr = this.dataBroker.newReadOnlyTransaction()) {
+ future = tr.read(LogicalDatastoreType.CONFIGURATION,
+ NEIGHBOR_SET_IID.child(NeighborSet.class, new NeighborSetKey(key)));
+
}
- return result.get().getNeighbor().values().stream()
- .map(nei -> RouterIds.createPeerId(nei.getAddress()))
- .collect(Collectors.toList());
+ return future.get().map(neighboursSet -> neighboursSet.getNeighbor().values().stream()
+ .map(nei -> RouterIds.createPeerId(nei.getAddress()))
+ .collect(Collectors.toUnmodifiableList())).orElse(List.of());
}
@Override
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import com.google.common.util.concurrent.FluentFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.Collections;
.augmentation(BgpClusterIdSets.class).child(ClusterIdSets.class);
private final DataBroker dataBroker;
private final LoadingCache<String, ClusterIdSet> sets = CacheBuilder.newBuilder()
- .build(new CacheLoader<String, ClusterIdSet>() {
+ .build(new CacheLoader<>() {
@Override
public ClusterIdSet load(final String key) throws ExecutionException, InterruptedException {
return loadSets(key);
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
justification = "https://github.com/spotbugs/spotbugs/issues/811")
private ClusterIdSet loadSets(final String key) throws ExecutionException, InterruptedException {
- final ReadTransaction tr = this.dataBroker.newReadOnlyTransaction();
- final Optional<ClusterIdSet> result = tr.read(LogicalDatastoreType.CONFIGURATION,
- CLUSTERS_ID_SETS_IID.child(ClusterIdSet.class, new ClusterIdSetKey(key))).get();
- return result.orElse(null);
+ final FluentFuture<Optional<ClusterIdSet>> future;
+ try (ReadTransaction tr = this.dataBroker.newReadOnlyTransaction()) {
+ future = tr.read(LogicalDatastoreType.CONFIGURATION,
+ CLUSTERS_ID_SETS_IID.child(ClusterIdSet.class, new ClusterIdSetKey(key)));
+ }
+ return future.get().orElse(null);
}
@Override
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import com.google.common.util.concurrent.FluentFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
.augmentation(BgpOriginatorIdSets.class).child(OriginatorIdSets.class);
private final DataBroker dataBroker;
private final LoadingCache<String, OriginatorIdSet> sets = CacheBuilder.newBuilder()
- .build(new CacheLoader<String, OriginatorIdSet>() {
+ .build(new CacheLoader<>() {
@Override
public OriginatorIdSet load(final String key) throws ExecutionException, InterruptedException {
return loadSets(key);
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
justification = "https://github.com/spotbugs/spotbugs/issues/811")
private OriginatorIdSet loadSets(final String key) throws ExecutionException, InterruptedException {
- final ReadTransaction tr = this.dataBroker.newReadOnlyTransaction();
- final Optional<OriginatorIdSet> result = tr.read(LogicalDatastoreType.CONFIGURATION,
- ORIGINATOR_ID_SETS_IID.child(OriginatorIdSet.class, new OriginatorIdSetKey(key))).get();
- return result.orElse(null);
+ final FluentFuture<Optional<OriginatorIdSet>> future;
+ try (ReadTransaction tr = this.dataBroker.newReadOnlyTransaction()) {
+ future = tr.read(LogicalDatastoreType.CONFIGURATION,
+ ORIGINATOR_ID_SETS_IID.child(OriginatorIdSet.class, new OriginatorIdSetKey(key)));
+ }
+ return future.get().orElse(null);
}
@Override
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import com.google.common.util.concurrent.FluentFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collections;
import java.util.List;
.augmentation(BgpRoleSets.class).child(RoleSets.class);
private final DataBroker dataBroker;
private final LoadingCache<String, List<PeerRole>> roleSets = CacheBuilder.newBuilder()
- .build(new CacheLoader<String, List<PeerRole>>() {
+ .build(new CacheLoader<>() {
@Override
public List<PeerRole> load(final String key) throws ExecutionException, InterruptedException {
return loadRoleSets(key);
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
justification = "https://github.com/spotbugs/spotbugs/issues/811")
private List<PeerRole> loadRoleSets(final String key) throws ExecutionException, InterruptedException {
- final ReadTransaction tr = this.dataBroker.newReadOnlyTransaction();
- final Optional<RoleSet> result = tr.read(LogicalDatastoreType.CONFIGURATION,
- ROLE_SET_IID.child(RoleSet.class, new RoleSetKey(key))).get();
- if (!result.isPresent()) {
- return Collections.emptyList();
+ final FluentFuture<Optional<RoleSet>> future;
+ try (ReadTransaction tr = this.dataBroker.newReadOnlyTransaction()) {
+ future = tr.read(LogicalDatastoreType.CONFIGURATION,
+ ROLE_SET_IID.child(RoleSet.class, new RoleSetKey(key)));
}
- return result.get().getRole();
+ return future.get().map(RoleSet::getRole).orElse(Collections.emptyList());
}
@Override