6516b17d51957ca6cabe8bb690168f798977c462
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / main / java / org / opendaylight / mdsal / dom / store / inmemory / 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
9 package org.opendaylight.mdsal.dom.store.inmemory;
10
11 import com.google.common.util.concurrent.Futures;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
14 import org.opendaylight.mdsal.dom.spi.shard.ForeignShardModificationContext;
15 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class ForeignShardThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
20
21     private static final Logger LOG = LoggerFactory.getLogger(ForeignShardThreePhaseCommitCohort.class);
22
23     private final DOMDataTreeIdentifier prefix;
24     private final ForeignShardModificationContext shard;
25
26     public ForeignShardThreePhaseCommitCohort(final DOMDataTreeIdentifier prefix,
27             final ForeignShardModificationContext shard) {
28         this.prefix = prefix;
29         this.shard = shard;
30     }
31
32     @Override
33     public ListenableFuture<Boolean> canCommit() {
34         LOG.debug("Validating transaction on foreign shard {}", prefix);
35         return shard.validate();
36     }
37
38     @Override
39     public ListenableFuture<Void> preCommit() {
40         LOG.debug("Preparing transaction on foreign shard {}", prefix);
41         return shard.prepare();
42     }
43
44     @Override
45     public ListenableFuture<Void> abort() {
46         // FIXME abort on the shard
47         return Futures.immediateFuture(null);
48     }
49
50     @Override
51     public ListenableFuture<Void> commit() {
52         LOG.debug("Submitting transaction on foreign shard {}", prefix);
53         return shard.submit();
54     }
55 }