Resolved the merge conflicts.
Implemented code review comments.
Implemented another set of code review comments.
Change-Id: I3eecb17342e4fd7f4736ca67bc57f01f91115c0f
Signed-off-by: Brinda Jana <brinda.jana@nexusis.com>
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
</plugins>
</build>
<scm>
import static com.google.common.base.Preconditions.checkState;
-import org.opendaylight.mdsal.dom.spi.store.DOMStore;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreTreeChangePublisher;
-
+import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicLong;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.common.api.TransactionChainListener;
import org.opendaylight.mdsal.dom.api.DOMDataBroker;
import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
-import com.google.common.collect.ImmutableMap;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.atomic.AtomicLong;
+import org.opendaylight.mdsal.dom.spi.store.DOMStore;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreTreeChangePublisher;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class AbstractDOMDataBroker extends AbstractDOMForwardedTransactionFactory<DOMStore> implements DOMDataBroker, AutoCloseable {
+public abstract class AbstractDOMDataBroker extends AbstractDOMForwardedTransactionFactory<DOMStore>
+ implements DOMDataBroker, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(AbstractDOMDataBroker.class);
private final AtomicLong txNum = new AtomicLong();
}
if (treeChange) {
- extensions = ImmutableMap.<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension>of(DOMDataTreeChangeService.class, new DOMDataTreeChangeService() {
- @Override
- public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerDataTreeChangeListener(final DOMDataTreeIdentifier treeId, final L listener) {
- DOMStore publisher = getTxFactories().get(treeId.getDatastoreType());
- checkState(publisher != null, "Requested logical data store is not available.");
-
- return ((DOMStoreTreeChangePublisher)publisher).registerTreeChangeListener(treeId.getRootIdentifier(), listener);
- }
- });
+ extensions = ImmutableMap.<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension>of(
+ DOMDataTreeChangeService.class, new DOMDataTreeChangeService() {
+ @Override
+ public <L extends DOMDataTreeChangeListener> ListenerRegistration<L>
+ registerDataTreeChangeListener(final DOMDataTreeIdentifier treeId, final L listener) {
+ DOMStore publisher = getTxFactories().get(treeId.getDatastoreType());
+ checkState(publisher != null, "Requested logical data store is not available.");
+
+ return ((DOMStoreTreeChangePublisher)publisher).registerTreeChangeListener(
+ treeId.getRootIdentifier(), listener);
+ }
+ });
} else {
extensions = Collections.emptyMap();
}
this.closeable = closeable;
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void close() {
super.close();
- if(closeable != null) {
+ if (closeable != null) {
try {
closeable.close();
- } catch(Exception e) {
+ } catch (Exception e) {
LOG.debug("Error closing instance", e);
}
}
public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
checkNotClosed();
- final Map<LogicalDatastoreType, DOMStoreTransactionChain> backingChains = new EnumMap<>(LogicalDatastoreType.class);
+ final Map<LogicalDatastoreType, DOMStoreTransactionChain> backingChains =
+ new EnumMap<>(LogicalDatastoreType.class);
for (Entry<LogicalDatastoreType, DOMStore> entry : getTxFactories().entrySet()) {
backingChains.put(entry.getKey(), entry.getValue().createTransactionChain());
}
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransaction;
-
-import org.opendaylight.mdsal.common.api.AsyncTransaction;
import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.Map;
+import org.opendaylight.mdsal.common.api.AsyncTransaction;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransaction;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
/**
* Composite DOM Transaction backed by {@link DOMStoreTransaction}.
*
+ *<p>
* Abstract base for composite transaction, which provides access only to common
* functionality as retrieval of subtransaction, close method and retrieval of
* identifier.
private final Object identifier;
/**
- *
* Creates new composite Transactions.
*
* @param identifier
/**
* Returns subtransaction associated with supplied key.
*
- * @param key
- * @return
+ * @param key is used to retrieve subtransaction object
+ * @return the subtransaction object
* @throws NullPointerException
* if key is null
* @throws IllegalArgumentException
return identifier;
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
protected void closeSubtransactions() {
/*
* We share one exception for all failures, which are added
import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionFactory;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
/**
- *
* Abstract composite transaction factory.
*
+ *<p>
* Provides an convenience common implementation for composite DOM Transactions,
* where subtransaction is identified by {@link LogicalDatastoreType} type and
* implementation of subtransaction is provided by
/**
* Implementations must return unique identifier for each and every call of
- * this method;
+ * this method.
*
* @return new Unique transaction identifier.
*/
/**
* User-supplied implementation of {@link DOMDataTreeWriteTransaction#submit()} for transaction.
*
+ *<p>
* Callback invoked when {@link DOMDataTreeWriteTransaction#submit()} is invoked on transaction
* created by this factory.
*
* returned from the Future, On failure, the Future fails with a
* {@link TransactionCommitFailedException}.
*/
- protected abstract CheckedFuture<Void,TransactionCommitFailedException> submit(final DOMDataTreeWriteTransaction transaction,
+ protected abstract CheckedFuture<Void,TransactionCommitFailedException> submit(
+ final DOMDataTreeWriteTransaction transaction,
final Collection<DOMStoreThreePhaseCommitCohort> cohorts);
/**
- * Creates a new composite read-only transaction
+ * Creates a new composite read-only transaction.
*
+ *<p>
* Creates a new composite read-only transaction backed by one transaction per factory in
* {@link #getTxFactories()}.
*
+ *<p>
* Subtransaction for reading is selected by supplied {@link LogicalDatastoreType} as parameter
* for
- * {@link DOMDataTreeReadTransaction#read(LogicalDatastoreType, org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)}
- * .
+ * {@link DOMDataTreeReadTransaction#read(LogicalDatastoreType,
+ * org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)}
*
+ *<p>
* Id of returned transaction is retrieved via {@link #newTransactionIdentifier()}.
*
* @return New composite read-only transaction.
*
* <ul>
* <li>
- * {@link DOMDataTreeWriteTransaction#put(LogicalDatastoreType, org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)}
+ * {@link DOMDataTreeWriteTransaction#put(LogicalDatastoreType,
+ * org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier,
+ * org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)}
* - backing subtransaction is selected by {@link LogicalDatastoreType},
- * {@link DOMStoreWriteTransaction#write(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)}
+ * {@link DOMStoreWriteTransaction#write(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier,
+ * org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)}
* is invoked on selected subtransaction.</li>
* <li>
- * {@link DOMDataTreeWriteTransaction#merge(LogicalDatastoreType, org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)}
+ * {@link DOMDataTreeWriteTransaction#merge(LogicalDatastoreType,
+ * org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier,
+ * org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)}
* - backing subtransaction is selected by {@link LogicalDatastoreType},
- * {@link DOMStoreWriteTransaction#merge(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)}
+ * {@link DOMStoreWriteTransaction#merge(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier,
+ * org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)}
* is invoked on selected subtransaction.</li>
* <li>
- * {@link DOMDataTreeWriteTransaction#delete(LogicalDatastoreType, org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)}
+ * {@link DOMDataTreeWriteTransaction#delete(LogicalDatastoreType,
+ * org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)}
* - backing subtransaction is selected by {@link LogicalDatastoreType},
* {@link DOMStoreWriteTransaction#delete(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)}
* is invoked on selected subtransaction.
* transaction which was commited and gathered results.</li>
* </ul>
*
+ * <p>
* Id of returned transaction is generated via {@link #newTransactionIdentifier()}.
*
* @return New composite write-only transaction associated with this factory.
*/
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.api.DOMRpcException;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.opendaylight.mdsal.dom.api.DOMRpcException;
+import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
+import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
private final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls;
private final SchemaPath schemaPath;
- protected AbstractDOMRpcRoutingTableEntry(final SchemaPath schemaPath, final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
+ protected AbstractDOMRpcRoutingTableEntry(final SchemaPath schemaPath, final Map<YangInstanceIdentifier,
+ List<DOMRpcImplementation>> impls) {
this.schemaPath = Preconditions.checkNotNull(schemaPath);
this.impls = Preconditions.checkNotNull(impls);
}
}
/**
+ * This method adds the given DOMRpcImplementation instance for the given list RPC identifiers.
*
- * @param implementation
- * @param newRpcs List of new RPCs, must be mutable
- * @return
+ * @param implementation the DOMRpcImplementation instance to add
+ * @param newRpcs the List of new RPCs that the DOMRpcImplementation provides, must be mutable
+ * @return a new instance of AbstractDOMRpcRoutingTableEntry with the additions
*/
- final AbstractDOMRpcRoutingTableEntry add(final DOMRpcImplementation implementation, final List<YangInstanceIdentifier> newRpcs) {
+ final AbstractDOMRpcRoutingTableEntry add(
+ final DOMRpcImplementation implementation, final List<YangInstanceIdentifier> newRpcs) {
final Builder<YangInstanceIdentifier, List<DOMRpcImplementation>> vb = ImmutableMap.builder();
for (final Entry<YangInstanceIdentifier, List<DOMRpcImplementation>> ve : impls.entrySet()) {
if (newRpcs.remove(ve.getKey())) {
vb.put(ve);
}
}
- for(final YangInstanceIdentifier ii : newRpcs) {
+ for (final YangInstanceIdentifier ii : newRpcs) {
final ArrayList<DOMRpcImplementation> impl = new ArrayList<>(1);
impl.add(implementation);
vb.put(ii,impl);
return newInstance(vb.build());
}
- final AbstractDOMRpcRoutingTableEntry remove(final DOMRpcImplementation implementation, final List<YangInstanceIdentifier> removed) {
+ final AbstractDOMRpcRoutingTableEntry remove(
+ final DOMRpcImplementation implementation, final List<YangInstanceIdentifier> removed) {
final Builder<YangInstanceIdentifier, List<DOMRpcImplementation>> vb = ImmutableMap.builder();
for (final Entry<YangInstanceIdentifier, List<DOMRpcImplementation>> ve : impls.entrySet()) {
if (removed.remove(ve.getKey())) {
}
protected abstract CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final NormalizedNode<?, ?> input);
- protected abstract AbstractDOMRpcRoutingTableEntry newInstance(final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls);
+
+ protected abstract AbstractDOMRpcRoutingTableEntry newInstance(
+ final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls);
}
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
-
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.util.concurrent.Futures;
import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
+import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
import org.opendaylight.yangtools.util.DurationStatisticsTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* support of cancellation.
*/
final class CommitCoordinationTask implements Callable<Void> {
- private static enum Phase {
+ private enum Phase {
canCommit,
preCommit,
doCommit,
private final DurationStatisticsTracker commitStatTracker;
private final DOMDataTreeWriteTransaction tx;
- public CommitCoordinationTask(final DOMDataTreeWriteTransaction transaction,
+ CommitCoordinationTask(final DOMDataTreeWriteTransaction transaction,
final Collection<DOMStoreThreePhaseCommitCohort> cohorts,
final DurationStatisticsTracker commitStatTracker) {
this.tx = Preconditions.checkNotNull(transaction, "transaction must not be null");
}
/**
- *
* 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 returns composite future
* which will contains {@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.
*
*/
private ListenableFuture<?>[] canCommitAll() {
final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
- int i = 0;
+ int index = 0;
for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
- ops[i++] = cohort.canCommit();
+ ops[index++] = cohort.canCommit();
}
return ops;
}
/**
- *
* Invokes preCommit on underlying cohorts and blocks till
* all results are returned.
*
+ *<p>
* Valid state transition is from CAN_COMMIT to PRE_COMMIT, if current
* state is not CAN_COMMIT
* throws IllegalStateException.
private void preCommitBlocking() throws TransactionCommitFailedException {
final ListenableFuture<?>[] preCommitFutures = preCommitAll();
try {
- for(final ListenableFuture<?> future : preCommitFutures) {
+ for (final ListenableFuture<?> future : preCommitFutures) {
future.get();
}
} catch (InterruptedException | ExecutionException e) {
}
/**
- *
* 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.
*/
private ListenableFuture<?>[] preCommitAll() {
final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
- int i = 0;
+ int index = 0;
for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
- ops[i++] = cohort.preCommit();
+ ops[index++] = cohort.preCommit();
}
return ops;
}
/**
- *
* Invokes commit on underlying cohorts and blocks till
* all results are returned.
*
+ *<p>
* Valid state transition is from PRE_COMMIT to COMMIT, if not throws
* IllegalStateException.
*
private void commitBlocking() throws TransactionCommitFailedException {
final ListenableFuture<?>[] commitFutures = commitAll();
try {
- for(final ListenableFuture<?> future : commitFutures) {
+ for (final ListenableFuture<?> future : commitFutures) {
future.get();
}
} catch (InterruptedException | ExecutionException e) {
}
/**
- *
* Invokes commit on underlying cohorts and returns future which
* completes
* once all commits on cohorts are completed.
*
+ *<p>
* Valid state transition is from PRE_COMMIT to COMMIT, if not throws
* IllegalStateException
*
*/
private ListenableFuture<?>[] commitAll() {
final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
- int i = 0;
+ int index = 0;
for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
- ops[i++] = cohort.commit();
+ ops[index++] = cohort.commit();
}
return ops;
}
/**
* 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>
* If aborts we're successful throws supplied exception
*
* @param originalCause
* @throws IllegalStateException
* if abort failed.
*/
- private void abortBlocking(final TransactionCommitFailedException originalCause) throws TransactionCommitFailedException {
+ private void abortBlocking(final TransactionCommitFailedException originalCause)
+ throws TransactionCommitFailedException {
Exception cause = originalCause;
try {
abortAsyncAll().get();
private ListenableFuture<Void> abortAsyncAll() {
final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
- int i = 0;
+ int index = 0;
for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
- ops[i++] = cohort.abort();
+ ops[index++] = cohort.abort();
}
/*
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
-
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.common.api.TransactionChainListener;
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
-import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.TransactionChainListener;
+import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
final class DOMDataBrokerTransactionChainImpl extends AbstractDOMForwardedTransactionFactory<DOMStoreTransactionChain>
implements DOMTransactionChain {
- private static enum State {
+ private enum State {
RUNNING,
CLOSING,
CLOSED,
private volatile int counter = 0;
/**
+ *Constructor with args.
*
* @param chainId
* ID of transaction chain
* @throws NullPointerException
* If any of arguments is null.
*/
- public DOMDataBrokerTransactionChainImpl(final long chainId,
+ DOMDataBrokerTransactionChainImpl(final long chainId,
final Map<LogicalDatastoreType, DOMStoreTransactionChain> chains,
final AbstractDOMDataBroker broker, final TransactionChainListener listener) {
super(chains);
}
@Override
- public void onFailure(final Throwable t) {
- transactionFailed(transaction, t);
+ public void onFailure(final Throwable throwable) {
+ transactionFailed(transaction, throwable);
}
});
*/
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
-
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.common.api.ReadFailedException;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import java.util.Map;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.ReadFailedException;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
*/
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
-
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
* <li>{@link #delete(LogicalDatastoreType, YangInstanceIdentifier)}
* <li>{@link #merge(LogicalDatastoreType, YangInstanceIdentifier, NormalizedNode)}
* </ul>
+ *
* <p>
* {@link #submit()} will result in invocation of
* {@link DOMDataCommitImplementation#submit(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction, Iterable)}
class DOMForwardedWriteTransaction<T extends DOMStoreWriteTransaction> extends
AbstractDOMForwardedCompositeTransaction<LogicalDatastoreType, T> implements DOMDataTreeWriteTransaction {
@SuppressWarnings("rawtypes")
- private static final AtomicReferenceFieldUpdater<DOMForwardedWriteTransaction, AbstractDOMForwardedTransactionFactory> IMPL_UPDATER =
- AtomicReferenceFieldUpdater.newUpdater(DOMForwardedWriteTransaction.class, AbstractDOMForwardedTransactionFactory.class, "commitImpl");
+ private static final AtomicReferenceFieldUpdater<DOMForwardedWriteTransaction,
+ AbstractDOMForwardedTransactionFactory> IMPL_UPDATER = AtomicReferenceFieldUpdater.newUpdater(
+ DOMForwardedWriteTransaction.class, AbstractDOMForwardedTransactionFactory.class, "commitImpl");
@SuppressWarnings("rawtypes")
private static final AtomicReferenceFieldUpdater<DOMForwardedWriteTransaction, Future> FUTURE_UPDATER =
AtomicReferenceFieldUpdater.newUpdater(DOMForwardedWriteTransaction.class, Future.class, "commitFuture");
* set appropriately on {@link #submit()} and {@link #cancel()} via
* {@link AtomicReferenceFieldUpdater#lazySet(Object, Object)}.
*
+ *<p>
* Lazy set is safe for use because it is only referenced to in the
* {@link #cancel()} slow path, where we will busy-wait for it. The
* fast path gets the benefit of a store-store barrier instead of the
}
@Override
- public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+ public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
+ final NormalizedNode<?, ?> data) {
checkRunning(commitImpl);
getSubtransaction(store).write(path, data);
}
}
@Override
- public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+ public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
+ final NormalizedNode<?, ?> data) {
checkRunning(commitImpl);
getSubtransaction(store).merge(path, data);
}
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.spi.SimpleDOMMountPoint;
-
-import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
-import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.mdsal.dom.api.DOMService;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.MutableClassToInstanceMap;
import java.util.HashMap;
import java.util.Map;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMService;
+import org.opendaylight.mdsal.dom.spi.SimpleDOMMountPoint;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.util.ListenerRegistry;
public ObjectRegistration<DOMMountPoint> registerMountPoint(final DOMMountPoint mountPoint) {
synchronized (mountPoints) {
- Preconditions.checkState(!mountPoints.containsKey(mountPoint.getIdentifier()), "Mount point already exists");
+ Preconditions.checkState(!mountPoints.containsKey(mountPoint.getIdentifier()),
+ "Mount point already exists");
mountPoints.put(mountPoint.getIdentifier(), mountPoint);
}
notifyMountCreated(mountPoint.getIdentifier());
private final class MountRegistration implements ObjectRegistration<DOMMountPoint> {
private final DOMMountPoint mountPoint;
- public MountRegistration(final DOMMountPoint mountPoint) {
+ MountRegistration(final DOMMountPoint mountPoint) {
this.mountPoint = mountPoint;
}
*/
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener;
-import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
-
-import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
-import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
-import org.opendaylight.mdsal.dom.api.DOMNotificationService;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
+import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
+import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener;
+import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.util.ListenerRegistry;
* Joint implementation of {@link DOMNotificationPublishService} and {@link DOMNotificationService}. Provides
* routing of notifications from publishers to subscribers.
*
+ *<p>
* Internal implementation works by allocating a two-handler Disruptor. The first handler delivers notifications
* to subscribed listeners and the second one notifies whoever may be listening on the returned future. Registration
* state tracking is performed by a simple immutable multimap -- when a registration or unregistration occurs we
* re-generate the entire map from scratch and set it atomically. While registrations/unregistrations synchronize
* on this instance, notifications do not take any locks here.
*
- * The fully-blocking {@link #publish(long, DOMNotification, Collection)} and non-blocking {@link #offerNotification(DOMNotification)}
- * are realized using the Disruptor's native operations. The bounded-blocking {@link #offerNotification(DOMNotification, long, TimeUnit)}
+ *<p>
+ * The fully-blocking {@link #publish(long, DOMNotification, Collection)}
+ * and non-blocking {@link #offerNotification(DOMNotification)}
+ * are realized using the Disruptor's native operations. The bounded-blocking {@link
+ * #offerNotification(DOMNotification, long, TimeUnit)}
* is realized by arming a background wakeup interrupt.
*/
public final class DOMNotificationRouter implements AutoCloseable, DOMNotificationPublishService,
private static final Logger LOG = LoggerFactory.getLogger(DOMNotificationRouter.class);
private static final ListenableFuture<Void> NO_LISTENERS = Futures.immediateFuture(null);
- private static final WaitStrategy DEFAULT_STRATEGY = PhasedBackoffWaitStrategy.withLock(1L, 30L, TimeUnit.MILLISECONDS);
- private static final EventHandler<DOMNotificationRouterEvent> DISPATCH_NOTIFICATIONS = new EventHandler<DOMNotificationRouterEvent>() {
+ private static final WaitStrategy DEFAULT_STRATEGY = PhasedBackoffWaitStrategy.withLock(
+ 1L, 30L, TimeUnit.MILLISECONDS);
+ private static final EventHandler<DOMNotificationRouterEvent> DISPATCH_NOTIFICATIONS =
+ new EventHandler<DOMNotificationRouterEvent>() {
@Override
- public void onEvent(final DOMNotificationRouterEvent event, final long sequence, final boolean endOfBatch) throws Exception {
+ public void onEvent(final DOMNotificationRouterEvent event, final long sequence,
+ final boolean endOfBatch) throws Exception {
event.deliverNotification();
}
};
- private static final EventHandler<DOMNotificationRouterEvent> NOTIFY_FUTURE = new EventHandler<DOMNotificationRouterEvent>() {
+ private static final EventHandler<DOMNotificationRouterEvent> NOTIFY_FUTURE =
+ new EventHandler<DOMNotificationRouterEvent>() {
@Override
public void onEvent(final DOMNotificationRouterEvent event, final long sequence, final boolean endOfBatch) {
event.setFuture();
private final Disruptor<DOMNotificationRouterEvent> disruptor;
private final ExecutorService executor;
- private volatile Multimap<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> listeners = ImmutableMultimap.of();
- private final ListenerRegistry<DOMNotificationSubscriptionListener> subscriptionListeners = ListenerRegistry.create();
+ private volatile Multimap<SchemaPath, ListenerRegistration<? extends
+ DOMNotificationListener>> listeners = ImmutableMultimap.of();
+ private final ListenerRegistry<DOMNotificationSubscriptionListener> subscriptionListeners =
+ ListenerRegistry.create();
@SuppressWarnings("unchecked")
private DOMNotificationRouter(final ExecutorService executor, final int queueDepth, final WaitStrategy strategy) {
this.executor = Preconditions.checkNotNull(executor);
- disruptor = new Disruptor<>(DOMNotificationRouterEvent.FACTORY, queueDepth, executor, ProducerType.MULTI, strategy);
+ disruptor = new Disruptor<>(DOMNotificationRouterEvent.FACTORY,
+ queueDepth, executor, ProducerType.MULTI, strategy);
disruptor.handleEventsWith(DISPATCH_NOTIFICATIONS);
disruptor.after(DISPATCH_NOTIFICATIONS).handleEventsWith(NOTIFY_FUTURE);
disruptor.start();
return new DOMNotificationRouter(executor, queueDepth, DEFAULT_STRATEGY);
}
- public static DOMNotificationRouter create(final int queueDepth, final long spinTime, final long parkTime, final TimeUnit unit) {
+ public static DOMNotificationRouter create(final int queueDepth, final long spinTime,
+ final long parkTime, final TimeUnit unit) {
final ExecutorService executor = Executors.newCachedThreadPool();
final WaitStrategy strategy = PhasedBackoffWaitStrategy.withLock(spinTime, parkTime, unit);
}
@Override
- public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener, final Collection<SchemaPath> types) {
+ public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(
+ final T listener, final Collection<SchemaPath> types) {
final ListenerRegistration<T> reg = new AbstractListenerRegistration<T>(listener) {
@Override
protected void removeRegistration() {
final ListenerRegistration<T> me = this;
synchronized (DOMNotificationRouter.this) {
- replaceListeners(ImmutableMultimap.copyOf(Multimaps.filterValues(listeners, new Predicate<ListenerRegistration<? extends DOMNotificationListener>>() {
- @Override
- public boolean apply(final ListenerRegistration<? extends DOMNotificationListener> input) {
- return input != me;
- }
- })));
+ replaceListeners(ImmutableMultimap.copyOf(Multimaps.filterValues(listeners,
+ new Predicate<ListenerRegistration<? extends DOMNotificationListener>>() {
+ @Override
+ public boolean apply(final ListenerRegistration<? extends DOMNotificationListener> input) {
+ return input != me;
+ }
+ })));
}
}
};
if (!types.isEmpty()) {
- final Builder<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> b = ImmutableMultimap.builder();
+ final Builder<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> b =
+ ImmutableMultimap.builder();
b.putAll(listeners);
for (final SchemaPath t : types) {
}
@Override
- public <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener, final SchemaPath... types) {
+ public <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(
+ final T listener, final SchemaPath... types) {
return registerNotificationListener(listener, Arrays.asList(types));
}
/**
- * Swaps registered listeners and triggers notification update
+ * Swaps registered listeners and triggers notification update.
*
- * @param newListeners
+ * @param newListeners is used to notify listenerTypes changed
*/
private void replaceListeners(
final Multimap<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> newListeners) {
notifyListenerTypesChanged(newListeners.keySet());
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
private void notifyListenerTypesChanged(final Set<SchemaPath> typesAfter) {
- final List<ListenerRegistration<DOMNotificationSubscriptionListener>> listenersAfter =ImmutableList.copyOf(subscriptionListeners.getListeners());
+ final List<ListenerRegistration<DOMNotificationSubscriptionListener>> listenersAfter =
+ ImmutableList.copyOf(subscriptionListeners.getListeners());
executor.submit(new Runnable() {
@Override
return subscriptionListeners.registerWithType(listener);
}
- private ListenableFuture<Void> publish(final long seq, final DOMNotification notification, final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers) {
+ private ListenableFuture<Void> publish(final long seq, final DOMNotification notification,
+ final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers) {
final DOMNotificationRouterEvent event = disruptor.get(seq);
final ListenableFuture<Void> future = event.initialize(notification, subscribers);
disruptor.getRingBuffer().publish(seq);
}
@Override
- public ListenableFuture<? extends Object> putNotification(final DOMNotification notification) throws InterruptedException {
- final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers = listeners.get(notification.getType());
+ public ListenableFuture<? extends Object> putNotification(final DOMNotification notification)
+ throws InterruptedException {
+ final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers =
+ listeners.get(notification.getType());
if (subscribers.isEmpty()) {
return NO_LISTENERS;
}
return publish(seq, notification, subscribers);
}
- private ListenableFuture<? extends Object> tryPublish(final DOMNotification notification, final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers) {
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ private ListenableFuture<? extends Object> tryPublish(final DOMNotification notification,
+ final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers) {
final long seq;
try {
- seq = disruptor.getRingBuffer().tryNext();
+ seq = disruptor.getRingBuffer().tryNext();
} catch (final InsufficientCapacityException e) {
return DOMNotificationPublishService.REJECTED;
}
@Override
public ListenableFuture<? extends Object> offerNotification(final DOMNotification notification) {
- final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers = listeners.get(notification.getType());
+ final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers =
+ listeners.get(notification.getType());
if (subscribers.isEmpty()) {
return NO_LISTENERS;
}
@Override
public ListenableFuture<? extends Object> offerNotification(final DOMNotification notification, final long timeout,
final TimeUnit unit) throws InterruptedException {
- final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers = listeners.get(notification.getType());
+ final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers =
+ listeners.get(notification.getType());
if (subscribers.isEmpty()) {
return NO_LISTENERS;
}
*/
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
-
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import com.lmax.disruptor.EventFactory;
import java.util.Collection;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
/**
* so they do have mutable state.
*/
final class DOMNotificationRouterEvent {
- public static final EventFactory<DOMNotificationRouterEvent> FACTORY = new EventFactory<DOMNotificationRouterEvent>() {
+ public static final EventFactory<DOMNotificationRouterEvent> FACTORY =
+ new EventFactory<DOMNotificationRouterEvent>() {
@Override
public DOMNotificationRouterEvent newInstance() {
return new DOMNotificationRouterEvent();
// Hidden on purpose, initialized in initialize()
}
- ListenableFuture<Void> initialize(final DOMNotification notification, final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers) {
+ ListenableFuture<Void> initialize(final DOMNotification notification,
+ final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers) {
this.notification = Preconditions.checkNotNull(notification);
this.subscribers = Preconditions.checkNotNull(subscribers);
this.future = SettableFuture.create();
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.Collection;
import java.util.Collections;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.ThreadFactory;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener;
import org.opendaylight.mdsal.dom.api.DOMRpcException;
import org.opendaylight.mdsal.dom.spi.AbstractDOMRpcImplementationRegistration;
import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
public final class DOMRpcRouter implements AutoCloseable, DOMRpcService, DOMRpcProviderService, SchemaContextListener {
- private static final ThreadFactory THREAD_FACTORY = new ThreadFactoryBuilder().setNameFormat("DOMRpcRouter-listener-%s").setDaemon(true).build();
+ private static final ThreadFactory THREAD_FACTORY = new ThreadFactoryBuilder().setNameFormat(
+ "DOMRpcRouter-listener-%s").setDaemon(true).build();
private final ExecutorService listenerNotifier = Executors.newSingleThreadExecutor(THREAD_FACTORY);
@GuardedBy("this")
private Collection<ListenerRegistration<? extends DOMRpcAvailabilityListener>> listeners = Collections.emptyList();
private volatile DOMRpcRoutingTable routingTable = DOMRpcRoutingTable.EMPTY;
- @Override
- public <T extends DOMRpcImplementation> DOMRpcImplementationRegistration<T> registerRpcImplementation(final T implementation, final DOMRpcIdentifier... rpcs) {
- return registerRpcImplementation(implementation, ImmutableSet.copyOf(rpcs));
- }
-
- private static Collection<DOMRpcIdentifier> notPresentRpcs(final DOMRpcRoutingTable table, final Collection<DOMRpcIdentifier> candidates) {
+ private static Collection<DOMRpcIdentifier> notPresentRpcs(final DOMRpcRoutingTable table,
+ final Collection<DOMRpcIdentifier> candidates) {
return ImmutableSet.copyOf(Collections2.filter(candidates, new Predicate<DOMRpcIdentifier>() {
@Override
public boolean apply(final DOMRpcIdentifier input) {
}));
}
- private synchronized void removeRpcImplementation(final DOMRpcImplementation implementation, final Set<DOMRpcIdentifier> rpcs) {
+ private synchronized void removeRpcImplementation(final DOMRpcImplementation implementation,
+ final Set<DOMRpcIdentifier> rpcs) {
final DOMRpcRoutingTable oldTable = routingTable;
final DOMRpcRoutingTable newTable = oldTable.remove(implementation, rpcs);
}
@Override
- public synchronized <T extends DOMRpcImplementation> DOMRpcImplementationRegistration<T> registerRpcImplementation(final T implementation, final Set<DOMRpcIdentifier> rpcs) {
+ public <T extends DOMRpcImplementation> DOMRpcImplementationRegistration<T> registerRpcImplementation(
+ final T implementation, final DOMRpcIdentifier... rpcs) {
+ return registerRpcImplementation(implementation, ImmutableSet.copyOf(rpcs));
+ }
+
+ @Override
+ public synchronized <T extends DOMRpcImplementation> DOMRpcImplementationRegistration<T>
+ registerRpcImplementation(final T implementation, final Set<DOMRpcIdentifier> rpcs) {
final DOMRpcRoutingTable oldTable = routingTable;
final DOMRpcRoutingTable newTable = oldTable.add(implementation, rpcs);
}
@Override
- public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath type, final NormalizedNode<?, ?> input) {
+ public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath type,
+ final NormalizedNode<?, ?> input) {
return routingTable.invokeRpc(type, input);
}
}
@Override
- public synchronized <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T listener) {
+ public synchronized <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(
+ final T listener) {
final ListenerRegistration<T> ret = new AbstractListenerRegistration<T>(listener) {
@Override
protected void removeRegistration() {
@Override
public void run() {
for (final Entry<SchemaPath, Set<YangInstanceIdentifier>> e : capturedRpcs.entrySet()) {
- listener.onRpcAvailable(Collections2.transform(e.getValue(), new Function<YangInstanceIdentifier, DOMRpcIdentifier>() {
- @Override
- public DOMRpcIdentifier apply(final YangInstanceIdentifier input) {
- return DOMRpcIdentifier.create(e.getKey(), input);
- }
- }));
+ listener.onRpcAvailable(Collections2.transform(e.getValue(),
+ new Function<YangInstanceIdentifier, DOMRpcIdentifier>() {
+ @Override
+ public DOMRpcIdentifier apply(final YangInstanceIdentifier input) {
+ return DOMRpcIdentifier.create(e.getKey(), input);
+ }
+ }));
}
}
});
*/
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.api.DOMRpcException;
-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 com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.opendaylight.mdsal.dom.api.DOMRpcException;
+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.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
final class DOMRpcRoutingTable {
- private static final QName CONTEXT_REFERENCE = QName.create("urn:opendaylight:yang:extension:yang-ext", "2013-07-09", "context-reference").intern();
+ private static final QName CONTEXT_REFERENCE = QName.create("urn:opendaylight:yang:extension:yang-ext",
+ "2013-07-09", "context-reference").intern();
static final DOMRpcRoutingTable EMPTY = new DOMRpcRoutingTable();
private static final Function<AbstractDOMRpcRoutingTableEntry, Set<YangInstanceIdentifier>> EXTRACT_IDENTIFIERS =
new Function<AbstractDOMRpcRoutingTableEntry, Set<YangInstanceIdentifier>>() {
- @Override
- public Set<YangInstanceIdentifier> apply(final AbstractDOMRpcRoutingTableEntry input) {
- return input.registeredIdentifiers();
- }
+ @Override
+ public Set<YangInstanceIdentifier> apply(final AbstractDOMRpcRoutingTableEntry input) {
+ return input.registeredIdentifiers();
+ }
};
private final Map<SchemaPath, AbstractDOMRpcRoutingTableEntry> rpcs;
private final SchemaContext schemaContext;
schemaContext = null;
}
- private DOMRpcRoutingTable(final Map<SchemaPath, AbstractDOMRpcRoutingTableEntry> rpcs, final SchemaContext schemaContext) {
+ private DOMRpcRoutingTable(final Map<SchemaPath, AbstractDOMRpcRoutingTableEntry> rpcs,
+ final SchemaContext schemaContext) {
this.rpcs = Preconditions.checkNotNull(rpcs);
this.schemaContext = schemaContext;
}
- private static ListMultimap<SchemaPath, YangInstanceIdentifier> decomposeIdentifiers(final Set<DOMRpcIdentifier> rpcs) {
+ private static ListMultimap<SchemaPath, YangInstanceIdentifier> decomposeIdentifiers(
+ final Set<DOMRpcIdentifier> rpcs) {
final ListMultimap<SchemaPath, YangInstanceIdentifier> ret = LinkedListMultimap.create();
for (DOMRpcIdentifier i : rpcs) {
ret.put(i.getType(), i.getContextReference());
return null;
}
- private static AbstractDOMRpcRoutingTableEntry createRpcEntry(final SchemaContext context, final SchemaPath key, final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> implementations) {
+ private static AbstractDOMRpcRoutingTableEntry createRpcEntry(final SchemaContext context, final SchemaPath key,
+ final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> implementations) {
final RpcDefinition rpcDef = findRpcDefinition(context, key);
if (rpcDef != null) {
final ContainerSchemaNode input = rpcDef.getInput();
for (DataSchemaNode c : input.getChildNodes()) {
for (UnknownSchemaNode extension : c.getUnknownSchemaNodes()) {
if (CONTEXT_REFERENCE.equals(extension.getNodeType())) {
- final YangInstanceIdentifier keyId = YangInstanceIdentifier.builder().node(c.getQName()).build();
+ final YangInstanceIdentifier keyId =
+ YangInstanceIdentifier.builder().node(c.getQName()).build();
return new RoutedDOMRpcRoutingTableEntry(rpcDef, keyId, implementations);
}
}
CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath type, final NormalizedNode<?, ?> input) {
final AbstractDOMRpcRoutingTableEntry entry = rpcs.get(type);
if (entry == null) {
- return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available", type));
+ return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(
+ new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available", type));
}
return entry.invokeRpc(input);
*/
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.api.DOMRpcException;
-import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.CheckedFuture;
import java.util.List;
import java.util.Map;
+import org.opendaylight.mdsal.dom.api.DOMRpcException;
+import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
+import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
+import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
private static final YangInstanceIdentifier ROOT = YangInstanceIdentifier.builder().build();
private final DOMRpcIdentifier rpcId;
- private GlobalDOMRpcRoutingTableEntry(final DOMRpcIdentifier rpcId, final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
+ private GlobalDOMRpcRoutingTableEntry(final DOMRpcIdentifier rpcId, final Map<YangInstanceIdentifier,
+ List<DOMRpcImplementation>> impls) {
super(rpcId.getType(), impls);
this.rpcId = Preconditions.checkNotNull(rpcId);
}
// We do not need the RpcDefinition, but this makes sure we do not
// forward something we don't know to be an RPC.
- GlobalDOMRpcRoutingTableEntry(final RpcDefinition def, final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
+ GlobalDOMRpcRoutingTableEntry(final RpcDefinition def, final Map<YangInstanceIdentifier,
+ List<DOMRpcImplementation>> impls) {
super(def.getPath(), impls);
this.rpcId = DOMRpcIdentifier.create(def.getPath());
}
}
@Override
- protected GlobalDOMRpcRoutingTableEntry newInstance(final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
+ protected GlobalDOMRpcRoutingTableEntry newInstance(final Map<YangInstanceIdentifier,
+ List<DOMRpcImplementation>> impls) {
return new GlobalDOMRpcRoutingTableEntry(rpcId, impls);
}
}
\ No newline at end of file
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.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final DOMRpcIdentifier globalRpcId;
private final YangInstanceIdentifier keyId;
- private RoutedDOMRpcRoutingTableEntry(final DOMRpcIdentifier globalRpcId, final YangInstanceIdentifier keyId, final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
+ private RoutedDOMRpcRoutingTableEntry(final DOMRpcIdentifier globalRpcId,
+ final YangInstanceIdentifier keyId,
+ final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
super(globalRpcId.getType(), impls);
this.keyId = Preconditions.checkNotNull(keyId);
this.globalRpcId = Preconditions.checkNotNull(globalRpcId);
}
- RoutedDOMRpcRoutingTableEntry(final RpcDefinition def, final YangInstanceIdentifier keyId, final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
+ RoutedDOMRpcRoutingTableEntry(final RpcDefinition def, final YangInstanceIdentifier keyId,
+ final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
super(def.getPath(), impls);
this.keyId = Preconditions.checkNotNull(keyId);
this.globalRpcId = DOMRpcIdentifier.create(def.getPath());
if (impls != null) {
return impls.get(0).invokeRpc(globalRpcId, input);
} else {
- return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available", getSchemaPath()));
+ return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(
+ new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available",
+ getSchemaPath()));
}
}
@Override
- protected RoutedDOMRpcRoutingTableEntry newInstance(final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
+ protected RoutedDOMRpcRoutingTableEntry newInstance(final Map<YangInstanceIdentifier,
+ List<DOMRpcImplementation>> impls) {
return new RoutedDOMRpcRoutingTableEntry(globalRpcId, keyId, impls);
}
}
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.spi.store.DOMStore;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
-
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.RejectedExecutionException;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.spi.store.DOMStore;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
import org.opendaylight.yangtools.util.DurationStatisticsTracker;
import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture;
import org.slf4j.Logger;
* Implementation of blocking three phase commit coordinator, which which
* supports coordination on multiple {@link DOMStoreThreePhaseCommitCohort}.
*
+ *<p>
* This implementation does not support cancellation of commit,
*
+ *<p>
* In order to advance to next phase of three phase commit all subtasks of
* previous step must be finish.
*
+ *<p>
* This executor does not have an upper bound on subtask timeout.
*/
public class SerializedDOMDataBroker extends AbstractDOMDataBroker {
private final ListeningExecutorService executor;
/**
- *
* Construct DOMDataCommitCoordinator which uses supplied executor to
* process commit coordinations.
*
- * @param executor
+ * @param datastores the Map of backing DOMStore instances
+ * @param executor the ListeningExecutorService to use
*/
- public SerializedDOMDataBroker(final Map<LogicalDatastoreType, DOMStore> datastores, final ListeningExecutorService executor) {
+ public SerializedDOMDataBroker(final Map<LogicalDatastoreType, DOMStore> datastores,
+ final ListeningExecutorService executor) {
super(datastores);
this.executor = Preconditions.checkNotNull(executor, "executor must not be null.");
}
}
@Override
- protected CheckedFuture<Void,TransactionCommitFailedException> submit(final DOMDataTreeWriteTransaction transaction,
+ protected CheckedFuture<Void,TransactionCommitFailedException> submit(
+ final DOMDataTreeWriteTransaction transaction,
final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
Preconditions.checkArgument(transaction != null, "Transaction must not be null.");
Preconditions.checkArgument(cohorts != null, "Cohorts must not be null.");
try {
commitFuture = executor.submit(new CommitCoordinationTask(transaction, cohorts,
commitStatsTracker));
- } catch(RejectedExecutionException e) {
- LOG.error("The commit executor's queue is full - submit task was rejected. \n" +
- executor, e);
+ } catch (RejectedExecutionException e) {
+ LOG.error("The commit executor's queue is full - submit task was rejected. \n"
+ + executor, e);
return Futures.immediateFailedCheckedFuture(
new TransactionCommitFailedException(
"Could not submit the commit task - the commit queue capacity has been exceeded.", e));
*/
package org.opendaylight.mdsal.dom.broker;
+import com.google.common.base.Preconditions;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeShard;
-
-import com.google.common.base.Preconditions;
import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
final class ShardRegistration<T extends DOMDataTreeShard> extends AbstractListenerRegistration<T> {
}
@Override
- public <T extends DOMDataTreeShard> ListenerRegistration<T> registerDataTreeShard(final DOMDataTreeIdentifier prefix, final T shard, final DOMDataTreeProducer producer) throws DOMDataTreeShardingConflictException {
+ public <T extends DOMDataTreeShard> ListenerRegistration<T> registerDataTreeShard(
+ final DOMDataTreeIdentifier prefix, final T shard, final DOMDataTreeProducer producer)
+ throws DOMDataTreeShardingConflictException {
- final DOMDataTreeIdentifier firstSubtree = Iterables.getOnlyElement(((ShardedDOMDataTreeProducer) producer).getSubtrees());
- Preconditions.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 than the producer has claimed");
+ final DOMDataTreeIdentifier firstSubtree = Iterables.getOnlyElement(((
+ ShardedDOMDataTreeProducer) producer).getSubtrees());
+ Preconditions.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"
+ + " than the producer has claimed");
final ShardRegistration<T> reg;
final ShardRegistration<?> parentReg;
}
@GuardedBy("this")
- private DOMDataTreeProducer createProducer(final Collection<DOMDataTreeIdentifier> subtrees, final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap) {
+ private DOMDataTreeProducer createProducer(final Collection<DOMDataTreeIdentifier> subtrees,
+ final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap) {
// Record the producer's attachment points
final DOMDataTreeProducer ret = ShardedDOMDataTreeProducer.create(this, subtrees, shardMap);
for (final DOMDataTreeIdentifier subtree : subtrees) {
return createProducer(subtrees, shardMap);
}
- synchronized DOMDataTreeProducer createProducer(final ShardedDOMDataTreeProducer parent, final Collection<DOMDataTreeIdentifier> subtrees) {
+ synchronized DOMDataTreeProducer createProducer(final ShardedDOMDataTreeProducer parent,
+ final Collection<DOMDataTreeIdentifier> subtrees) {
Preconditions.checkNotNull(parent);
final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap = new HashMap<>();
return createProducer(subtrees, shardMap);
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Override
public synchronized <T extends DOMDataTreeListener> ListenerRegistration<T> registerListener(final T listener,
final Collection<DOMDataTreeIdentifier> subtrees, final boolean allowRxMerges,
};
}
- private static void simpleLoopCheck(final Collection<DOMDataTreeIdentifier> listen, final Set<DOMDataTreeIdentifier> writes)
- throws DOMDataTreeLoopException {
- for(final DOMDataTreeIdentifier listenPath : listen) {
+ private static void simpleLoopCheck(final Collection<DOMDataTreeIdentifier> listen,
+ final Set<DOMDataTreeIdentifier> writes) throws DOMDataTreeLoopException {
+ for (final DOMDataTreeIdentifier listenPath : listen) {
for (final DOMDataTreeIdentifier writePath : writes) {
if (listenPath.contains(writePath)) {
throw new DOMDataTreeLoopException(String.format(
private final LogicalDatastoreType type;
- public StoreListener(LogicalDatastoreType type) {
+ StoreListener(LogicalDatastoreType type) {
this.type = type;
}
idToShard = ImmutableMap.copyOf(shardMap);
}
- private BiMap<DOMDataTreeIdentifier, DOMDataTreeShardProducer> mapIdsToProducer(final Multimap<DOMDataTreeShard, DOMDataTreeIdentifier> shardToId) {
+ private BiMap<DOMDataTreeIdentifier, DOMDataTreeShardProducer> mapIdsToProducer(final Multimap<DOMDataTreeShard,
+ DOMDataTreeIdentifier> shardToId) {
final Builder<DOMDataTreeIdentifier, DOMDataTreeShardProducer> idToProducerBuilder = ImmutableBiMap.builder();
for (final Entry<DOMDataTreeShard, Collection<DOMDataTreeIdentifier>> entry : shardToId.asMap().entrySet()) {
if (entry.getKey() instanceof WriteableDOMDataTreeShard) {
//create a single producer for all prefixes in a single shard
- final DOMDataTreeShardProducer producer = ((WriteableDOMDataTreeShard) entry.getKey()).createProducer(entry.getValue());
+ final DOMDataTreeShardProducer producer = ((WriteableDOMDataTreeShard) entry.getKey())
+ .createProducer(entry.getValue());
// id mapped to producers
for (final DOMDataTreeIdentifier id : entry.getValue()) {
idToProducerBuilder.put(id, producer);
}
@GuardedBy("this")
- private DOMDataTreeProducer lookupChild(final DOMDataTreeIdentifier s) {
+ private DOMDataTreeProducer lookupChild(final DOMDataTreeIdentifier domDataTreeIdentifier) {
for (final Entry<DOMDataTreeIdentifier, DOMDataTreeProducer> e : children.entrySet()) {
- if (e.getKey().contains(s)) {
+ if (e.getKey().contains(domDataTreeIdentifier)) {
return e.getValue();
}
}
// Check if part of the requested subtree is not delegated to a child.
for (final DOMDataTreeIdentifier c : children.keySet()) {
if (s.contains(c)) {
- throw new IllegalArgumentException(String.format("Subtree %s cannot be delegated as it is superset of already-delegated %s", s, c));
+ throw new IllegalArgumentException(String.format("Subtree %s cannot be delegated as it is"
+ + " superset of already-delegated %s", s, c));
}
}
}
final Map<DOMDataTreeIdentifier, DOMDataTreeProducer> childProducers) {
this.producer = Preconditions.checkNotNull(producer);
idToTransaction = new HashMap<>();
- Preconditions.checkNotNull(idToProducer).forEach((id, prod) -> idToTransaction.put(id, prod.createTransaction()));
+ Preconditions.checkNotNull(idToProducer).forEach((id, prod) -> idToTransaction.put(
+ id, prod.createTransaction()));
this.identifier = "SHARDED-DOM-" + COUNTER.getAndIncrement();
childProducers.forEach((id, prod) -> childBoundaries.add(id.getRootIdentifier()));
}
return e.getValue();
}
}
- throw new IllegalArgumentException(String.format("Path %s is not accessible from transaction %s", prefix, this));
+ throw new IllegalArgumentException(String.format("Path %s is not accessible from transaction %s",
+ prefix, this));
}
@Override
}
@Override
- public void onFailure(final Throwable t) {
- ret.setException(t);
+ public void onFailure(final Throwable exp) {
+ ret.setException(exp);
}
});
private final DOMDataTreeWriteCursor delegate;
private final Deque<PathArgument> path = new LinkedList<>();
- public DelegatingCursor(final DOMDataTreeWriteCursor delegate, final DOMDataTreeIdentifier rootPosition) {
+ DelegatingCursor(final DOMDataTreeWriteCursor delegate, final DOMDataTreeIdentifier rootPosition) {
this.delegate = delegate;
path.addAll(rootPosition.getRootIdentifier().getPathArguments());
}
childBoundaries.forEach(id -> {
if (id.contains(yid)) {
path.removeLast();
- throw new IllegalArgumentException("Path {" + yid + "} is not available to this cursor since it's already claimed by a child producer");
+ throw new IllegalArgumentException("Path {" + yid + "} is not available to this cursor"
+ + " since it's already claimed by a child producer");
}
});
path.removeLast();
}
@Override
- public void onFailure(final Throwable t) {
+ public void onFailure(final Throwable throwable) {
reg.close();
}
});
checkRunning();
LOG.debug("{}: Invoking exists at {}:{}", txIdentifier, store, path);
final Function<Optional<NormalizedNode<?, ?>>, Boolean> transform =
- optionalNode -> optionalNode.isPresent() ? Boolean.TRUE : Boolean.FALSE;
+ optionalNode -> optionalNode.isPresent() ? Boolean.TRUE : Boolean.FALSE;
final ListenableFuture<Boolean> existsResult = Futures.transform(read(store, path), transform);
return Futures.makeChecked(existsResult, ReadFailedException.MAPPER);
}
private final SettableFuture<Optional<NormalizedNode<?, ?>>> readResultFuture;
- public ReadShardedListener(final SettableFuture<Optional<NormalizedNode<?, ?>>> future) {
+ ReadShardedListener(final SettableFuture<Optional<NormalizedNode<?, ?>>> future) {
this.readResultFuture = Preconditions.checkNotNull(future);
}
// We chain all exceptions and return aggregated one
readResultFuture.setException(new DOMDataTreeListeningException("Aggregated DOMDataTreeListening exception",
- causes.stream().reduce((e1, e2) ->
- {
+ causes.stream().reduce((e1, e2) -> {
e1.addSuppressed(e2);
return e1;
}).get()));
}
@Override
- public void onFailure(final Throwable t) {
+ public void onFailure(final Throwable throwable) {
// We don't have to do nothing here,
// tx should take car of it
}
@Nonnull
@Override
- public <T extends DOMDataTreeListener> ListenerRegistration<T>
- registerListener(@Nonnull final T listener, @Nonnull final Collection<DOMDataTreeIdentifier> subtrees,
+ public <T extends DOMDataTreeListener> ListenerRegistration<T> registerListener(
+ @Nonnull final T listener, @Nonnull final Collection<DOMDataTreeIdentifier> subtrees,
final boolean allowRxMerges, @Nonnull final Collection<DOMDataTreeProducer> producers)
throws DOMDataTreeLoopException {
return delegateTreeService.registerListener(listener, subtrees, allowRxMerges, producers);
}
private void closeProducers() {
- producerMap.values().forEach(domDataTreeProducer ->
- {
+ producerMap.values().forEach(domDataTreeProducer -> {
try {
domDataTreeProducer.close();
} catch (final DOMDataTreeProducerException e) {
@Override
public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store,
- final YangInstanceIdentifier path) {
+ final YangInstanceIdentifier path) {
final SettableFuture<Optional<NormalizedNode<?, ?>>> readResult = SettableFuture.create();
Futures.addCallback(previousWriteTxFuture, new FutureCallback<Void>() {
}
@Override
- public void onFailure(final Throwable t) {
- txChain.transactionFailed(TransactionChainReadTransaction.this, t);
- readResult.setException(t);
+ public void onFailure(final Throwable throwable) {
+ txChain.transactionFailed(TransactionChainReadTransaction.this, throwable);
+ readResult.setException(throwable);
}
});
}
@Override
- public void onFailure(final Throwable t) {
+ public void onFailure(final Throwable throwable) {
// we don't have to notify txchain about this failure
// failed write transaction should do this
- readResult.setException(t);
+ readResult.setException(throwable);
}
});
public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
final YangInstanceIdentifier path) {
final Function<Optional<NormalizedNode<?, ?>>, Boolean> transform =
- optionalNode -> optionalNode.isPresent() ? Boolean.TRUE : Boolean.FALSE;
+ optionalNode -> optionalNode.isPresent() ? Boolean.TRUE : Boolean.FALSE;
final ListenableFuture<Boolean> existsResult = Futures.transform(read(store, path), transform);
return Futures.makeChecked(existsResult, ReadFailedException.MAPPER);
}
@Override
- public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+ public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
+ final NormalizedNode<?, ?> data) {
delegateTx.put(store, path, data);
}
@Override
- public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+ public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
+ final NormalizedNode<?, ?> data) {
delegateTx.merge(store, path, data);
}
}
@Override
- public void onFailure(final Throwable t) {
- txChain.transactionFailed(TransactionChainWriteTransaction.this, t);
+ public void onFailure(final Throwable throwable) {
+ txChain.transactionFailed(TransactionChainWriteTransaction.this, throwable);
}
});
package org.opendaylight.mdsal.dom.broker;
import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
-
import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
/**
*/
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.api.DOMRpcException;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import java.util.List;
import java.util.Map;
+import org.opendaylight.mdsal.dom.api.DOMRpcException;
+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.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
final class UnknownDOMRpcRoutingTableEntry extends AbstractDOMRpcRoutingTableEntry {
private final CheckedFuture<DOMRpcResult, DOMRpcException> unknownRpc;
- UnknownDOMRpcRoutingTableEntry(final SchemaPath schemaPath, final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
+ UnknownDOMRpcRoutingTableEntry(final SchemaPath schemaPath, final Map<YangInstanceIdentifier,
+ List<DOMRpcImplementation>> impls) {
super(schemaPath, impls);
unknownRpc = Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(
new DOMRpcImplementationNotAvailableException("SchemaPath %s is not resolved to an RPC", schemaPath));
}
@Override
- protected UnknownDOMRpcRoutingTableEntry newInstance(final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
+ protected UnknownDOMRpcRoutingTableEntry newInstance(final Map<YangInstanceIdentifier,
+ List<DOMRpcImplementation>> impls) {
return new UnknownDOMRpcRoutingTableEntry(getSchemaPath(), impls);
}
}
\ No newline at end of file
package org.opendaylight.mdsal.dom.broker.osgi;
import static com.google.common.base.Preconditions.checkState;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class OsgiBundleScanningSchemaService implements SchemaContextProvider, DOMSchemaService, ServiceTrackerCustomizer<SchemaContextListener, SchemaContextListener>, AutoCloseable {
+public class OsgiBundleScanningSchemaService implements SchemaContextProvider, DOMSchemaService,
+ ServiceTrackerCustomizer<SchemaContextListener, SchemaContextListener>, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(OsgiBundleScanningSchemaService.class);
private final ListenerRegistry<SchemaContextListener> listeners = new ListenerRegistry<>();
this.context = Preconditions.checkNotNull(context);
}
- public synchronized static OsgiBundleScanningSchemaService createInstance(final BundleContext ctx) {
+ public static synchronized OsgiBundleScanningSchemaService createInstance(final BundleContext ctx) {
Preconditions.checkState(instance == null);
instance = new OsgiBundleScanningSchemaService(ctx);
instance.start();
return instance;
}
- public synchronized static OsgiBundleScanningSchemaService getInstance() {
+ public static synchronized OsgiBundleScanningSchemaService getInstance() {
Preconditions.checkState(instance != null, "Global Instance was not instantiated");
return instance;
}
checkState(context != null);
LOG.debug("start() starting");
- listenerTracker = new ServiceTracker<>(context, SchemaContextListener.class, OsgiBundleScanningSchemaService.this);
- bundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING |
+ listenerTracker = new ServiceTracker<>(context, SchemaContextListener.class,
+ OsgiBundleScanningSchemaService.this);
+ bundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING
+ |
Bundle.STOPPING | Bundle.ACTIVE, scanner);
bundleTracker.open();
}
@Override
- public synchronized ListenerRegistration<SchemaContextListener> registerSchemaContextListener(final SchemaContextListener listener) {
+ public synchronized ListenerRegistration<SchemaContextListener>
+ registerSchemaContextListener(final SchemaContextListener listener) {
final Optional<SchemaContext> potentialCtx = contextResolver.getSchemaContext();
- if(potentialCtx.isPresent()) {
+ if (potentialCtx.isPresent()) {
listener.onGlobalContextUpdated(potentialCtx.get());
}
return listeners.register(listener);
}
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
private synchronized void updateContext(final SchemaContext snapshot) {
final Object[] services = listenerTracker.getServices();
for (final ListenerRegistration<SchemaContextListener> listener : listeners) {
}
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
private class BundleScanner implements BundleTrackerCustomizer<Iterable<Registration>> {
@Override
public Iterable<Registration> addingBundle(final Bundle bundle, final BundleEvent event) {
* {@link #getYangStoreSnapshot()} will throw exception. There is no
* rollback.
*/
-
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Override
- public synchronized void removedBundle(final Bundle bundle, final BundleEvent event, final Iterable<Registration> urls) {
+ public synchronized void removedBundle(final Bundle bundle, final BundleEvent event,
+ final Iterable<Registration> urls) {
for (final Registration url : urls) {
try {
url.close();
}
final int numUrls = Iterables.size(urls);
- if(numUrls > 0 ) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("removedBundle: {}, state: {}, # urls: {}", bundle.getSymbolicName(), bundle.getState(), numUrls);
+ if (numUrls > 0 ) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("removedBundle: {}, state: {}, # urls: {}", bundle.getSymbolicName(),
+ bundle.getState(), numUrls);
}
tryToUpdateSchemaContext();
return;
}
final Optional<SchemaContext> schema = contextResolver.getSchemaContext();
- if(schema.isPresent()) {
- if(LOG.isDebugEnabled()) {
+ if (schema.isPresent()) {
+ if (LOG.isDebugEnabled()) {
LOG.debug("Got new SchemaContext: # of modules {}", schema.get().getAllModuleIdentifiers().size());
}
}
@Override
- public void modifiedService(final ServiceReference<SchemaContextListener> reference, final SchemaContextListener service) {
+ public void modifiedService(final ServiceReference<SchemaContextListener> reference,
+ final SchemaContextListener service) {
// NOOP
}
@Override
- public void removedService(final ServiceReference<SchemaContextListener> reference, final SchemaContextListener service) {
+ public void removedService(final ServiceReference<SchemaContextListener> reference,
+ final SchemaContextListener service) {
context.ungetService(reference);
}
}
*/
package org.opendaylight.mdsal.dom.broker.osgi;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import java.util.Hashtable;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
@Override
public void start(final BundleContext context) {
schemaService = OsgiBundleScanningSchemaService.createInstance(context);
- schemaServiceReg = context.registerService(DOMSchemaService.class, schemaService, new Hashtable<String,String>());
+ schemaServiceReg = context.registerService(DOMSchemaService.class,
+ schemaService, new Hashtable<String,String>());
}
@Override
/**
* Simple implementation of {@link TransactionChainListener} for testing.
*
+ *<p>
* This transaction chain listener does not contain any logic, only update
* futures ({@link #getFailFuture()} and {@link #getSuccessFuture()} when
* transaction chain event is retrieved.
operStore.onGlobalContextUpdated(schemaContext);
configStore.onGlobalContextUpdated(schemaContext);
- final ImmutableMap<LogicalDatastoreType, DOMStore> stores = ImmutableMap.<LogicalDatastoreType, DOMStore> builder()
+ final ImmutableMap<LogicalDatastoreType, DOMStore> stores =
+ ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
.put(CONFIGURATION, configStore)
.put(OPERATIONAL, operStore)
.build();
@After
public void tearDown() {
- if( executor != null ) {
+ if (executor != null ) {
executor.shutdownNow();
}
- if(futureExecutor != null) {
+ if (futureExecutor != null) {
futureExecutor.shutdownNow();
}
}
- @Test(timeout=10000)
+ @Test(timeout = 10000)
public void testTransactionIsolation() throws InterruptedException, ExecutionException {
assertNotNull(domBroker);
assertNotNull(writeTx);
/**
- *
- * Writes /test in writeTx
+ * Writes /test in writeTx.
*
*/
writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
/**
- *
* Reads /test from readTx Read should return Absent.
*
*/
assertFalse(readTxContainer.get().isPresent());
}
- @Test(timeout=10000)
+ @Test(timeout = 10000)
public void testTransactionCommit() throws InterruptedException, ExecutionException {
final DOMDataTreeWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
assertNotNull(writeTx);
/**
- *
* Writes /test in writeTx
*
*/
assertTrue(afterCommitRead.isPresent());
}
- @Test(expected=TransactionCommitFailedException.class)
+ @Test(expected = TransactionCommitFailedException.class)
public void testRejectedCommit() throws Exception {
commitExecutor.delegate = Mockito.mock( ExecutorService.class );
Mockito.doThrow( new RejectedExecutionException( "mock" ) )
writeTx.submit().checkedGet( 5, TimeUnit.SECONDS );
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
AtomicReference<Throwable> submitTxAsync( final DOMDataTreeWriteTransaction writeTx ) {
final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
new Thread() {
try {
writeTx.submit();
- } catch( final Throwable e ) {
+ } catch ( final Throwable e ) {
caughtEx.set( e );
}
}
readRx.read(OPERATIONAL, TestModel.TEST_PATH).checkedGet();
}
+ @SuppressWarnings({"checkstyle:IllegalThrows", "checkstyle:IllegalCatch"})
@Test
public void closeTest() throws Exception {
- final String TEST_EXCEPTION = "TestException";
+ final String testException = "TestException";
+
+ domBroker.setCloseable(() -> {
+ throw new Exception(testException);
+ });
- domBroker.setCloseable(() -> { throw new Exception(TEST_EXCEPTION); });
- try{
+ try {
domBroker.close();
- }catch(final Exception e){
- assertTrue(e.getMessage().contains(TEST_EXCEPTION));
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains(testException));
}
}
ExecutorService delegate;
- public CommitExecutorService( final ExecutorService delegate ) {
+ CommitExecutorService( final ExecutorService delegate ) {
this.delegate = delegate;
}
operStore.onGlobalContextUpdated(schemaContext);
configStore.onGlobalContextUpdated(schemaContext);
- final ImmutableMap<LogicalDatastoreType, DOMStore> stores = ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
+ final ImmutableMap<LogicalDatastoreType, DOMStore> stores = ImmutableMap.<LogicalDatastoreType,
+ DOMStore>builder()
.put(CONFIGURATION, configStore)
.put(OPERATIONAL, operStore)
.build();
ExecutorService delegate;
- public CommitExecutorService(final ExecutorService delegate) {
+ CommitExecutorService(final ExecutorService delegate) {
this.delegate = delegate;
}
private final List<Collection<DataTreeCandidate>> receivedChanges = new ArrayList<>();
private final CountDownLatch latch;
- public TestDataTreeListener(final CountDownLatch latch) {
+ TestDataTreeListener(final CountDownLatch latch) {
this.latch = latch;
}
assertNotNull(DOMNotificationRouter.create(1));
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Test
public void complexTest() throws Exception {
final DOMNotificationSubscriptionListener domNotificationSubscriptionListener =
private AbstractDOMDataBroker domBroker;
@Before
- public void setupStore() throws Exception{
- final InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService());
- final InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.newDirectExecutorService());
+ public void setupStore() throws Exception {
+ final InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER",
+ MoreExecutors.newDirectExecutorService());
+ final InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG",
+ MoreExecutors.newDirectExecutorService());
schemaContext = TestModel.createTestContext();
operStore.onGlobalContextUpdated(schemaContext);
configStore.onGlobalContextUpdated(schemaContext);
- final ImmutableMap<LogicalDatastoreType, DOMStore> stores = ImmutableMap.<LogicalDatastoreType, DOMStore> builder() //
- .put(CONFIGURATION, configStore) //
- .put(OPERATIONAL, operStore) //
+ final ImmutableMap<LogicalDatastoreType, DOMStore> stores =
+ ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
+ .put(CONFIGURATION, configStore)
+ .put(OPERATIONAL, operStore)
.build();
- final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
+ final ListeningExecutorService executor = MoreExecutors.listeningDecorator(
+ Executors.newSingleThreadExecutor());
domBroker = new SerializedDOMDataBroker(stores, executor);
}
assertNotNull(txChain);
/**
- * We alocate new read-write transaction and write /test
- *
- *
+ * We alocate new read-write transaction and write /test.
*/
final DOMDataTreeWriteTransaction firstTx = allocateAndWrite(txChain);
/**
* First transaction is marked as ready, we are able to allocate chained
- * transactions
+ * transactions.
*/
final ListenableFuture<Void> firstWriteTxFuture = firstTx.submit();
assertTestContainerExists(secondReadTx);
/**
- *
* We alocate next transaction, which is still based on first one, but
* is read-write.
*
assertCommitSuccessful(firstWriteTxFuture);
/**
- *
* Allocates transaction from data store.
*
*/
assertTestContainerExists(storeReadTx);
/**
- * third transaction is sealed and commited
+ * third transaction is sealed and commited.
*/
final ListenableFuture<Void> thirdDeleteTxFuture = thirdDeleteTx.submit();
assertCommitSuccessful(thirdDeleteTxFuture);
listener.getSuccessFuture().get(1000, TimeUnit.MILLISECONDS);
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Test
public void testTransactionChainNotSealed() throws InterruptedException, ExecutionException, TimeoutException {
final BlockingTransactionChainListener listener = new BlockingTransactionChainListener();
/**
* We alocate new read-write transaction and write /test
- *
- *
*/
allocateAndWrite(txChain);
future.get();
}
- private static void assertTestContainerExists(final DOMDataTreeReadTransaction readTx) throws InterruptedException,
- ExecutionException {
- final ListenableFuture<Optional<NormalizedNode<?, ?>>> readFuture = readTx.read(OPERATIONAL, TestModel.TEST_PATH);
+ private static void assertTestContainerExists(final DOMDataTreeReadTransaction readTx)
+ throws InterruptedException, ExecutionException {
+ final ListenableFuture<Optional<NormalizedNode<?, ?>>> readFuture =
+ readTx.read(OPERATIONAL, TestModel.TEST_PATH);
final Optional<NormalizedNode<?, ?>> readedData = readFuture.get();
assertTrue(readedData.isPresent());
}
assertTrue(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().containsValue(
rpcImplementation));
- try{
+ try {
globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations)
.invokeRpc(TEST_CONTAINER).checkedGet();
fail("Expected DOMRpcImplementationNotAvailableException");
- }catch(DOMRpcImplementationNotAvailableException e){
+ } catch (DOMRpcImplementationNotAvailableException e) {
assertTrue(e.getMessage().contains(EXCEPTION_TEXT));
}
}
public class RoutedDOMRpcRoutingTableEntryTest extends TestUtils {
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Test
public void basicTest() throws Exception {
final RpcDefinition rpcDefinition = mock(RpcDefinition.class);
dataTreeService = dataTree;
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testTxReadyMultiples() throws Exception {
final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID));
final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction();
transaction.ready();
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testSubmitUnclosedCursor() throws Exception {
final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID));
final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction();
final DOMDataTreeListener mockedDataTreeListener = Mockito.mock(DOMDataTreeListener.class);
doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
- dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID), true, Collections.emptyList());
+ dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID),
+ true, Collections.emptyList());
final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID));
final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction();
transaction.ready();
transaction.submit();
- verify(mockedDataTreeListener, timeout(1000).times(2)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
+ verify(mockedDataTreeListener, timeout(1000).times(2)).onDataTreeChanged(
+ captorForChanges.capture(), captorForSubtrees.capture());
final Collection<DataTreeCandidate> capturedValue = captorForChanges.getValue();
assertTrue(capturedValue.size() == 1);
- final ContainerNode dataAfter = (ContainerNode) capturedValue.iterator().next().getRootNode().getDataAfter().get();
+ final ContainerNode dataAfter =
+ (ContainerNode) capturedValue.iterator().next().getRootNode().getDataAfter().get();
assertEquals(innerContainer, dataAfter);
verifyNoMoreInteractions(mockedDataTreeListener);
}
final DOMDataTreeListener mockedDataTreeListener = Mockito.mock(DOMDataTreeListener.class);
doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
- dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID), true, Collections.emptyList());
+ dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID), true,
+ Collections.emptyList());
final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID));
final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction();
writeCrossShardContainer(transaction);
- verify(mockedDataTreeListener, timeout(1000).times(2)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
+ verify(mockedDataTreeListener, timeout(1000).times(2)).onDataTreeChanged(
+ captorForChanges.capture(), captorForSubtrees.capture());
final Collection<DataTreeCandidate> capturedValue = captorForChanges.getValue();
assertTrue(capturedValue.size() == 1);
- final ContainerNode dataAfter = (ContainerNode) capturedValue.iterator().next().getRootNode().getDataAfter().get();
- assertEquals(crossShardContainer.getChild(TestModel.INNER_CONTAINER_PATH.getLastPathArgument()).get(), dataAfter);
+ final ContainerNode dataAfter =
+ (ContainerNode) capturedValue.iterator().next().getRootNode().getDataAfter().get();
+ assertEquals(crossShardContainer.getChild(
+ TestModel.INNER_CONTAINER_PATH.getLastPathArgument()).get(), dataAfter);
final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> capturedSubtrees = captorForSubtrees.getValue();
assertTrue(capturedSubtrees.size() == 1);
assertTrue(capturedSubtrees.containsKey(INNER_CONTAINER_ID));
- assertEquals(crossShardContainer.getChild(TestModel.INNER_CONTAINER_PATH.getLastPathArgument()).get(), capturedSubtrees.get(INNER_CONTAINER_ID));
+ assertEquals(crossShardContainer.getChild(TestModel.INNER_CONTAINER_PATH.getLastPathArgument()).get(),
+ capturedSubtrees.get(INNER_CONTAINER_ID));
verifyNoMoreInteractions(mockedDataTreeListener);
}
final InMemoryDOMDataTreeShard innerShard = InMemoryDOMDataTreeShard.create(INNER_CONTAINER_ID, executor, 1);
innerShard.onGlobalContextUpdated(schemaContext);
- final DOMDataTreeProducer shardRegProducer = dataTreeService.createProducer(Collections.singletonList(INNER_CONTAINER_ID));
+ final DOMDataTreeProducer shardRegProducer =
+ dataTreeService.createProducer(Collections.singletonList(INNER_CONTAINER_ID));
innerShardReg = dataTreeService.registerDataTreeShard(INNER_CONTAINER_ID, innerShard, shardRegProducer);
shardRegProducer.close();
- dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID), true, Collections.emptyList());
+ dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID),
+ true, Collections.emptyList());
final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID));
final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction();
.build();
//verify listeners have been notified
- verify(mockedDataTreeListener, timeout(1000).times(4)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
+ verify(mockedDataTreeListener, timeout(1000).times(4)).onDataTreeChanged(
+ captorForChanges.capture(), captorForSubtrees.capture());
final List<Collection<DataTreeCandidate>> capturedChanges = captorForChanges.getAllValues();
- final List<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> capturedSubtrees = captorForSubtrees.getAllValues();
+ final List<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> capturedSubtrees =
+ captorForSubtrees.getAllValues();
final DataTreeCandidate firstNotificationCandidate = capturedChanges.get(2).iterator().next();
assertTrue(capturedSubtrees.get(2).size() == 1);
final DOMDataTreeListener mockedDataTreeListener = Mockito.mock(DOMDataTreeListener.class);
doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
- dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID), true, Collections.emptyList());
+ dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID),
+ true, Collections.emptyList());
final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID));
final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction();
cursor.enter(TestModel.TEST_PATH.getLastPathArgument());
final LeafNode<String> shardedValue1 =
- ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(TestModel.SHARDED_VALUE_1)).withValue("sharded value 1").build();
+ ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(
+ new NodeIdentifier(TestModel.SHARDED_VALUE_1)).withValue("sharded value 1").build();
final LeafNode<String> shardedValue2 =
- ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(TestModel.SHARDED_VALUE_2)).withValue("sharded value 2").build();
+ ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(
+ new NodeIdentifier(TestModel.SHARDED_VALUE_2)).withValue("sharded value 2").build();
- final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerNodeBuilder = ImmutableContainerNodeBuilder.create();
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerNodeBuilder =
+ ImmutableContainerNodeBuilder.create();
final ContainerNode containerNode =
containerNodeBuilder
.withNodeIdentifier(new NodeIdentifier(TestModel.INNER_CONTAINER))
final ContainerNode lowerShardContainer = ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new NodeIdentifier(TestModel.ANOTHER_SHARD_CONTAINER))
- .withChild(ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.ANOTHER_SHARD_VALUE)).build())
+ .withChild(ImmutableLeafNodeBuilder.create().withNodeIdentifier(
+ new NodeIdentifier(TestModel.ANOTHER_SHARD_VALUE)).build())
.build();
cursor.write(TestModel.ANOTHER_SHARD_PATH.getLastPathArgument(), lowerShardContainer);
private ContainerNode createCrossShardContainer() {
final LeafNode<String> shardedValue1 =
- ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(TestModel.SHARDED_VALUE_1)).withValue("sharded value 1").build();
+ ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(
+ new NodeIdentifier(TestModel.SHARDED_VALUE_1)).withValue("sharded value 1").build();
final LeafNode<String> shardedValue2 =
- ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(TestModel.SHARDED_VALUE_2)).withValue("sharded value 2").build();
+ ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(
+ TestModel.SHARDED_VALUE_2)).withValue("sharded value 2").build();
final ContainerNode lowerShardContainer = ImmutableContainerNodeBuilder.create()
return testContainer;
}
- private void writeCrossShardContainer(final DOMDataTreeShardWriteTransaction transaction) throws Exception{
+ private void writeCrossShardContainer(final DOMDataTreeShardWriteTransaction transaction) throws Exception {
final DOMDataTreeWriteCursor cursor = transaction.createCursor(ROOT_ID);
cursor.write(TestModel.TEST_PATH.getLastPathArgument(), crossShardContainer);
@Test
public void attachAndRemoveShard() throws DOMDataTreeShardingConflictException {
doNothing().when(rootShard).onChildAttached(TEST_ID, childShard);
- final ListenerRegistration<DOMDataTreeShard> reg = shardingService.registerDataTreeShard(TEST_ID, childShard, testProducer);
+ final ListenerRegistration<DOMDataTreeShard> reg =
+ shardingService.registerDataTreeShard(TEST_ID, childShard, testProducer);
verify(rootShard, times(1)).onChildAttached(TEST_ID, childShard);
doNothing().when(rootShard).onChildDetached(TEST_ID, childShard);
final InMemoryDOMDataTreeShard innerShard = InMemoryDOMDataTreeShard.create(INNER_CONTAINER_ID, executor, 1);
innerShard.onGlobalContextUpdated(schemaContext);
- final DOMDataTreeProducer shardRegProducer2 = dataTreeService.createProducer(Collections.singletonList(INNER_CONTAINER_ID));
- ListenerRegistration<InMemoryDOMDataTreeShard> innerShardReg = dataTreeService.registerDataTreeShard(INNER_CONTAINER_ID, innerShard, shardRegProducer2);
+ final DOMDataTreeProducer shardRegProducer2 =
+ dataTreeService.createProducer(Collections.singletonList(INNER_CONTAINER_ID));
+ ListenerRegistration<InMemoryDOMDataTreeShard> innerShardReg =
+ dataTreeService.registerDataTreeShard(INNER_CONTAINER_ID, innerShard, shardRegProducer2);
innerShardReg.close();
// try to register the shard again
final DOMDataTreeListener mockedDataTreeListener = Mockito.mock(DOMDataTreeListener.class);
doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
- dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID), true, Collections.emptyList());
+ dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID),
+ true, Collections.emptyList());
final DOMDataTreeProducer producer = dataTreeService.createProducer(Collections.singletonList(ROOT_ID));
DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(false);
cursor.close();
tx.submit().checkedGet();
- verify(mockedDataTreeListener, timeout(1000).times(3)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
+ verify(mockedDataTreeListener, timeout(1000).times(3)).onDataTreeChanged(captorForChanges.capture(),
+ captorForSubtrees.capture());
final List<Collection<DataTreeCandidate>> capturedValue = captorForChanges.getAllValues();
assertTrue(capturedValue.size() == 3);
- final ContainerNode capturedChange = (ContainerNode) capturedValue.get(1).iterator().next().getRootNode().getDataAfter().get();
- final ContainerNode innerContainerVerify = (ContainerNode) crossShardContainer.getChild(TestModel.INNER_CONTAINER_PATH.getLastPathArgument()).get();
+ final ContainerNode capturedChange =
+ (ContainerNode) capturedValue.get(1).iterator().next().getRootNode().getDataAfter().get();
+ final ContainerNode innerContainerVerify = (ContainerNode) crossShardContainer.getChild(
+ TestModel.INNER_CONTAINER_PATH.getLastPathArgument()).get();
assertEquals(innerContainerVerify, capturedChange);
verifyNoMoreInteractions(mockedDataTreeListener);
assertTrue(rootTx.cancel());
- final DOMDataTreeProducer innerContainerProducer = rootProducer.createProducer(Collections.singletonList(INNER_CONTAINER_ID));
+ final DOMDataTreeProducer innerContainerProducer = rootProducer.createProducer(
+ Collections.singletonList(INNER_CONTAINER_ID));
rootTx = rootProducer.createTransaction(false);
try {
private ContainerNode createCrossShardContainer() {
final LeafNode<String> shardedValue1 =
- ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(TestModel.SHARDED_VALUE_1)).withValue("sharded value 1").build();
+ ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(
+ TestModel.SHARDED_VALUE_1)).withValue("sharded value 1").build();
final LeafNode<String> shardedValue2 =
- ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(TestModel.SHARDED_VALUE_2)).withValue("sharded value 2").build();
+ ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(
+ TestModel.SHARDED_VALUE_2)).withValue("sharded value 2").build();
final ContainerNode lowerShardContainer = ImmutableContainerNodeBuilder.create()
final ShardedDOMDataTree shardedDOMDataTree =
new ShardedDOMDataTree();
- final DOMDataTreeProducer shardRegProducer = shardedDOMDataTree.createProducer(Collections.singletonList(ROOT_ID));
+ final DOMDataTreeProducer shardRegProducer = shardedDOMDataTree.createProducer(
+ Collections.singletonList(ROOT_ID));
shardedDOMDataTree.registerDataTreeShard(ROOT_ID, rootShard, shardRegProducer);
shardRegProducer.close();
final YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.of(QName.create("test"));
cursor.close();
try {
- transaction.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY));
+ transaction.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
+ YangInstanceIdentifier.EMPTY));
fail("Should have failed, config ds not available to this tx");
} catch (final IllegalArgumentException e) {
assertTrue(e.getMessage().contains("not accessible"));
assertFalse(transaction.cancel());
final DOMDataTreeCursorAwareTransaction newTx = producer.createTransaction(false);
- assertTrue("Transaction identifier incorrect " + transaction.getIdentifier(), ((String) transaction.getIdentifier()).contains("SHARDED-DOM-"));
+ assertTrue("Transaction identifier incorrect " + transaction.getIdentifier(), (
+ (String) transaction.getIdentifier()).contains("SHARDED-DOM-"));
assertNotEquals(transaction.getIdentifier(),
newTx.getIdentifier());
}
@Nonnull
@Override
public <T extends DOMDataTreeListener> ListenerRegistration<T>
- registerListener(@Nonnull final T listener, @Nonnull final Collection<DOMDataTreeIdentifier> subtrees,
+ registerListener(@Nonnull final T listener, @Nonnull final Collection<DOMDataTreeIdentifier> subtrees,
final boolean allowRxMerges,
@Nonnull final Collection<DOMDataTreeProducer> producers) throws DOMDataTreeLoopException {
final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> subtree = Maps.newHashMap();
ALLWAYS_SUCCESS(true, true, true, true), CAN_COMMIT_FAILED(false, false, false, true), PRE_COMMIT_FAILED(true,
false, false, true), COMMIT_FAILED(true, true, false, true);
- ;
-
- private TestCommitCohort(final boolean canCommit, final boolean preCommit, final boolean commit, final boolean abort) {
+ TestCommitCohort(final boolean canCommit, final boolean preCommit,
+ final boolean commit, final boolean abort) {
this.canCommit = Futures.immediateFuture(canCommit);
this.preCommit = immediate(canCommit, new IllegalStateException());
this.commit = immediate(commit, new IllegalStateException());
return commit;
}
- private static ListenableFuture<Void> immediate(final boolean isSuccess, final Exception e) {
- return isSuccess ? Futures.<Void>immediateFuture(null) : Futures.<Void>immediateFailedFuture(e);
+ private static ListenableFuture<Void> immediate(final boolean isSuccess, final Exception except) {
+ return isSuccess ? Futures.<Void>immediateFuture(null) : Futures.<Void>immediateFailedFuture(except);
}
private static final QName TOP_LEVEL_LIST_QNAME = QName.create(TOP_QNAME, "top-level-list");
private static final QName TOP_LEVEL_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
- private final static MapEntryNode topLevelListNormalized = ImmutableMapEntryNodeBuilder.create()
+ private static final MapEntryNode TOP_LEVEL_LIST_NODE = ImmutableMapEntryNodeBuilder.create()
.withNodeIdentifier(
new YangInstanceIdentifier.NodeIdentifierWithPredicates(
TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
private static final DataContainerChild<?, ?> CHILD_LIST = ImmutableNodes.mapNodeBuilder(TestModel.TEST_QNAME)
.withNodeIdentifier(NodeIdentifier.create(TestModel.TEST_QNAME))
- .withChild(topLevelListNormalized)
+ .withChild(TOP_LEVEL_LIST_NODE)
.build();
static final NormalizedNode<?, ?> TEST_CONTAINER = Builders.containerBuilder()
static final String EXCEPTION_TEXT = "TestRpcImplementationException";
- static TestRpcImplementation getTestRpcImplementation(){
+ static TestRpcImplementation getTestRpcImplementation() {
return new TestRpcImplementation();
}
assertEquals(bundleContext, osgiService.getContext());
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
@After
public void destroyInstance() throws Exception {
try {
verify(osgiBundle).close();
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
@After
@Before
public void destroyInstance() throws Exception {