2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.binding.impl;
\r
11 import java.util.Map.Entry;
12 import java.util.concurrent.Future;
13 import java.util.concurrent.atomic.AtomicLong;
15 import org.opendaylight.controller.md.sal.common.impl.service.AbstractDataBroker;
16 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
17 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
18 import org.opendaylight.controller.sal.binding.impl.util.BindingAwareDataReaderRouter;
19 import org.opendaylight.controller.sal.common.DataStoreIdentifier;
20 import org.opendaylight.yangtools.yang.binding.DataObject;
21 import org.opendaylight.yangtools.yang.binding.DataRoot;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.binding.util.DataObjectReadingUtil;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
26 import com.google.common.base.Predicate;
27 import com.google.common.collect.ImmutableMap;
28 import com.google.common.collect.ImmutableMap.Builder;
29 import com.google.common.collect.Maps;
32 public class DataBrokerImpl extends AbstractDataBroker<InstanceIdentifier<? extends DataObject>, DataObject, DataChangeListener> //
\r
33 implements DataProviderService, AutoCloseable {
\r
35 private final static class ContainsWildcarded implements Predicate<InstanceIdentifier<? extends DataObject>> {
37 private final InstanceIdentifier<? extends DataObject> key;
39 public ContainsWildcarded(InstanceIdentifier<? extends DataObject> key) {
44 public boolean apply(InstanceIdentifier<? extends DataObject> input) {
45 return key.containsWildcarded(input);
49 private final static class IsContainedWildcarded implements Predicate<InstanceIdentifier<? extends DataObject>> {
51 private final InstanceIdentifier<? extends DataObject> key;
53 public IsContainedWildcarded(InstanceIdentifier<? extends DataObject> key) {
58 public boolean apply(InstanceIdentifier<? extends DataObject> input) {
59 return input.containsWildcarded(key);
63 private final AtomicLong nextTransaction = new AtomicLong();
\r
64 private final AtomicLong createdTransactionsCount = new AtomicLong();
\r
66 public AtomicLong getCreatedTransactionsCount() {
\r
67 return createdTransactionsCount;
\r
70 public DataBrokerImpl() {
\r
71 setDataReadRouter(new BindingAwareDataReaderRouter());
\r
75 public DataTransactionImpl beginTransaction() {
\r
76 String transactionId = "BA-" + nextTransaction.getAndIncrement();
\r
77 createdTransactionsCount.getAndIncrement();
\r
78 return new DataTransactionImpl(transactionId,this);
\r
83 public <T extends DataRoot> T getData(DataStoreIdentifier store, Class<T> rootType) {
\r
84 throw new UnsupportedOperationException("Deprecated");
\r
89 public <T extends DataRoot> T getData(DataStoreIdentifier store, T filter) {
\r
90 throw new UnsupportedOperationException("Deprecated");
\r
95 public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, Class<T> rootType) {
\r
96 throw new UnsupportedOperationException("Deprecated");
\r
101 public <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, T filter) {
\r
102 throw new UnsupportedOperationException("Deprecated");
\r
107 public RpcResult<DataRoot> editCandidateData(DataStoreIdentifier store, DataRoot changeSet) {
\r
108 throw new UnsupportedOperationException("Deprecated");
\r
113 public Future<RpcResult<Void>> commit(DataStoreIdentifier store) {
\r
114 throw new UnsupportedOperationException("Deprecated");
\r
119 public DataObject getData(InstanceIdentifier<? extends DataObject> data) {
\r
120 throw new UnsupportedOperationException("Deprecated");
\r
125 public DataObject getConfigurationData(InstanceIdentifier<?> data) {
\r
126 throw new UnsupportedOperationException("Deprecated");
\r
131 public void registerChangeListener(InstanceIdentifier<? extends DataObject> path, DataChangeListener changeListener) {
\r
132 throw new UnsupportedOperationException("Deprecated");
\r
137 public void unregisterChangeListener(InstanceIdentifier<? extends DataObject> path,
\r
138 DataChangeListener changeListener) {
\r
139 throw new UnsupportedOperationException("Deprecated");
\r
143 public void close() throws Exception {
\r
148 protected Predicate<InstanceIdentifier<? extends DataObject>> createContainsPredicate(final
149 InstanceIdentifier<? extends DataObject> key) {
150 return new ContainsWildcarded(key);
154 protected Predicate<InstanceIdentifier<? extends DataObject>> createIsContainedPredicate(final
155 InstanceIdentifier<? extends DataObject> key) {
156 return new IsContainedWildcarded(key);
159 @SuppressWarnings({ "unchecked", "rawtypes" })
161 protected Map<InstanceIdentifier<? extends DataObject>, DataObject> deepGetBySubpath(
162 Map<InstanceIdentifier<? extends DataObject>, DataObject> dataSet,
163 InstanceIdentifier<? extends DataObject> path) {
164 Builder<InstanceIdentifier<? extends DataObject>, DataObject> builder = ImmutableMap.builder();
165 Map<InstanceIdentifier<? extends DataObject>, DataObject> potential = Maps.filterKeys(dataSet, createIsContainedPredicate(path));
166 for(Entry<InstanceIdentifier<? extends DataObject>, DataObject> entry : potential.entrySet()) {
168 builder.putAll(DataObjectReadingUtil.readData(entry.getValue(),(InstanceIdentifier)entry.getKey(),path));
169 } catch (Exception e) {
170 // FIXME : Log exception;
173 return builder.build();