Do not use ListenerRegistration
[mdsal.git] / common / mdsal-common-api / src / main / java / org / opendaylight / mdsal / common / api / PostPreCommitStep.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.ListenableFuture;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
14
15 /**
16  * User implementation of steps following pre-commit from Three-Phase Protocol.
17  */
18 @Beta
19 public interface PostPreCommitStep extends ThreePhaseCommitStep {
20     /**
21      * No-op implementation of {@link #abort()} and {@link #commit()} method, which always success
22      * calls.
23      * This implementation is intended for users which may not need to implement commit and abort
24      * method.
25      *
26      */
27     PostPreCommitStep NOOP = new PostPreCommitStep() {
28
29         @Override
30         public ListenableFuture<?> abort() {
31             return ThreePhaseCommitStep.NOOP_ABORT_FUTURE;
32         }
33
34         @Override
35         public ListenableFuture<?> commit() {
36             return NOOP_COMMIT_FUTURE;
37         }
38     };
39
40     @NonNull ListenableFuture<?> NOOP_COMMIT_FUTURE = FluentFutures.immediateNullFluentFuture();
41
42     @NonNull ListenableFuture<? extends PostPreCommitStep> NOOP_FUTURE = FluentFutures.immediateFluentFuture(NOOP);
43
44     /**
45      * Commits cohort transaction.
46      * This callback is invoked by three-phase commit coordinator if associated data transaction
47      * finished pre-commit phase and will be commited.
48      * Implementation should make state, which were derived by implementation from associated data
49      * visible.
50      *
51      * @return Listenable Future which will complete once commit is finished.
52      */
53     @NonNull ListenableFuture<?> commit();
54 }