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 com.google.common.collect.Iterables;
11 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.controller.md.sal.common.api.RegistrationListener;
14 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
15 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandlerRegistration;
16 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
17 import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
18 import org.opendaylight.controller.sal.common.DataStoreIdentifier;
19 import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration;
20 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration;
21 import org.opendaylight.controller.sal.core.api.RoutedRpcDefaultImplementation;
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.YangInstanceIdentifier;
40 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<YangInstanceIdentifier,CompositeNode> readWrapper;
51 private final YangInstanceIdentifier mountPath;
53 private SchemaContext schemaContext;
55 public MountPointImpl(final YangInstanceIdentifier 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 YangInstanceIdentifier getMountPath() {
67 public DataReader<YangInstanceIdentifier, CompositeNode> getReadWrapper() {
72 public void publish(final CompositeNode notification) {
73 notificationRouter.publish(notification);
77 public ListenerRegistration<NotificationListener> addNotificationListener(final QName notification, final NotificationListener listener) {
78 return notificationRouter.addNotificationListener(notification, listener);
82 public CompositeNode readConfigurationData(final YangInstanceIdentifier path) {
83 return dataReader.readConfigurationData(path);
87 public CompositeNode readOperationalData(final YangInstanceIdentifier path) {
88 return dataReader.readOperationalData(path);
92 public Registration registerOperationalReader(
93 final YangInstanceIdentifier path, final DataReader<YangInstanceIdentifier, CompositeNode> reader) {
94 return dataReader.registerOperationalReader(path, reader);
98 public Registration registerConfigurationReader(
99 final YangInstanceIdentifier path, final DataReader<YangInstanceIdentifier, CompositeNode> reader) {
100 return dataReader.registerConfigurationReader(path, reader);
104 public RoutedRpcRegistration addRoutedRpcImplementation(final QName rpcType, final RpcImplementation implementation) {
105 return rpcs.addRoutedRpcImplementation(rpcType, implementation);
109 public void setRoutedRpcDefaultDelegate(final RoutedRpcDefaultImplementation defaultImplementation) {
110 rpcs.setRoutedRpcDefaultDelegate(defaultImplementation);
114 public RpcRegistration addRpcImplementation(final QName rpcType, final RpcImplementation implementation)
115 throws IllegalArgumentException {
116 return rpcs.addRpcImplementation(rpcType, implementation);
120 public Set<QName> getSupportedRpcs() {
121 return rpcs.getSupportedRpcs();
125 public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(final QName rpc, final CompositeNode input) {
126 return rpcs.invokeRpc(rpc, input);
130 public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(final RpcRegistrationListener listener) {
131 return rpcs.addRpcRegistrationListener(listener);
135 public ListenableFuture<RpcResult<CompositeNode>> rpc(final QName type, final CompositeNode input) {
136 return rpcs.invokeRpc( type, input );
140 public DataModificationTransaction beginTransaction() {
141 return dataReader.beginTransaction();
145 public ListenerRegistration<DataChangeListener> registerDataChangeListener(final YangInstanceIdentifier path,
146 final DataChangeListener listener) {
147 return dataReader.registerDataChangeListener(path, listener);
151 public Registration registerCommitHandler(
152 final YangInstanceIdentifier path, final DataCommitHandler<YangInstanceIdentifier, CompositeNode> commitHandler) {
153 return dataReader.registerCommitHandler(path, commitHandler);
157 public void removeRefresher(final DataStoreIdentifier store, final DataRefresher refresher) {
162 public void addRefresher(final DataStoreIdentifier store, final DataRefresher refresher) {
167 public void addValidator(final DataStoreIdentifier store, final DataValidator validator) {
171 public void removeValidator(final DataStoreIdentifier store, final DataValidator validator) {
176 public SchemaContext getSchemaContext() {
177 return schemaContext;
181 public void setSchemaContext(final SchemaContext schemaContext) {
182 this.schemaContext = schemaContext;
185 class ReadWrapper implements DataReader<YangInstanceIdentifier, CompositeNode> {
186 private YangInstanceIdentifier shortenPath(final YangInstanceIdentifier path) {
187 if (!mountPath.contains(path)) {
191 return YangInstanceIdentifier.create(Iterables.skip(path.getPathArguments(), Iterables.size(mountPath.getPathArguments())));
195 public CompositeNode readConfigurationData(final YangInstanceIdentifier path) {
196 YangInstanceIdentifier newPath = shortenPath(path);
197 if(newPath == null) {
200 return MountPointImpl.this.readConfigurationData(newPath);
204 public CompositeNode readOperationalData(final YangInstanceIdentifier path) {
205 YangInstanceIdentifier newPath = shortenPath(path);
206 if(newPath == null) {
209 return MountPointImpl.this.readOperationalData(newPath);
214 public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<YangInstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
215 final RegistrationListener<DataCommitHandlerRegistration<YangInstanceIdentifier, CompositeNode>> commitHandlerListener) {
216 return dataReader.registerCommitHandlerListener(commitHandlerListener);
220 public <L extends RouteChangeListener<RpcRoutingContext, YangInstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
222 return rpcs.registerRouteChangeListener(listener);