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.RpcImplementation;
23 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
24 import org.opendaylight.controller.sal.core.api.RpcRoutingContext;
25 import org.opendaylight.controller.sal.core.api.data.DataChangeListener;
26 import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction;
27 import org.opendaylight.controller.sal.core.api.data.DataValidator;
28 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
29 import org.opendaylight.controller.sal.core.api.notify.NotificationListener;
30 import org.opendaylight.controller.sal.dom.broker.impl.NotificationRouterImpl;
31 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker;
32 import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProvider;
33 import org.opendaylight.controller.sal.dom.broker.spi.NotificationRouter;
34 import org.opendaylight.yangtools.concepts.ListenerRegistration;
35 import org.opendaylight.yangtools.concepts.Registration;
36 import org.opendaylight.yangtools.yang.common.QName;
37 import org.opendaylight.yangtools.yang.common.RpcResult;
38 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
39 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
40 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
41 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
43 public class MountPointImpl implements MountProvisionInstance, SchemaContextProvider {
45 private final SchemaAwareRpcBroker rpcs;
46 private final DataBrokerImpl dataReader;
47 private final NotificationRouter notificationRouter;
48 private final DataReader<InstanceIdentifier,CompositeNode> readWrapper;
51 private final InstanceIdentifier mountPath;
53 private SchemaContext schemaContext;
55 public MountPointImpl(InstanceIdentifier path) {
56 this.mountPath = path;
57 rpcs = new SchemaAwareRpcBroker(path.toString(),this);
58 dataReader = new DataBrokerImpl();
59 notificationRouter = new NotificationRouterImpl();
60 readWrapper = new ReadWrapper();
63 public InstanceIdentifier getMountPath() {
67 public DataReader<InstanceIdentifier, CompositeNode> getReadWrapper() {
72 public void publish(CompositeNode notification) {
73 notificationRouter.publish(notification);
77 public Registration<NotificationListener> addNotificationListener(QName notification, NotificationListener listener) {
78 return notificationRouter.addNotificationListener(notification, listener);
82 public CompositeNode readConfigurationData(InstanceIdentifier path) {
83 return dataReader.readConfigurationData(path);
87 public CompositeNode readOperationalData(InstanceIdentifier path) {
88 return dataReader.readOperationalData(path);
91 public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerOperationalReader(
92 InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
93 return dataReader.registerOperationalReader(path, reader);
96 public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerConfigurationReader(
97 InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
98 return dataReader.registerConfigurationReader(path, reader);
102 public RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
103 return rpcs.addRoutedRpcImplementation(rpcType, implementation);
107 public RpcRegistration addRpcImplementation(QName rpcType, RpcImplementation implementation)
108 throws IllegalArgumentException {
109 return rpcs.addRpcImplementation(rpcType, implementation);
112 public Set<QName> getSupportedRpcs() {
113 return rpcs.getSupportedRpcs();
117 public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
118 return rpcs.invokeRpc(rpc, input);
121 public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener) {
122 return rpcs.addRpcRegistrationListener(listener);
127 public Future<RpcResult<CompositeNode>> rpc(QName type, CompositeNode input) {
132 public DataModificationTransaction beginTransaction() {
133 return dataReader.beginTransaction();
137 public ListenerRegistration<DataChangeListener> registerDataChangeListener(InstanceIdentifier path,
138 DataChangeListener listener) {
139 return dataReader.registerDataChangeListener(path, listener);
143 public void sendNotification(CompositeNode notification) {
144 publish(notification);
148 public Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registerCommitHandler(
149 InstanceIdentifier path, DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
150 return dataReader.registerCommitHandler(path, commitHandler);
154 public void removeRefresher(DataStoreIdentifier store, DataRefresher refresher) {
159 public void addRefresher(DataStoreIdentifier store, DataRefresher refresher) {
164 public void addValidator(DataStoreIdentifier store, DataValidator validator) {
168 public void removeValidator(DataStoreIdentifier store, DataValidator validator) {
172 public SchemaContext getSchemaContext() {
173 return schemaContext;
176 public void setSchemaContext(SchemaContext schemaContext) {
177 this.schemaContext = schemaContext;
180 class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
183 private InstanceIdentifier shortenPath(InstanceIdentifier path) {
184 InstanceIdentifier ret = null;
185 if(mountPath.contains(path)) {
186 List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
187 ret = new InstanceIdentifier(newArgs);
193 public CompositeNode readConfigurationData(InstanceIdentifier path) {
194 InstanceIdentifier newPath = shortenPath(path);
195 if(newPath == null) {
198 return MountPointImpl.this.readConfigurationData(newPath);
202 public CompositeNode readOperationalData(InstanceIdentifier path) {
203 InstanceIdentifier newPath = shortenPath(path);
204 if(newPath == null) {
207 return MountPointImpl.this.readOperationalData(newPath);
212 public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
213 RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
214 return dataReader.registerCommitHandlerListener(commitHandlerListener);
218 public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
220 return rpcs.registerRouteChangeListener(listener);