2 * Copyright (c) 2013 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.dom.broker;
10 import java.util.List;
12 import java.util.concurrent.Future;
14 import org.opendaylight.controller.md.sal.common.api.RegistrationListener;
15 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
16 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandlerRegistration;
17 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
18 import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
19 import org.opendaylight.controller.sal.common.DataStoreIdentifier;
20 import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration;
21 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration;
22 import org.opendaylight.controller.sal.core.api.RoutedRpcDefaultImplementation;
23 import org.opendaylight.controller.sal.core.api.RpcImplementation;
24 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
25 import org.opendaylight.controller.sal.core.api.RpcRoutingContext;
26 import org.opendaylight.controller.sal.core.api.data.DataChangeListener;
27 import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction;
28 import org.opendaylight.controller.sal.core.api.data.DataValidator;
29 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
30 import org.opendaylight.controller.sal.core.api.notify.NotificationListener;
31 import org.opendaylight.controller.sal.dom.broker.impl.NotificationRouterImpl;
32 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker;
33 import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProvider;
34 import org.opendaylight.controller.sal.dom.broker.spi.NotificationRouter;
35 import org.opendaylight.yangtools.concepts.ListenerRegistration;
36 import org.opendaylight.yangtools.concepts.Registration;
37 import org.opendaylight.yangtools.yang.common.QName;
38 import org.opendaylight.yangtools.yang.common.RpcResult;
39 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
40 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
41 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
42 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
44 public class MountPointImpl implements MountProvisionInstance, SchemaContextProvider {
46 private final SchemaAwareRpcBroker rpcs;
47 private final DataBrokerImpl dataReader;
48 private final NotificationRouter notificationRouter;
49 private final DataReader<InstanceIdentifier,CompositeNode> readWrapper;
52 private final InstanceIdentifier mountPath;
54 private SchemaContext schemaContext;
56 public MountPointImpl(InstanceIdentifier path) {
57 this.mountPath = path;
58 rpcs = new SchemaAwareRpcBroker(path.toString(),this);
59 dataReader = new DataBrokerImpl();
60 notificationRouter = new NotificationRouterImpl();
61 readWrapper = new ReadWrapper();
64 public InstanceIdentifier getMountPath() {
68 public DataReader<InstanceIdentifier, CompositeNode> getReadWrapper() {
73 public void publish(CompositeNode notification) {
74 notificationRouter.publish(notification);
78 public Registration<NotificationListener> addNotificationListener(QName notification, NotificationListener listener) {
79 return notificationRouter.addNotificationListener(notification, listener);
83 public CompositeNode readConfigurationData(InstanceIdentifier path) {
84 return dataReader.readConfigurationData(path);
88 public CompositeNode readOperationalData(InstanceIdentifier path) {
89 return dataReader.readOperationalData(path);
92 public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerOperationalReader(
93 InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
94 return dataReader.registerOperationalReader(path, reader);
97 public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerConfigurationReader(
98 InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
99 return dataReader.registerConfigurationReader(path, reader);
103 public RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
104 return rpcs.addRoutedRpcImplementation(rpcType, implementation);
108 public void setRoutedRpcDefaultDelegate(RoutedRpcDefaultImplementation defaultImplementation) {
109 rpcs.setRoutedRpcDefaultDelegate(defaultImplementation);
113 public RpcRegistration addRpcImplementation(QName rpcType, RpcImplementation implementation)
114 throws IllegalArgumentException {
115 return rpcs.addRpcImplementation(rpcType, implementation);
118 public Set<QName> getSupportedRpcs() {
119 return rpcs.getSupportedRpcs();
123 public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
124 return rpcs.invokeRpc(rpc, input);
127 public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener) {
128 return rpcs.addRpcRegistrationListener(listener);
133 public Future<RpcResult<CompositeNode>> rpc(QName type, CompositeNode input) {
138 public DataModificationTransaction beginTransaction() {
139 return dataReader.beginTransaction();
143 public ListenerRegistration<DataChangeListener> registerDataChangeListener(InstanceIdentifier path,
144 DataChangeListener listener) {
145 return dataReader.registerDataChangeListener(path, listener);
149 public void sendNotification(CompositeNode notification) {
150 publish(notification);
154 public Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registerCommitHandler(
155 InstanceIdentifier path, DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
156 return dataReader.registerCommitHandler(path, commitHandler);
160 public void removeRefresher(DataStoreIdentifier store, DataRefresher refresher) {
165 public void addRefresher(DataStoreIdentifier store, DataRefresher refresher) {
170 public void addValidator(DataStoreIdentifier store, DataValidator validator) {
174 public void removeValidator(DataStoreIdentifier store, DataValidator validator) {
178 public SchemaContext getSchemaContext() {
179 return schemaContext;
182 public void setSchemaContext(SchemaContext schemaContext) {
183 this.schemaContext = schemaContext;
186 class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
189 private InstanceIdentifier shortenPath(InstanceIdentifier path) {
190 InstanceIdentifier ret = null;
191 if(mountPath.contains(path)) {
192 List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
193 ret = new InstanceIdentifier(newArgs);
199 public CompositeNode readConfigurationData(InstanceIdentifier path) {
200 InstanceIdentifier newPath = shortenPath(path);
201 if(newPath == null) {
204 return MountPointImpl.this.readConfigurationData(newPath);
208 public CompositeNode readOperationalData(InstanceIdentifier path) {
209 InstanceIdentifier newPath = shortenPath(path);
210 if(newPath == null) {
213 return MountPointImpl.this.readOperationalData(newPath);
218 public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
219 RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
220 return dataReader.registerCommitHandlerListener(commitHandlerListener);
224 public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
226 return rpcs.registerRouteChangeListener(listener);