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 public class ForeignShardThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
22 private static final Logger LOG = LoggerFactory.getLogger(ForeignShardThreePhaseCommitCohort.class);
24 private final DOMDataTreeIdentifier prefix;
25 private final ForeignShardModificationContext shard;
27 public ForeignShardThreePhaseCommitCohort(final DOMDataTreeIdentifier prefix,
28 final ForeignShardModificationContext shard) {
29 this.prefix = requireNonNull(prefix);
30 this.shard = requireNonNull(shard);
34 public ListenableFuture<Boolean> canCommit() {
35 LOG.debug("Validating transaction on foreign shard {}", prefix);
36 return shard.isModified() ? shard.validate() : FluentFutures.immediateTrueFluentFuture();
40 public ListenableFuture<Void> preCommit() {
41 LOG.debug("Preparing transaction on foreign shard {}", prefix);
42 return shard.isModified() ? shard.prepare() : FluentFutures.immediateNullFluentFuture();
46 public ListenableFuture<Void> abort() {
47 LOG.debug("Aborting transaction of foreign shard {}", prefix);
48 shard.closeForeignTransaction();
49 return FluentFutures.immediateNullFluentFuture();
53 public ListenableFuture<Void> commit() {
54 LOG.debug("Submitting transaction on foreign shard {}", prefix);
55 return shard.isModified() ? shard.submit() : FluentFutures.immediateNullFluentFuture();