CommitInfo forward compatibility
[mdsal.git] / common / mdsal-common-api / src / main / java / org / opendaylight / mdsal / common / api / PostCanCommitStep.java
1 /*
2  * Copyright (c) 2015 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.common.api;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.FluentFuture;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
15
16 /**
17  * User implementation of steps following can-commit in three phase protocol.
18  * If no additional visibility into transaction and data being aborted or committed is needed, use
19  * {@link #NOOP} implementation.
20  */
21 @Beta
22 public interface PostCanCommitStep extends ThreePhaseCommitStep {
23     /**
24      * No-op implementation of abort, pre-commit and commit steps.
25      * This implementation should be used if user logic does only validation of data and does not
26      * need to perform any actions associated with pre-commit, commit or abort.
27      */
28     PostCanCommitStep NOOP = new PostCanCommitStep() {
29
30         @Override
31         public ListenableFuture<?> abort() {
32             return ThreePhaseCommitStep.NOOP_ABORT_FUTURE;
33         }
34
35         @Override
36         public ListenableFuture<? extends PostPreCommitStep> preCommit() {
37             return PostPreCommitStep.NOOP_FUTURE;
38         }
39     };
40
41     @NonNull FluentFuture<PostCanCommitStep> NOOP_SUCCESSFUL_FUTURE = FluentFutures.immediateFluentFuture(NOOP);
42
43     /**
44      * Initiates a pre-commit of associated request
45      * Implementation MUST NOT do any blocking calls during this callback, all pre-commit
46      * preparation SHOULD happen asynchronously and MUST result in completing returned future
47      * object.
48      *
49      * @return Future which is completed once pre-commit phase for this request is finished.
50      */
51     @NonNull ListenableFuture<? extends PostPreCommitStep> preCommit();
52 }