Add MountInstance client documentation and promote to ListenableFuture
[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
127     @Override
128     public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
129         return rpcs.invokeRpc(rpc, input);
130     }
131
132     @Override
133     public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener) {
134         return rpcs.addRpcRegistrationListener(listener);
135     }
136
137
138     @Override
139     public ListenableFuture<RpcResult<CompositeNode>> rpc(QName type, CompositeNode input) {
140         return null;
141     }
142
143     @Override
144     public DataModificationTransaction beginTransaction() {
145         return dataReader.beginTransaction();
146     }
147
148     @Override
149     public ListenerRegistration<DataChangeListener> registerDataChangeListener(InstanceIdentifier path,
150             DataChangeListener listener) {
151         return dataReader.registerDataChangeListener(path, listener);
152     }
153
154     @Override
155     public Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registerCommitHandler(
156             InstanceIdentifier path, DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
157         return dataReader.registerCommitHandler(path, commitHandler);
158     }
159
160     @Override
161     public void removeRefresher(DataStoreIdentifier store, DataRefresher refresher) {
162      // NOOP
163     }
164
165     @Override
166     public void addRefresher(DataStoreIdentifier store, DataRefresher refresher) {
167      // NOOP
168     }
169
170     @Override
171     public void addValidator(DataStoreIdentifier store, DataValidator validator) {
172      // NOOP
173     }
174     @Override
175     public void removeValidator(DataStoreIdentifier store, DataValidator validator) {
176         // NOOP
177     }
178
179     @Override
180     public SchemaContext getSchemaContext() {
181         return schemaContext;
182     }
183
184     @Override
185     public void setSchemaContext(SchemaContext schemaContext) {
186         this.schemaContext = schemaContext;
187     }
188
189     class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
190
191
192         private InstanceIdentifier shortenPath(InstanceIdentifier path) {
193             InstanceIdentifier ret = null;
194             if(mountPath.contains(path)) {
195                 List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
196                 ret = new InstanceIdentifier(newArgs);
197             }
198             return ret;
199         }
200
201         @Override
202         public CompositeNode readConfigurationData(InstanceIdentifier path) {
203             InstanceIdentifier newPath = shortenPath(path);
204             if(newPath == null) {
205                 return null;
206             }
207             return MountPointImpl.this.readConfigurationData(newPath);
208         }
209
210         @Override
211         public CompositeNode readOperationalData(InstanceIdentifier path) {
212             InstanceIdentifier newPath = shortenPath(path);
213             if(newPath == null) {
214                 return null;
215             }
216             return MountPointImpl.this.readOperationalData(newPath);
217         }
218     }
219
220     @Override
221     public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
222             RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
223         return dataReader.registerCommitHandlerListener(commitHandlerListener);
224     }
225
226     @Override
227     public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
228             L listener) {
229         return rpcs.registerRouteChangeListener(listener);
230     }
231
232
233 }

©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.