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