623bbdb19514ce15ffa0b9102959fbac77cb51d2
[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
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.InstanceIdentifier;
40 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
41 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
42
43 import com.google.common.util.concurrent.ListenableFuture;
44
45 public class MountPointImpl implements MountProvisionInstance, SchemaContextProvider {
46
47     private final SchemaAwareRpcBroker rpcs;
48     private final DataBrokerImpl dataReader;
49     private final NotificationRouter notificationRouter;
50     private final DataReader<InstanceIdentifier,CompositeNode> readWrapper;
51
52
53     private final InstanceIdentifier mountPath;
54
55     private SchemaContext schemaContext;
56
57     public MountPointImpl(InstanceIdentifier path) {
58         this.mountPath = path;
59         rpcs = new SchemaAwareRpcBroker(path.toString(),this);
60         dataReader = new DataBrokerImpl();
61         notificationRouter = new NotificationRouterImpl();
62         readWrapper = new ReadWrapper();
63     }
64
65     public InstanceIdentifier getMountPath() {
66         return mountPath;
67     }
68
69     public DataReader<InstanceIdentifier, CompositeNode> getReadWrapper() {
70         return readWrapper;
71     }
72
73     @Override
74     public void publish(CompositeNode notification) {
75         notificationRouter.publish(notification);
76     }
77
78     @Override
79     public Registration<NotificationListener> addNotificationListener(QName notification, NotificationListener listener) {
80         return notificationRouter.addNotificationListener(notification, listener);
81     }
82
83     @Override
84     public CompositeNode readConfigurationData(InstanceIdentifier path) {
85         return dataReader.readConfigurationData(path);
86     }
87
88     @Override
89     public CompositeNode readOperationalData(InstanceIdentifier path) {
90         return dataReader.readOperationalData(path);
91     }
92
93     @Override
94     public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerOperationalReader(
95             InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
96         return dataReader.registerOperationalReader(path, reader);
97     }
98
99     @Override
100     public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerConfigurationReader(
101             InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
102         return dataReader.registerConfigurationReader(path, reader);
103     }
104
105     @Override
106     public RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
107         return rpcs.addRoutedRpcImplementation(rpcType, implementation);
108     }
109
110     @Override
111     public void setRoutedRpcDefaultDelegate(RoutedRpcDefaultImplementation defaultImplementation) {
112       rpcs.setRoutedRpcDefaultDelegate(defaultImplementation);
113     }
114
115   @Override
116     public RpcRegistration addRpcImplementation(QName rpcType, RpcImplementation implementation)
117             throws IllegalArgumentException {
118         return rpcs.addRpcImplementation(rpcType, implementation);
119     }
120
121     @Override
122     public Set<QName> getSupportedRpcs() {
123         return rpcs.getSupportedRpcs();
124     }
125
126     @Override
127     public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input) {
128         return rpcs.invokeRpc(rpc, input);
129     }
130
131     @Override
132     public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener) {
133         return rpcs.addRpcRegistrationListener(listener);
134     }
135
136     @Override
137     public ListenableFuture<RpcResult<CompositeNode>> rpc(QName type, CompositeNode input) {
138         return rpcs.invokeRpc( type, input );
139     }
140
141     @Override
142     public DataModificationTransaction beginTransaction() {
143         return dataReader.beginTransaction();
144     }
145
146     @Override
147     public ListenerRegistration<DataChangeListener> registerDataChangeListener(InstanceIdentifier path,
148             DataChangeListener listener) {
149         return dataReader.registerDataChangeListener(path, listener);
150     }
151
152     @Override
153     public Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registerCommitHandler(
154             InstanceIdentifier path, DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
155         return dataReader.registerCommitHandler(path, commitHandler);
156     }
157
158     @Override
159     public void removeRefresher(DataStoreIdentifier store, DataRefresher refresher) {
160      // NOOP
161     }
162
163     @Override
164     public void addRefresher(DataStoreIdentifier store, DataRefresher refresher) {
165      // NOOP
166     }
167
168     @Override
169     public void addValidator(DataStoreIdentifier store, DataValidator validator) {
170      // NOOP
171     }
172     @Override
173     public void removeValidator(DataStoreIdentifier store, DataValidator validator) {
174         // NOOP
175     }
176
177     @Override
178     public SchemaContext getSchemaContext() {
179         return schemaContext;
180     }
181
182     @Override
183     public void setSchemaContext(SchemaContext schemaContext) {
184         this.schemaContext = schemaContext;
185     }
186
187     class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
188
189
190         private InstanceIdentifier shortenPath(InstanceIdentifier path) {
191             InstanceIdentifier ret = null;
192             if(mountPath.contains(path)) {
193                 List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
194                 ret = new InstanceIdentifier(newArgs);
195             }
196             return ret;
197         }
198
199         @Override
200         public CompositeNode readConfigurationData(InstanceIdentifier path) {
201             InstanceIdentifier newPath = shortenPath(path);
202             if(newPath == null) {
203                 return null;
204             }
205             return MountPointImpl.this.readConfigurationData(newPath);
206         }
207
208         @Override
209         public CompositeNode readOperationalData(InstanceIdentifier path) {
210             InstanceIdentifier newPath = shortenPath(path);
211             if(newPath == null) {
212                 return null;
213             }
214             return MountPointImpl.this.readOperationalData(newPath);
215         }
216     }
217
218     @Override
219     public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
220             RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
221         return dataReader.registerCommitHandlerListener(commitHandlerListener);
222     }
223
224     @Override
225     public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
226             L listener) {
227         return rpcs.registerRouteChangeListener(listener);
228     }
229 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.