Merge "Fix for bug #236 and bug #240 Have made changes in opendaylight-table-types...
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / DataBrokerImpl.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.impl;\r
9 \r
10 import java.util.Set;
11 import java.util.concurrent.Future;\r
12 import java.util.concurrent.atomic.AtomicLong;\r
13 \r
14 import org.opendaylight.controller.md.sal.common.impl.service.AbstractDataBroker;\r
15 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;\r
16 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;\r
17 import org.opendaylight.controller.sal.binding.impl.util.BindingAwareDataReaderRouter;\r
18 import org.opendaylight.controller.sal.common.DataStoreIdentifier;\r
19 import org.opendaylight.yangtools.yang.binding.DataObject;\r
20 import org.opendaylight.yangtools.yang.binding.DataRoot;\r
21 import org.opendaylight.yangtools.yang.binding.Identifiable;\r
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
23 import org.opendaylight.yangtools.yang.common.RpcResult;\r
24 \r
25 \r
26 public class DataBrokerImpl extends AbstractDataBroker<InstanceIdentifier<? extends DataObject>, DataObject, DataChangeListener> //\r
27        implements DataProviderService, AutoCloseable {\r
28 \r
29     private final AtomicLong nextTransaction = new AtomicLong();\r
30     private final AtomicLong createdTransactionsCount = new AtomicLong();\r
31     \r
32     public AtomicLong getCreatedTransactionsCount() {\r
33         return createdTransactionsCount;\r
34     }\r
35 \r
36     public DataBrokerImpl() {\r
37         setDataReadRouter(new BindingAwareDataReaderRouter());\r
38     }\r
39 \r
40     @Override\r
41     public DataTransactionImpl beginTransaction() {\r
42         String transactionId = "BA-" + nextTransaction.getAndIncrement();\r
43         createdTransactionsCount.getAndIncrement();\r
44         return new DataTransactionImpl(transactionId,this);\r
45     }\r
46 \r
47     @Override\r
48     @Deprecated\r
49     public <T extends DataRoot> T getData(DataStoreIdentifier store, Class<T> rootType) {\r
50         throw new UnsupportedOperationException("Deprecated");\r
51     }\r
52 \r
53     @Override\r
54     @Deprecated\r
55     public <T extends DataRoot> T getData(DataStoreIdentifier store, T filter) {\r
56         throw new UnsupportedOperationException("Deprecated");\r
57     }\r
58 \r
59     @Override\r
60     @Deprecated\r
61     public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, Class<T> rootType) {\r
62         throw new UnsupportedOperationException("Deprecated");\r
63     }\r
64 \r
65     @Override\r
66     @Deprecated\r
67     public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, T filter) {\r
68         throw new UnsupportedOperationException("Deprecated");\r
69     }\r
70 \r
71     @Override\r
72     @Deprecated\r
73     public RpcResult<DataRoot> editCandidateData(DataStoreIdentifier store, DataRoot changeSet) {\r
74         throw new UnsupportedOperationException("Deprecated");\r
75     }\r
76 \r
77     @Override\r
78     @Deprecated\r
79     public Future<RpcResult<Void>> commit(DataStoreIdentifier store) {\r
80         throw new UnsupportedOperationException("Deprecated");\r
81     }\r
82 \r
83     @Override\r
84     @Deprecated\r
85     public DataObject getData(InstanceIdentifier<? extends DataObject> data) {\r
86         throw new UnsupportedOperationException("Deprecated");\r
87     }\r
88 \r
89     @Override\r
90     @Deprecated\r
91     public DataObject getConfigurationData(InstanceIdentifier<?> data) {\r
92         throw new UnsupportedOperationException("Deprecated");\r
93     }\r
94 \r
95     @Override\r
96     @Deprecated\r
97     public void registerChangeListener(InstanceIdentifier<? extends DataObject> path, DataChangeListener changeListener) {\r
98         throw new UnsupportedOperationException("Deprecated");\r
99     }\r
100 \r
101     @Override\r
102     @Deprecated\r
103     public void unregisterChangeListener(InstanceIdentifier<? extends DataObject> path,\r
104             DataChangeListener changeListener) {\r
105         throw new UnsupportedOperationException("Deprecated");\r
106     }\r
107     \r
108     @Override\r
109     public void close() throws Exception {\r
110         \r
111     }
112     
113     
114     @Override
115     protected boolean isAffectedBy(InstanceIdentifier<? extends DataObject> key,
116             Set<InstanceIdentifier<? extends DataObject>> paths) {
117         if (paths.contains(key)) {
118             return true;
119         }
120         for (InstanceIdentifier<?> path : paths) {
121             if (key.containsWildcarded(path)) {
122                 return true;
123             }
124         }
125         return false;
126     }\r
127 }