82c15ef993bd2a5c76641916810ee25734315287
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / connect / dom / DomToBindingTransaction.java
1 package org.opendaylight.controller.sal.binding.impl.connect.dom;
2
3 import java.util.concurrent.ConcurrentMap;
4 import java.util.concurrent.ExecutionException;
5 import java.util.concurrent.Future;
6
7 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
8 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
9 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
10 import org.opendaylight.yangtools.yang.common.RpcResult;
11 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
12 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14
15 @Deprecated
16 class DomToBindingTransaction implements
17     DataCommitHandler.DataCommitTransaction<YangInstanceIdentifier, CompositeNode> {
18
19     private final org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction backing;
20     private final DataModification<YangInstanceIdentifier, CompositeNode> modification;
21     private final ConcurrentMap<Object, DomToBindingTransaction> bindingOpenedTransactions;
22
23     public DomToBindingTransaction(
24     final org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction backing,
25     final DataModification<org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, CompositeNode> modification,
26         ConcurrentMap<Object, DomToBindingTransaction> bindingOpenedTransactions) {
27         super();
28         this.backing = backing;
29         this.modification = modification;
30         this.bindingOpenedTransactions = bindingOpenedTransactions;
31         this.bindingOpenedTransactions.put(backing.getIdentifier(), this);
32     }
33
34     @Override
35     public DataModification<org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, CompositeNode> getModification() {
36         return modification;
37     }
38
39     @Override
40     public RpcResult<Void> rollback() throws IllegalStateException {
41         bindingOpenedTransactions.remove(backing.getIdentifier());
42         return RpcResultBuilder.<Void> success().build();
43     }
44
45     @Override
46     public RpcResult<Void> finish() throws IllegalStateException {
47         Future<RpcResult<TransactionStatus>> result = backing.commit();
48         try {
49             RpcResult<TransactionStatus> baResult = result.get();
50             bindingOpenedTransactions.remove(backing.getIdentifier());
51             return RpcResultBuilder.<Void> status(baResult.isSuccessful())
52                                           .withRpcErrors(baResult.getErrors()).build();
53         } catch (InterruptedException e) {
54             throw new IllegalStateException("", e);
55         } catch (ExecutionException e) {
56             throw new IllegalStateException("", e);
57         } finally {
58             bindingOpenedTransactions.remove(backing.getIdentifier());
59         }
60     }
61 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.