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

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