Merge "Bug 629: Introduction of Configuration Commit Handler"
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / test / java / org / opendaylight / controller / md / sal / dom / broker / impl / BlockingTransactionChainListener.java
1 /*
2  * Copyright (c) 2014 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.controller.md.sal.dom.broker.impl;
9
10 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
11 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
12 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
13
14 import com.google.common.util.concurrent.SettableFuture;
15
16 /**
17  * Simple implementation of {@link TransactionChainListener} for testing.
18  *
19  * This transaction chain listener does not contain any logic, only update
20  * futures ({@link #getFailFuture()} and {@link #getSuccessFuture()} when
21  * transaction chain event is retrieved.
22  *
23  */
24 class BlockingTransactionChainListener implements TransactionChainListener {
25
26     private final SettableFuture<Throwable> failFuture = SettableFuture.create();
27     private final SettableFuture<Void> successFuture = SettableFuture.create();
28
29     @Override
30     public void onTransactionChainFailed(final TransactionChain<?, ?> chain, final AsyncTransaction<?, ?> transaction,
31             final Throwable cause) {
32         failFuture.set(cause);
33     }
34
35     @Override
36     public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
37         successFuture.set(null);
38     }
39
40     public SettableFuture<Throwable> getFailFuture() {
41         return failFuture;
42     }
43
44     public SettableFuture<Void> getSuccessFuture() {
45         return successFuture;
46     }
47
48 }