This fixes up the issues reported and flips enforcement to on.
Change-Id: Iae6de422f027e6413b4e3021d4324b051f41a513
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
<propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
</configuration>
</plugin>
+ <plugin>
+ <groupId>com.github.spotbugs</groupId>
+ <artifactId>spotbugs-maven-plugin</artifactId>
+ <configuration>
+ <failOnError>true</failOnError>
+ </configuration>
+ </plugin>
</plugins>
</build>
<scm>
import org.slf4j.LoggerFactory;
public abstract class AbstractDOMDataBroker extends AbstractDOMForwardedTransactionFactory<DOMStore>
- implements DOMDataBroker, AutoCloseable {
+ implements DOMDataBroker {
private static final Logger LOG = LoggerFactory.getLogger(AbstractDOMDataBroker.class);
private final AtomicLong txNum = new AtomicLong();
* 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.mdsal.dom.broker;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import org.slf4j.LoggerFactory;
/**
- * Implementation of blocking three-phase commit-coordination tasks without
- * support of cancellation.
+ * Implementation of blocking three-phase commit-coordination tasks without support of cancellation.
*/
final class CommitCoordinationTask implements Callable<CommitInfo> {
private enum Phase {
}
/**
- * Invokes canCommit on underlying cohorts and blocks till
- * all results are returned.
- *
- *<p>
- * Valid state transition is from SUBMITTED to CAN_COMMIT,
- * if currentPhase is not SUBMITTED throws IllegalStateException.
+ * Invokes canCommit on underlying cohorts and blocks till all results are returned.
*
- * @throws TransactionCommitFailedException
- * If one of cohorts failed can Commit
+ * <p>
+ * Valid state transition is from SUBMITTED to CAN_COMMIT, if currentPhase is not SUBMITTED throws
+ * IllegalStateException.
*
+ * @throws TransactionCommitFailedException If one of cohorts failed can Commit
*/
+ @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
private void canCommitBlocking() throws TransactionCommitFailedException {
for (final ListenableFuture<?> canCommit : canCommitAll()) {
try {
}
/**
- * Invokes canCommit on underlying cohorts and returns composite future
- * which will contains {@link Boolean#TRUE} only and only if
- * all cohorts returned true.
+ * Invokes canCommit on underlying cohorts and returns composite future which will contain {@link Boolean#TRUE} only
+ * and only if all cohorts returned true.
*
- *<p>
- * Valid state transition is from SUBMITTED to CAN_COMMIT,
- * if currentPhase is not SUBMITTED throws IllegalStateException.
+ * <p>
+ * Valid state transition is from SUBMITTED to CAN_COMMIT, if currentPhase is not SUBMITTED throws
+ * IllegalStateException.
*
* @return List of all cohorts futures from can commit phase.
- *
*/
private ListenableFuture<?>[] canCommitAll() {
final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
}
/**
- * Invokes preCommit on underlying cohorts and blocks till
- * all results are returned.
+ * Invokes preCommit on underlying cohorts and blocks until all results are returned.
*
- *<p>
- * Valid state transition is from CAN_COMMIT to PRE_COMMIT, if current
- * state is not CAN_COMMIT
- * throws IllegalStateException.
- *
- * @throws TransactionCommitFailedException
- * If one of cohorts failed preCommit
+ * <p>
+ * Valid state transition is from CAN_COMMIT to PRE_COMMIT, if current state is not CAN_COMMIT throws
+ * IllegalStateException.
*
+ * @throws TransactionCommitFailedException If one of cohorts failed preCommit
*/
+ @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
private void preCommitBlocking() throws TransactionCommitFailedException {
final ListenableFuture<?>[] preCommitFutures = preCommitAll();
try {
}
/**
- * Invokes preCommit on underlying cohorts and returns future
- * which will complete once all preCommit on cohorts completed or
- * failed.
+ * Invokes preCommit on underlying cohorts and returns future which will complete once all preCommit on cohorts
+ * completed or failed.
*
- *<p>
- * Valid state transition is from CAN_COMMIT to PRE_COMMIT, if current
- * state is not CAN_COMMIT
- * throws IllegalStateException.
+ * <p>
+ * Valid state transition is from CAN_COMMIT to PRE_COMMIT, if current state is not CAN_COMMIT throws
+ * IllegalStateException.
*
* @return List of all cohorts futures from can commit phase.
- *
*/
private ListenableFuture<?>[] preCommitAll() {
final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
}
/**
- * Invokes commit on underlying cohorts and blocks till
- * all results are returned.
+ * Invokes commit on underlying cohorts and blocks until all results are returned.
*
- *<p>
- * Valid state transition is from PRE_COMMIT to COMMIT, if not throws
- * IllegalStateException.
- *
- * @throws TransactionCommitFailedException
- * If one of cohorts failed preCommit
+ * <p>
+ * Valid state transition is from PRE_COMMIT to COMMIT, if not throws IllegalStateException.
*
+ * @throws TransactionCommitFailedException If one of cohorts failed preCommit
*/
+ @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
private void commitBlocking() throws TransactionCommitFailedException {
final ListenableFuture<?>[] commitFutures = commitAll();
try {
/**
* Aborts transaction.
*
- *<p>
- * Invokes {@link DOMStoreThreePhaseCommitCohort#abort()} on all
- * cohorts, blocks
- * for all results. If any of the abort failed throws
- * IllegalStateException,
- * which will contains originalCause as suppressed Exception.
+ * <p>
+ * Invokes {@link DOMStoreThreePhaseCommitCohort#abort()} on all cohorts, blocks for all results. If any
+ * of the abort failed throws IllegalStateException, which will contains originalCause as suppressed Exception.
*
- *<p>
+ * <p>
* If aborts we're successful throws supplied exception
*
- * @param originalCause
- * Exception which should be used to fail transaction for
- * consumers of transaction
- * future and listeners of transaction failure.
+ * @param originalCause Exception which should be used to fail transaction for consumers of transaction future
+ * and listeners of transaction failure.
* @param phase phase in which the problem ensued
- * @throws TransactionCommitFailedException
- * on invocation of this method.
- * originalCa
- * @throws IllegalStateException
- * if abort failed.
+ * @throws TransactionCommitFailedException on invocation of this method.
+ * @throws IllegalStateException if abort failed.
*/
private void abortBlocking(final TransactionCommitFailedException originalCause)
throws TransactionCommitFailedException {
}
/**
- * Invokes abort on underlying cohorts and returns future which
- * completes once all abort on cohorts are completed.
+ * Invokes abort on underlying cohorts and returns future which completes once all abort on cohorts are completed.
*
- * @return Future which will complete once all cohorts completed
- * abort.
+ * @return Future which will complete once all cohorts completed abort.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private ListenableFuture<Void> abortAsyncAll() {
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* Joint implementation of {@link DOMNotificationPublishService} and {@link DOMNotificationService}. Provides
* routing of notifications from publishers to subscribers.
ListenerRegistry.create();
private final ScheduledThreadPoolExecutor observer;
- @SuppressWarnings("unchecked")
@VisibleForTesting
DOMNotificationRouter(final ExecutorService executor, final int queueDepth, final WaitStrategy strategy) {
this.executor = Preconditions.checkNotNull(executor);
private void notifyListenerTypesChanged(final Set<SchemaPath> typesAfter) {
final List<ListenerRegistration<DOMNotificationSubscriptionListener>> listenersAfter =
ImmutableList.copyOf(subscriptionListeners.getListeners());
- executor.submit(() -> {
+ executor.execute(() -> {
for (final ListenerRegistration<DOMNotificationSubscriptionListener> subListener : listenersAfter) {
try {
subListener.getInstance().onSubscriptionChanged(typesAfter);
public <L extends DOMNotificationSubscriptionListener> ListenerRegistration<L> registerSubscriptionListener(
final L listener) {
final Set<SchemaPath> initialTypes = listeners.keySet();
- executor.submit(() -> listener.onSubscriptionChanged(initialTypes));
+ executor.execute(() -> listener.onSubscriptionChanged(initialTypes));
return subscriptionListeners.registerWithType(listener);
}
}
@VisibleForTesting
- Collection<?> listeners() {
+ synchronized Collection<?> listeners() {
return listeners;
}
*/
package org.opendaylight.mdsal.dom.broker;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Verify;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Verify.verifyNotNull;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.ImmutableClassToInstanceMap;
public <T extends DOMDataTreeShard> DOMDataTreeShardRegistration<T> registerDataTreeShard(
final DOMDataTreeIdentifier prefix, final T shard, final DOMDataTreeProducer producer)
throws DOMDataTreeShardingConflictException {
+ checkArgument(producer instanceof ShardedDOMDataTreeProducer, "Unsupported producer %s", producer);
+ final ShardedDOMDataTreeProducer prod = (ShardedDOMDataTreeProducer) producer;
- final DOMDataTreeIdentifier firstSubtree = Iterables.getOnlyElement(((
- ShardedDOMDataTreeProducer) producer).getSubtrees());
- Preconditions.checkArgument(firstSubtree != null, "Producer that is used to verify namespace claim can"
+ final DOMDataTreeIdentifier firstSubtree = Iterables.getOnlyElement(prod.getSubtrees());
+ checkArgument(firstSubtree != null, "Producer that is used to verify namespace claim can"
+ " only claim a single namespace");
- Preconditions.checkArgument(prefix.equals(firstSubtree), "Trying to register shard to a different namespace"
+ checkArgument(prefix.equals(firstSubtree), "Trying to register shard to a different namespace"
+ " than the producer has claimed");
final DOMDataTreeShardRegistration<T> reg;
shards.store(prefix, reg);
- ((ShardedDOMDataTreeProducer) producer).subshardAdded(Collections.singletonMap(prefix, shard));
+ prod.subshardAdded(Collections.singletonMap(prefix, shard));
}
// Notify the parent shard
@Override
public synchronized DOMDataTreeProducer createProducer(final Collection<DOMDataTreeIdentifier> subtrees) {
- Preconditions.checkArgument(!subtrees.isEmpty(), "Subtrees may not be empty");
+ checkArgument(!subtrees.isEmpty(), "Subtrees may not be empty");
final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap = new HashMap<>();
for (final DOMDataTreeIdentifier subtree : subtrees) {
// Attempting to create a disconnected producer -- all subtrees have to be unclaimed
final DOMDataTreeProducer producer = findProducer(subtree);
- Preconditions.checkArgument(producer == null, "Subtree %s is attached to producer %s", subtree, producer);
+ checkArgument(producer == null, "Subtree %s is attached to producer %s", subtree, producer);
final DOMDataTreePrefixTableEntry<DOMDataTreeShardRegistration<?>> possibleShardReg =
shards.lookup(subtree);
synchronized DOMDataTreeProducer createProducer(final ShardedDOMDataTreeProducer parent,
final Collection<DOMDataTreeIdentifier> subtrees) {
- Preconditions.checkNotNull(parent);
+ requireNonNull(parent);
final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap = new HashMap<>();
for (final DOMDataTreeIdentifier s : subtrees) {
public synchronized <T extends DOMDataTreeListener> ListenerRegistration<T> registerListener(final T listener,
final Collection<DOMDataTreeIdentifier> subtrees, final boolean allowRxMerges,
final Collection<DOMDataTreeProducer> producers) throws DOMDataTreeLoopException {
- Preconditions.checkNotNull(listener, "listener");
+ requireNonNull(listener, "listener");
// Cross-check specified trees for exclusivity and eliminate duplicates, noDupSubtrees is effectively a Set
final Collection<DOMDataTreeIdentifier> noDupSubtrees;
for (DOMDataTreeIdentifier toCheck : subtrees) {
for (DOMDataTreeIdentifier against : subtrees) {
if (!toCheck.equals(against)) {
- Preconditions.checkArgument(!toCheck.contains(against), "Subtree %s contains subtree %s",
- toCheck, against);
+ checkArgument(!toCheck.contains(against), "Subtree %s contains subtree %s", toCheck,
+ against);
}
}
}
final ListMultimap<DOMDataTreeShardRegistration<?>, DOMDataTreeIdentifier> needed =
ArrayListMultimap.create();
for (final DOMDataTreeIdentifier subtree : subtrees) {
- final DOMDataTreeShardRegistration<?> reg = Verify.verifyNotNull(shards.lookup(subtree).getValue());
+ final DOMDataTreeShardRegistration<?> reg = verifyNotNull(shards.lookup(subtree).getValue());
needed.put(reg, subtree);
}
// Sanity check: all selected shards have to support one of the listening interfaces
needed.asMap().forEach((reg, trees) -> {
final DOMDataTreeShard shard = reg.getInstance();
- Preconditions.checkArgument(shard instanceof ListenableDOMDataTreeShard
+ checkArgument(shard instanceof ListenableDOMDataTreeShard
|| shard instanceof DOMStoreTreeChangePublisher, "Subtrees %s do not point to listenable subtree.",
trees);
});
// Sanity check: all producers have to come from this implementation and must not form loops
for (DOMDataTreeProducer producer : producers) {
- Preconditions.checkArgument(producer instanceof ShardedDOMDataTreeProducer);
+ checkArgument(producer instanceof ShardedDOMDataTreeProducer);
simpleLoopCheck(subtrees, ((ShardedDOMDataTreeProducer) producer).getSubtrees());
}
public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
final NormalizedNode<?, ?> data) {
checkRunning();
- LOG.debug("{}: Invoking put operation at {}:{} with payload {}", txIdentifier, store, path);
+ LOG.debug("{}: Invoking put operation at {}:{}", txIdentifier, store, path);
+ LOG.trace("{}: payload is {}", txIdentifier, data);
if (!initialized) {
initializeDataTreeProducerLayer(path.getParent());
}
public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
final NormalizedNode<?, ?> data) {
checkRunning();
- LOG.debug("{}: Invoking merge operation at {}:{} with payload {}", txIdentifier, store, path);
+ LOG.debug("{}: Invoking merge operation at {}:{}", txIdentifier, store, path);
+ LOG.trace("{}: payload is {}", txIdentifier, data);
if (!initialized) {
initializeDataTreeProducerLayer(path.getParent());
}
treeService.createProducer(
Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, path))));
- LOG.debug("{}: Creating DOMDataTreeCursorAwareTransactions delegates", txIdentifier, path);
+ LOG.debug("{}: Creating DOMDataTreeCursorAwareTransactions delegates on {}", txIdentifier, path);
transactionMap.put(LogicalDatastoreType.CONFIGURATION,
producerMap.get(LogicalDatastoreType.CONFIGURATION).createTransaction(true));
transactionMap.put(LogicalDatastoreType.OPERATIONAL,
*/
package org.opendaylight.mdsal.dom.broker;
-import com.google.common.util.concurrent.FluentFuture;
import java.util.List;
import java.util.Map;
import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
final class UnknownDOMRpcRoutingTableEntry extends AbstractDOMRpcRoutingTableEntry {
- private final FluentFuture<DOMRpcResult> unknownRpc;
-
UnknownDOMRpcRoutingTableEntry(final SchemaPath schemaPath, final Map<YangInstanceIdentifier,
List<DOMRpcImplementation>> impls) {
super(DOMRpcIdentifier.create(schemaPath), impls);
- unknownRpc = FluentFutures.immediateFailedFluentFuture(
- new DOMRpcImplementationNotAvailableException("SchemaPath %s is not resolved to an RPC", schemaPath));
}
@Override