Topology Manager to avoid redundant edge updates
[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     @Deprecated
77     public synchronized void putRuntimeData(InstanceIdentifier<? extends DataObject> path, DataObject data) {
78         delegate.putRuntimeData(path, data);
79     }
80
81     @Override
82     public synchronized Object getIdentifier() {
83         return delegate.getIdentifier();
84     }
85
86     @Override
87     public synchronized DataObject readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
88         return delegate.readConfigurationData(path);
89     }
90
91     @Override
92     public synchronized Future<RpcResult<TransactionStatus>> commit() {
93         return delegate.commit();
94     }
95
96     @Override
97     public synchronized void putOperationalData(InstanceIdentifier<? extends DataObject> path, DataObject data) {
98         delegate.putOperationalData(path, data);
99     }
100
101     @Override
102     public synchronized void putConfigurationData(InstanceIdentifier<? extends DataObject> path, DataObject data) {
103         delegate.putConfigurationData(path, data);
104     }
105
106     @Override
107     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getUpdatedConfigurationData() {
108         return delegate.getUpdatedConfigurationData();
109     }
110
111     @Deprecated
112     public synchronized void removeRuntimeData(InstanceIdentifier<? extends DataObject> path) {
113         delegate.removeRuntimeData(path);
114     }
115
116     @Override
117     public synchronized void removeOperationalData(InstanceIdentifier<? extends DataObject> path) {
118         delegate.removeOperationalData(path);
119     }
120
121     @Override
122     public synchronized void removeConfigurationData(InstanceIdentifier<? extends DataObject> path) {
123         delegate.removeConfigurationData(path);
124     }
125
126     @Override
127     public synchronized Set<InstanceIdentifier<? extends DataObject>> getRemovedConfigurationData() {
128         return delegate.getRemovedConfigurationData();
129     }
130
131     @Override
132     public synchronized Set<InstanceIdentifier<? extends DataObject>> getRemovedOperationalData() {
133         return delegate.getRemovedOperationalData();
134     }
135
136     @Override
137     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getOriginalConfigurationData() {
138         return delegate.getOriginalConfigurationData();
139     }
140
141     @Override
142     public synchronized ListenerRegistration<DataTransactionListener> registerListener(DataTransactionListener listener) {
143         return delegate.registerListener(listener);
144     }
145
146     @Override
147     public synchronized Map<InstanceIdentifier<? extends DataObject>, DataObject> getOriginalOperationalData() {
148         return delegate.getOriginalOperationalData();
149     }
150
151     @Override
152     public synchronized DataModificationTransaction getDelegate() {
153         return delegate;
154     }
155
156     @Override
157     public int hashCode() {
158         final int prime = 31;
159         int result = 1;
160         result = prime * result + ((delegate == null) ? 0 : delegate.hashCode());
161         return result;
162     }
163
164     @Override
165     public boolean equals(Object obj) {
166         if (this == obj) {
167             return true;
168         }
169         if (obj == null) {
170             return false;
171         }
172         if (getClass() != obj.getClass()){
173             return false;
174         }
175         SynchronizedTransaction other = (SynchronizedTransaction) obj;
176         if (delegate == null) {
177             if (other.delegate != null) {
178                 return false;
179             }
180         } else if (!delegate.equals(other.delegate)) {
181             return false;
182         }
183         return true;
184     }
185 }
186

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