2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.dom.spi.shard;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
15 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
16 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 @Deprecated(forRemoval = true)
22 public class ForeignShardThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
23 private static final Logger LOG = LoggerFactory.getLogger(ForeignShardThreePhaseCommitCohort.class);
25 private final DOMDataTreeIdentifier prefix;
26 private final ForeignShardModificationContext shard;
28 public ForeignShardThreePhaseCommitCohort(final DOMDataTreeIdentifier prefix,
29 final ForeignShardModificationContext shard) {
30 this.prefix = requireNonNull(prefix);
31 this.shard = requireNonNull(shard);
35 public ListenableFuture<Boolean> canCommit() {
36 LOG.debug("Validating transaction on foreign shard {}", prefix);
37 return shard.isModified() ? shard.validate() : FluentFutures.immediateTrueFluentFuture();
41 public ListenableFuture<Void> preCommit() {
42 LOG.debug("Preparing transaction on foreign shard {}", prefix);
43 return shard.isModified() ? shard.prepare() : FluentFutures.immediateNullFluentFuture();
47 public ListenableFuture<Void> abort() {
48 LOG.debug("Aborting transaction of foreign shard {}", prefix);
49 shard.closeForeignTransaction();
50 return FluentFutures.immediateNullFluentFuture();
54 public ListenableFuture<Void> commit() {
55 LOG.debug("Submitting transaction on foreign shard {}", prefix);
56 return shard.isModified() ? shard.submit() : FluentFutures.immediateNullFluentFuture();