BUG-1092: adjust to YangInstanceIdentifier
[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 class DomToBindingTransaction implements
16     DataCommitHandler.DataCommitTransaction<YangInstanceIdentifier, CompositeNode> {
17
18     private final org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction backing;
19     private final DataModification<YangInstanceIdentifier, CompositeNode> modification;
20     private final ConcurrentMap<Object, DomToBindingTransaction> bindingOpenedTransactions;
21
22     public DomToBindingTransaction(
23     final org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction backing,
24     final DataModification<org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, CompositeNode> modification,
25         ConcurrentMap<Object, DomToBindingTransaction> bindingOpenedTransactions) {
26         super();
27         this.backing = backing;
28         this.modification = modification;
29         this.bindingOpenedTransactions = bindingOpenedTransactions;
30         this.bindingOpenedTransactions.put(backing.getIdentifier(), this);
31     }
32
33     @Override
34     public DataModification<org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, CompositeNode> getModification() {
35         return modification;
36     }
37
38     @Override
39     public RpcResult<Void> rollback() throws IllegalStateException {
40         bindingOpenedTransactions.remove(backing.getIdentifier());
41         return RpcResultBuilder.<Void> success().build();
42     }
43
44     @Override
45     public RpcResult<Void> finish() throws IllegalStateException {
46         Future<RpcResult<TransactionStatus>> result = backing.commit();
47         try {
48             RpcResult<TransactionStatus> baResult = result.get();
49             bindingOpenedTransactions.remove(backing.getIdentifier());
50             return RpcResultBuilder.<Void> status(baResult.isSuccessful())
51                                           .withRpcErrors(baResult.getErrors()).build();
52         } catch (InterruptedException e) {
53             throw new IllegalStateException("", e);
54         } catch (ExecutionException e) {
55             throw new IllegalStateException("", e);
56         } finally {
57             bindingOpenedTransactions.remove(backing.getIdentifier());
58         }
59     }
60 }

©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.