Do not generate 'isFoo()' methods
[mdsal.git] / dom / mdsal-dom-spi / src / main / java / org / opendaylight / mdsal / dom / spi / shard / ForeignShardThreePhaseCommitCohort.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.dom.spi.shard;
9
10 import static java.util.Objects.requireNonNull;
11
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;
19
20 @Beta
21 @Deprecated(forRemoval = true)
22 public class ForeignShardThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
23     private static final Logger LOG = LoggerFactory.getLogger(ForeignShardThreePhaseCommitCohort.class);
24
25     private final DOMDataTreeIdentifier prefix;
26     private final ForeignShardModificationContext shard;
27
28     public ForeignShardThreePhaseCommitCohort(final DOMDataTreeIdentifier prefix,
29             final ForeignShardModificationContext shard) {
30         this.prefix = requireNonNull(prefix);
31         this.shard = requireNonNull(shard);
32     }
33
34     @Override
35     public ListenableFuture<Boolean> canCommit() {
36         LOG.debug("Validating transaction on foreign shard {}", prefix);
37         return shard.isModified() ? shard.validate() : FluentFutures.immediateTrueFluentFuture();
38     }
39
40     @Override
41     public ListenableFuture<Void> preCommit() {
42         LOG.debug("Preparing transaction on foreign shard {}", prefix);
43         return shard.isModified() ? shard.prepare() : FluentFutures.immediateNullFluentFuture();
44     }
45
46     @Override
47     public ListenableFuture<Void> abort() {
48         LOG.debug("Aborting transaction of foreign shard {}", prefix);
49         shard.closeForeignTransaction();
50         return FluentFutures.immediateNullFluentFuture();
51     }
52
53     @Override
54     public ListenableFuture<Void> commit() {
55         LOG.debug("Submitting transaction on foreign shard {}", prefix);
56         return shard.isModified() ? shard.submit() : FluentFutures.immediateNullFluentFuture();
57     }
58 }