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);
93 public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerOperationalReader(
94 InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
95 return dataReader.registerOperationalReader(path, reader);
99 public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerConfigurationReader(
100 InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
101 return dataReader.registerConfigurationReader(path, reader);
105 public RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
106 return rpcs.addRoutedRpcImplementation(rpcType, implementation);
110 public void setRoutedRpcDefaultDelegate(RoutedRpcDefaultImplementation defaultImplementation) {
111 rpcs.setRoutedRpcDefaultDelegate(defaultImplementation);
115 public RpcRegistration addRpcImplementation(QName rpcType, RpcImplementation implementation)
116 throws IllegalArgumentException {
117 return rpcs.addRpcImplementation(rpcType, implementation);
121 public Set<QName> getSupportedRpcs() {
122 return rpcs.getSupportedRpcs();
127 public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
128 return rpcs.invokeRpc(rpc, input);
132 public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener) {
133 return rpcs.addRpcRegistrationListener(listener);
138 public Future<RpcResult<CompositeNode>> rpc(QName type, CompositeNode input) {
143 public DataModificationTransaction beginTransaction() {
144 return dataReader.beginTransaction();
148 public ListenerRegistration<DataChangeListener> registerDataChangeListener(InstanceIdentifier path,
149 DataChangeListener listener) {
150 return dataReader.registerDataChangeListener(path, listener);
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) {
179 public SchemaContext getSchemaContext() {
180 return schemaContext;
184 public void setSchemaContext(SchemaContext schemaContext) {
185 this.schemaContext = schemaContext;
188 class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
191 private InstanceIdentifier shortenPath(InstanceIdentifier path) {
192 InstanceIdentifier ret = null;
193 if(mountPath.contains(path)) {
194 List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
195 ret = new InstanceIdentifier(newArgs);
201 public CompositeNode readConfigurationData(InstanceIdentifier path) {
202 InstanceIdentifier newPath = shortenPath(path);
203 if(newPath == null) {
206 return MountPointImpl.this.readConfigurationData(newPath);
210 public CompositeNode readOperationalData(InstanceIdentifier path) {
211 InstanceIdentifier newPath = shortenPath(path);
212 if(newPath == null) {
215 return MountPointImpl.this.readOperationalData(newPath);
220 public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
221 RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
222 return dataReader.registerCommitHandlerListener(commitHandlerListener);
226 public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
228 return rpcs.registerRouteChangeListener(listener);