9b9e12217e7d6d0719db779dc476e5cfbc478278
[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.CheckedFuture;
12 import com.google.common.util.concurrent.FluentFuture;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
17
18 /**
19  * User implementation of steps following can-commit in three phase protocol.
20  * If no additional visibility into transaction and data being aborted or committed is needed, use
21  * {@link #NOOP} implementation.
22  *
23  */
24 @Beta
25 public interface PostCanCommitStep extends ThreePhaseCommitStep {
26
27     /**
28      * No-op implementation of abort, pre-commit and commit steps.
29      * This implementation should be used if user logic does only validation of data and does not
30      * need to perform any actions associated with pre-commit, commit or abort.
31      */
32     PostCanCommitStep NOOP = new PostCanCommitStep() {
33
34         @Override
35         public ListenableFuture<?> abort() {
36             return ThreePhaseCommitStep.NOOP_ABORT_FUTURE;
37         }
38
39         @Override
40         public ListenableFuture<? extends PostPreCommitStep> preCommit() {
41             return PostPreCommitStep.NOOP_FUTURE;
42         }
43     };
44
45     /**
46      * Successful future, returning {@link #NOOP} implementation of {@link PostCanCommitStep}s.
47      */
48     @Deprecated
49     CheckedFuture<PostCanCommitStep, DataValidationFailedException> NOOP_SUCCESS_FUTURE =
50             Futures.immediateCheckedFuture(NOOP);
51
52     FluentFuture<PostCanCommitStep> NOOP_SUCCESSFUL_FUTURE = FluentFutures.immediateFluentFuture(NOOP);
53
54     /**
55      * Initiates a pre-commit of associated request
56      * Implementation MUST NOT do any blocking calls during this callback, all pre-commit
57      * preparation SHOULD happen asynchronously and MUST result in completing returned future
58      * object.
59      *
60      * @return Future which is completed once pre-commit phase for this request is finished.
61      *
62      */
63     @Nonnull
64     ListenableFuture<? extends PostPreCommitStep> preCommit();
65
66 }