Merge "Fixed bug when RPC was not propagared"
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / MountPointImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.dom.broker;
9
10 import java.util.List;
11 import java.util.Set;
12 import java.util.concurrent.Future;
13
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;
42
43 public class MountPointImpl implements MountProvisionInstance, SchemaContextProvider {
44
45     private final SchemaAwareRpcBroker rpcs;
46     private final DataBrokerImpl dataReader;
47     private final NotificationRouter notificationRouter;
48     private final DataReader<InstanceIdentifier,CompositeNode> readWrapper;
49     
50     
51     private final InstanceIdentifier mountPath;
52
53     private SchemaContext schemaContext;
54
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();
61     }
62
63     public InstanceIdentifier getMountPath() {
64         return mountPath;
65     }
66
67     public DataReader<InstanceIdentifier, CompositeNode> getReadWrapper() {
68         return readWrapper;
69     }
70
71     @Override
72     public void publish(CompositeNode notification) {
73         notificationRouter.publish(notification);
74     }
75
76     @Override
77     public Registration<NotificationListener> addNotificationListener(QName notification, NotificationListener listener) {
78         return notificationRouter.addNotificationListener(notification, listener);
79     }
80
81     @Override
82     public CompositeNode readConfigurationData(InstanceIdentifier path) {
83         return dataReader.readConfigurationData(path);
84     }
85
86     @Override
87     public CompositeNode readOperationalData(InstanceIdentifier path) {
88         return dataReader.readOperationalData(path);
89     }
90
91     public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerOperationalReader(
92             InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
93         return dataReader.registerOperationalReader(path, reader);
94     }
95
96     public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerConfigurationReader(
97             InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
98         return dataReader.registerConfigurationReader(path, reader);
99     }
100
101     @Override
102     public RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
103         return rpcs.addRoutedRpcImplementation(rpcType, implementation);
104     }
105
106     @Override
107     public RpcRegistration addRpcImplementation(QName rpcType, RpcImplementation implementation)
108             throws IllegalArgumentException {
109         return rpcs.addRpcImplementation(rpcType, implementation);
110     }
111
112     public Set<QName> getSupportedRpcs() {
113         return rpcs.getSupportedRpcs();
114     }
115
116     
117     public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
118         return rpcs.invokeRpc(rpc, input);
119     }
120
121     public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener) {
122         return rpcs.addRpcRegistrationListener(listener);
123     }
124
125
126     @Override
127     public Future<RpcResult<CompositeNode>> rpc(QName type, CompositeNode input) {
128         return null;
129     }
130
131     @Override
132     public DataModificationTransaction beginTransaction() {
133         return dataReader.beginTransaction();
134     }
135
136     @Override
137     public ListenerRegistration<DataChangeListener> registerDataChangeListener(InstanceIdentifier path,
138             DataChangeListener listener) {
139         return dataReader.registerDataChangeListener(path, listener);
140     }
141
142     @Override
143     public void sendNotification(CompositeNode notification) {
144         publish(notification);
145     }
146     
147     @Override
148     public Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registerCommitHandler(
149             InstanceIdentifier path, DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
150         return dataReader.registerCommitHandler(path, commitHandler);
151     }
152     
153     @Override
154     public void removeRefresher(DataStoreIdentifier store, DataRefresher refresher) {
155      // NOOP
156     }
157     
158     @Override
159     public void addRefresher(DataStoreIdentifier store, DataRefresher refresher) {
160      // NOOP
161     }
162     
163     @Override
164     public void addValidator(DataStoreIdentifier store, DataValidator validator) {
165      // NOOP
166     }
167     @Override
168     public void removeValidator(DataStoreIdentifier store, DataValidator validator) {
169         // NOOP
170     }
171     
172     public SchemaContext getSchemaContext() {
173         return schemaContext;
174     }
175
176     public void setSchemaContext(SchemaContext schemaContext) {
177         this.schemaContext = schemaContext;
178     }
179
180     class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
181         
182         
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);
188             }
189             return ret;
190         }
191         
192         @Override
193         public CompositeNode readConfigurationData(InstanceIdentifier path) {
194             InstanceIdentifier newPath = shortenPath(path);
195             if(newPath == null) {
196                 return null;
197             }
198             return MountPointImpl.this.readConfigurationData(newPath);
199         }
200         
201         @Override
202         public CompositeNode readOperationalData(InstanceIdentifier path) {
203             InstanceIdentifier newPath = shortenPath(path);
204             if(newPath == null) {
205                 return null;
206             }
207             return MountPointImpl.this.readOperationalData(newPath);
208         }
209     }
210
211     @Override
212     public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
213             RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
214         return dataReader.registerCommitHandlerListener(commitHandlerListener);
215     }
216
217     @Override
218     public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
219             L listener) {
220         return rpcs.registerRouteChangeListener(listener);
221     }
222
223
224 }