45be5c96fa7deba766fa75b17e404a1874655120
[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.Collections;
4 import java.util.concurrent.ConcurrentMap;
5 import java.util.concurrent.ExecutionException;
6 import java.util.concurrent.Future;
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.controller.sal.common.util.Rpcs;
11 import org.opendaylight.yangtools.yang.common.RpcError;
12 import org.opendaylight.yangtools.yang.common.RpcResult;
13 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
14 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
15
16 class DomToBindingTransaction implements
17     DataCommitHandler.DataCommitTransaction<InstanceIdentifier, CompositeNode> {
18
19     private final org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction backing;
20     private final DataModification<InstanceIdentifier, 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.InstanceIdentifier, 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.InstanceIdentifier, CompositeNode> getModification() {
36         return modification;
37     }
38
39     @Override
40     public RpcResult<Void> rollback() throws IllegalStateException {
41         bindingOpenedTransactions.remove(backing.getIdentifier());
42         return Rpcs.getRpcResult(true, null, Collections.<RpcError>emptySet());
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 Rpcs.getRpcResult(baResult.isSuccessful(), null, baResult.getErrors());
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.