* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.mdsal.dom.store.inmemory;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
-import org.opendaylight.mdsal.common.api.ReadFailedException;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
import org.opendaylight.mdsal.dom.spi.shard.DOMDataTreeShardWriteTransaction;
import org.opendaylight.mdsal.dom.spi.shard.ForeignShardModificationContext;
+import org.opendaylight.mdsal.dom.spi.shard.ForeignShardThreePhaseCommitCohort;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
final InMemoryDOMDataTreeShardChangePublisher changePublisher,
final ListeningExecutorService executor) {
this.producer = producer;
- this.modification = Preconditions.checkNotNull(root);
- this.rootShardDataTree = Preconditions.checkNotNull(rootShardDataTree);
- this.changePublisher = Preconditions.checkNotNull(changePublisher);
+ this.modification = requireNonNull(root);
+ this.rootShardDataTree = requireNonNull(rootShardDataTree);
+ this.changePublisher = requireNonNull(changePublisher);
this.identifier = "INMEMORY-SHARD-TX-" + COUNTER.getAndIncrement();
LOG.debug("Shard transaction{} created", identifier);
this.executor = executor;
void delete(final YangInstanceIdentifier path) {
final YangInstanceIdentifier relativePath = toRelative(path);
- Preconditions.checkArgument(!YangInstanceIdentifier.EMPTY.equals(relativePath),
- "Deletion of shard root is not allowed");
+ checkArgument(!relativePath.isEmpty(), "Deletion of shard root is not allowed");
SimpleCursorOperation.DELETE.apply(getCursor(), relativePath, null);
}
private YangInstanceIdentifier toRelative(final YangInstanceIdentifier path) {
final Optional<YangInstanceIdentifier> relative =
path.relativeTo(modification.getPrefix().getRootIdentifier());
- Preconditions.checkArgument(relative.isPresent());
+ checkArgument(relative.isPresent());
return relative.get();
}
- public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
- throw new UnsupportedOperationException("Not implemented yet");
- }
-
- public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
- throw new UnsupportedOperationException("Not implemented yet");
- }
-
@Override
public void close() {
- Preconditions.checkState(!finished, "Attempting to close an already finished transaction.");
+ checkState(!finished, "Attempting to close an already finished transaction.");
modification.closeTransactions();
if (cursor != null) {
cursor.close();
}
void cursorClosed() {
- Preconditions.checkNotNull(cursor);
+ requireNonNull(cursor);
modification.closeCursor();
cursor = null;
}
@Override
public void ready() {
- Preconditions.checkState(!finished, "Attempting to ready an already finished transaction.");
- Preconditions.checkState(cursor == null, "Attempting to ready a transaction that has an open cursor.");
- Preconditions.checkNotNull(modification, "Attempting to ready an empty transaction.");
+ checkState(!finished, "Attempting to ready an already finished transaction.");
+ checkState(cursor == null, "Attempting to ready a transaction that has an open cursor.");
+ requireNonNull(modification, "Attempting to ready an empty transaction.");
LOG.debug("Readying open transaction on shard {}", modification.getPrefix());
rootModification = modification.seal();
public ListenableFuture<Void> submit() {
LOG.debug("Submitting open transaction on shard {}", modification.getPrefix());
- Preconditions.checkNotNull(cohorts);
- Preconditions.checkState(!cohorts.isEmpty(), "Transaction was not readied yet.");
+ requireNonNull(cohorts);
+ checkState(!cohorts.isEmpty(), "Transaction was not readied yet.");
return executor.submit(new ShardSubmitCoordinationTask(modification.getPrefix(), cohorts, this));
}
}
DataTreeModification getRootModification() {
- Preconditions.checkNotNull(rootModification, "Transaction wasn't sealed yet");
+ requireNonNull(rootModification, "Transaction wasn't sealed yet");
return rootModification;
}
@Override
public DOMDataTreeWriteCursor createCursor(final DOMDataTreeIdentifier prefix) {
- Preconditions.checkState(!finished, "Transaction is finished/closed already.");
- Preconditions.checkState(cursor == null, "Previous cursor wasn't closed");
+ checkState(!finished, "Transaction is finished/closed already.");
+ checkState(cursor == null, "Previous cursor wasn't closed");
final YangInstanceIdentifier relativePath = toRelative(prefix.getRootIdentifier());
final DOMDataTreeWriteCursor ret = getCursor();
ret.enter(relativePath.getPathArguments());