da6d46d499317d647673cfb2b7ef5d60e43b2eae
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / sal / binding / api / data / SynchronizedTransaction.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.sal.binding.api.data;
9
10 import java.util.Map;
11 import java.util.Set;
12 import java.util.concurrent.Future;
13
14 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
15 import org.opendaylight.yangtools.concepts.Delegator;
16 import org.opendaylight.yangtools.concepts.ListenerRegistration;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20
21 import com.google.common.base.Preconditions;
22
23 /**
24  * Synchronized wrapper for DataModificationTransaction.
25  *
26  * To get instance of synchronized wrapper use {@link #from(DataModificationTransaction)}
27  *
28  */
29 public final class SynchronizedTransaction implements DataModificationTransaction,Delegator<DataModificationTransaction> {
30
31     private final DataModificationTransaction delegate;
32
33     private SynchronizedTransaction(DataModificationTransaction delegate) {
34         this.delegate = delegate;
35     }
36
37     /**
38      * Returns synchronized wrapper on supplied transaction.
39      *
40      * @param transaction Transaction for which synchronized wrapper should be created.
41      * @return Synchronized wrapper over transaction.
42      */
43     public static final SynchronizedTransaction from(DataModificationTransaction transaction) {
44         Preconditions.checkArgument(transaction != null, "Transaction must not be null.");
45         if (transaction instanceof SynchronizedTransaction) {
46             return (SynchronizedTransaction) transaction;
47         }
48         return new SynchronizedTransaction(transaction);
49     }
50
51     @Override
52     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getCreatedOperationalData() {
53         return delegate.getCreatedOperationalData();
54     }
55
56     @Override
57     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getCreatedConfigurationData() {
58         return delegate.getCreatedConfigurationData();
59     }
60
61     @Override
62     public synchronized DataObject readOperationalData(InstanceIdentifier<? extends DataObject> path) {
63         return delegate.readOperationalData(path);
64     }
65
66     @Override
67     public synchronized TransactionStatus getStatus() {
68         return delegate.getStatus();
69     }
70
71     @Override
72     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getUpdatedOperationalData() {
73         return delegate.getUpdatedOperationalData();
74     }
75
76     @Override
77     public synchronized Object getIdentifier() {
78         return delegate.getIdentifier();
79     }
80
81     @Override
82     public synchronized DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
83         return delegate.readConfigurationData(path);
84     }
85
86     @Override
87     public synchronized Future<RpcResult<TransactionStatus>> commit() {
88         return delegate.commit();
89     }
90
91     @Override
92     public synchronized void putOperationalData(InstanceIdentifier<? extends DataObject> path, DataObject data) {
93         delegate.putOperationalData(path, data);
94     }
95
96     @Override
97     public synchronized void putConfigurationData(InstanceIdentifier<? extends DataObject> path, DataObject data) {
98         delegate.putConfigurationData(path, data);
99     }
100
101     @Override
102     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getUpdatedConfigurationData() {
103         return delegate.getUpdatedConfigurationData();
104     }
105
106     @Override
107     public synchronized void removeOperationalData(InstanceIdentifier<? extends DataObject> path) {
108         delegate.removeOperationalData(path);
109     }
110
111     @Override
112     public synchronized void removeConfigurationData(InstanceIdentifier<? extends DataObject> path) {
113         delegate.removeConfigurationData(path);
114     }
115
116     @Override
117     public synchronized Set<InstanceIdentifier<? extends DataObject>> getRemovedConfigurationData() {
118         return delegate.getRemovedConfigurationData();
119     }
120
121     @Override
122     public synchronized Set<InstanceIdentifier<? extends DataObject>> getRemovedOperationalData() {
123         return delegate.getRemovedOperationalData();
124     }
125
126     @Override
127     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getOriginalConfigurationData() {
128         return delegate.getOriginalConfigurationData();
129     }
130
131     @Override
132     public synchronized ListenerRegistration<DataTransactionListener> registerListener(DataTransactionListener listener) {
133         return delegate.registerListener(listener);
134     }
135
136     @Override
137     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getOriginalOperationalData() {
138         return delegate.getOriginalOperationalData();
139     }
140
141     @Override
142     public synchronized DataModificationTransaction getDelegate() {
143         return delegate;
144     }
145
146     @Override
147     public int hashCode() {
148         final int prime = 31;
149         int result = 1;
150         result = prime * result + ((delegate == null) ? 0 : delegate.hashCode());
151         return result;
152     }
153
154     @Override
155     public boolean equals(Object obj) {
156         if (this == obj) {
157             return true;
158         }
159         if (obj == null) {
160             return false;
161         }
162         if (getClass() != obj.getClass()){
163             return false;
164         }
165         SynchronizedTransaction other = (SynchronizedTransaction) obj;
166         if (delegate == null) {
167             if (other.delegate != null) {
168                 return false;
169             }
170         } else if (!delegate.equals(other.delegate)) {
171             return false;
172         }
173         return true;
174     }
175 }
176

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