Merge "Bug-1903:On recovery all replicated log entries should not be applied to state"
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / DOMDataCommitErrorInvoker.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
3  * This program and the accompanying materials are made available under the
4  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/epl-v10.html
6  */
7 package org.opendaylight.controller.md.sal.dom.broker.impl;
8
9 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
10 import com.google.common.base.Preconditions;
11 import com.google.common.util.concurrent.FutureCallback;
12
13 /**
14  *
15  * Utility implemetation of {@link FutureCallback} which is responsible
16  * for invoking {@link DOMDataCommitErrorListener} on TransactionCommit failed.
17  *
18  * When {@link #onFailure(Throwable)} is invoked, supplied {@link DOMDataCommitErrorListener}
19  * callback is invoked with associated transaction and throwable is invoked on listener.
20  *
21  */
22 class DOMDataCommitErrorInvoker implements FutureCallback<Void> {
23
24     private final DOMDataWriteTransaction tx;
25     private final DOMDataCommitErrorListener listener;
26
27
28     /**
29      *
30      * Construct new DOMDataCommitErrorInvoker.
31      *
32      * @param transaction Transaction which should be passed as argument to {@link DOMDataCommitErrorListener#onCommitFailed(DOMDataWriteTransaction, Throwable)}
33      * @param listener Listener which should be invoked on error.
34      */
35     public DOMDataCommitErrorInvoker(DOMDataWriteTransaction transaction, DOMDataCommitErrorListener listener) {
36         this.tx = Preconditions.checkNotNull(transaction, "Transaction must not be null");
37         this.listener = Preconditions.checkNotNull(listener, "Listener must not be null");
38     }
39
40     @Override
41     public void onFailure(Throwable t) {
42         listener.onCommitFailed(tx, t);
43     }
44
45     @Override
46     public void onSuccess(Void result) {
47         // NOOP
48     }
49 }