b46c9fcf0b0712e551a8ddb2e4bb403777a5a2d3
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / main / java / org / opendaylight / mdsal / dom / store / inmemory / ShardSubmitCoordinationTask.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 java.util.Collection;
12 import java.util.concurrent.Callable;
13 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
15 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 class ShardSubmitCoordinationTask implements Callable<Void> {
20
21     private static final Logger LOG = LoggerFactory.getLogger(ShardSubmitCoordinationTask.class);
22
23     private final DOMDataTreeIdentifier rootShardPrefix;
24     private final ShardCanCommitCoordinationTask canCommitCoordinationTask;
25     private final ShardPreCommitCoordinationTask preCommitCoordinationTask;
26     private final ShardCommitCoordinationTask commitCoordinationTask;
27
28
29     ShardSubmitCoordinationTask(final DOMDataTreeIdentifier rootShardPrefix,
30                                        final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
31         this.rootShardPrefix = rootShardPrefix;
32
33         canCommitCoordinationTask = new ShardCanCommitCoordinationTask(rootShardPrefix, cohorts);
34         preCommitCoordinationTask = new ShardPreCommitCoordinationTask(rootShardPrefix, cohorts);
35         commitCoordinationTask = new ShardCommitCoordinationTask(rootShardPrefix, cohorts);
36     }
37
38     @Override
39     public Void call() throws TransactionCommitFailedException {
40
41         LOG.debug("Shard {}, CanCommit started", rootShardPrefix);
42         canCommitCoordinationTask.canCommitBlocking();
43
44         LOG.debug("Shard {}, PreCommit started", rootShardPrefix);
45         preCommitCoordinationTask.preCommitBlocking();
46
47         LOG.debug("Shard {}, commit started", rootShardPrefix);
48         commitCoordinationTask.commitBlocking();
49
50         return null;
51     }
52 }