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     public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerOperationalReader(
93             InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
94         return dataReader.registerOperationalReader(path, reader);
95     }
96
97     public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerConfigurationReader(
98             InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
99         return dataReader.registerConfigurationReader(path, reader);
100     }
101
102     @Override
103     public RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
104         return rpcs.addRoutedRpcImplementation(rpcType, implementation);
105     }
106
107     @Override
108     public void setRoutedRpcDefaultDelegate(RoutedRpcDefaultImplementation defaultImplementation) {
109       rpcs.setRoutedRpcDefaultDelegate(defaultImplementation);
110     }
111
112   @Override
113     public RpcRegistration addRpcImplementation(QName rpcType, RpcImplementation implementation)
114             throws IllegalArgumentException {
115         return rpcs.addRpcImplementation(rpcType, implementation);
116     }
117
118     public Set<QName> getSupportedRpcs() {
119         return rpcs.getSupportedRpcs();
120     }
121
122     
123     public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
124         return rpcs.invokeRpc(rpc, input);
125     }
126
127     public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener) {
128         return rpcs.addRpcRegistrationListener(listener);
129     }
130
131
132     @Override
133     public Future<RpcResult<CompositeNode>> rpc(QName type, CompositeNode input) {
134         return null;
135     }
136
137     @Override
138     public DataModificationTransaction beginTransaction() {
139         return dataReader.beginTransaction();
140     }
141
142     @Override
143     public ListenerRegistration<DataChangeListener> registerDataChangeListener(InstanceIdentifier path,
144             DataChangeListener listener) {
145         return dataReader.registerDataChangeListener(path, listener);
146     }
147
148     @Override
149     public void sendNotification(CompositeNode notification) {
150         publish(notification);
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     public SchemaContext getSchemaContext() {
179         return schemaContext;
180     }
181
182     public void setSchemaContext(SchemaContext schemaContext) {
183         this.schemaContext = schemaContext;
184     }
185
186     class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
187         
188         
189         private InstanceIdentifier shortenPath(InstanceIdentifier path) {
190             InstanceIdentifier ret = null;
191             if(mountPath.contains(path)) {
192                 List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
193                 ret = new InstanceIdentifier(newArgs);
194             }
195             return ret;
196         }
197         
198         @Override
199         public CompositeNode readConfigurationData(InstanceIdentifier path) {
200             InstanceIdentifier newPath = shortenPath(path);
201             if(newPath == null) {
202                 return null;
203             }
204             return MountPointImpl.this.readConfigurationData(newPath);
205         }
206         
207         @Override
208         public CompositeNode readOperationalData(InstanceIdentifier path) {
209             InstanceIdentifier newPath = shortenPath(path);
210             if(newPath == null) {
211                 return null;
212             }
213             return MountPointImpl.this.readOperationalData(newPath);
214         }
215     }
216
217     @Override
218     public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
219             RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
220         return dataReader.registerCommitHandlerListener(commitHandlerListener);
221     }
222
223     @Override
224     public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
225             L listener) {
226         return rpcs.registerRouteChangeListener(listener);
227     }
228
229
230 }