3147ec57a3c71ff314f9cea1034146f768ca52d4
[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 com.google.common.util.concurrent.SettableFuture;
11 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
12 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
13 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
14
15 /**
16  * Simple implementation of {@link TransactionChainListener} for testing.
17  *
18  * <p>
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 class BlockingTransactionChainListener implements TransactionChainListener {
24
25     private final SettableFuture<Throwable> failFuture = SettableFuture.create();
26     private final SettableFuture<Void> successFuture = SettableFuture.create();
27
28     @Override
29     public void onTransactionChainFailed(final TransactionChain<?, ?> chain, final AsyncTransaction<?, ?> transaction,
30                                          final Throwable cause) {
31         failFuture.set(cause);
32     }
33
34     @Override
35     public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
36         successFuture.set(null);
37     }
38
39     public SettableFuture<Throwable> getFailFuture() {
40         return failFuture;
41     }
42
43     public SettableFuture<Void> getSuccessFuture() {
44         return successFuture;
45     }
46
47 }