Merge "BugFix : Changes to get ping between two hosts to work"
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / MountPointImpl.java
1 package org.opendaylight.controller.sal.dom.broker;
2
3 import java.util.List;
4 import java.util.Set;
5 import java.util.concurrent.Future;
6
7 import org.opendaylight.controller.md.sal.common.api.RegistrationListener;
8 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
9 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandlerRegistration;
10 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
11 import org.opendaylight.controller.sal.common.DataStoreIdentifier;
12 import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration;
13 import org.opendaylight.controller.sal.core.api.RpcImplementation;
14 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration;
15 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
16 import org.opendaylight.controller.sal.core.api.data.DataChangeListener;
17 import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction;
18 import org.opendaylight.controller.sal.core.api.data.DataValidator;
19 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
20 import org.opendaylight.controller.sal.core.api.notify.NotificationListener;
21 import org.opendaylight.controller.sal.dom.broker.impl.DataReaderRouter;
22 import org.opendaylight.controller.sal.dom.broker.impl.NotificationRouterImpl;
23 import org.opendaylight.controller.sal.dom.broker.impl.RpcRouterImpl;
24 import org.opendaylight.controller.sal.dom.broker.spi.NotificationRouter;
25 import org.opendaylight.controller.sal.dom.broker.spi.RpcRouter;
26 import org.opendaylight.yangtools.concepts.ListenerRegistration;
27 import org.opendaylight.yangtools.concepts.Registration;
28 import org.opendaylight.yangtools.yang.common.QName;
29 import org.opendaylight.yangtools.yang.common.RpcResult;
30 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
31 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.InstanceIdentifierBuilder;
33 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
34 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
35
36 public class MountPointImpl implements MountProvisionInstance {
37
38     private final RpcRouter rpcs;
39     private final DataBrokerImpl dataReader;
40     private final NotificationRouter notificationRouter;
41     private final DataReader<InstanceIdentifier,CompositeNode> readWrapper;
42     
43     
44     private final InstanceIdentifier mountPath;
45
46     private SchemaContext schemaContext;
47
48     public MountPointImpl(InstanceIdentifier path) {
49         this.mountPath = path;
50         rpcs = new RpcRouterImpl("");
51         dataReader = new DataBrokerImpl();
52         notificationRouter = new NotificationRouterImpl();
53         readWrapper = new ReadWrapper();
54     }
55
56     public InstanceIdentifier getMountPath() {
57         return mountPath;
58     }
59
60     public DataReader<InstanceIdentifier, CompositeNode> getReadWrapper() {
61         return readWrapper;
62     }
63
64     @Override
65     public void publish(CompositeNode notification) {
66         notificationRouter.publish(notification);
67     }
68
69     @Override
70     public Registration<NotificationListener> addNotificationListener(QName notification, NotificationListener listener) {
71         return notificationRouter.addNotificationListener(notification, listener);
72     }
73
74     @Override
75     public CompositeNode readConfigurationData(InstanceIdentifier path) {
76         return dataReader.readConfigurationData(path);
77     }
78
79     @Override
80     public CompositeNode readOperationalData(InstanceIdentifier path) {
81         return dataReader.readOperationalData(path);
82     }
83
84     public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerOperationalReader(
85             InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
86         return dataReader.registerOperationalReader(path, reader);
87     }
88
89     public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerConfigurationReader(
90             InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
91         return dataReader.registerConfigurationReader(path, reader);
92     }
93
94     @Override
95     public RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
96         return rpcs.addRoutedRpcImplementation(rpcType, implementation);
97     }
98
99     @Override
100     public RpcRegistration addRpcImplementation(QName rpcType, RpcImplementation implementation)
101             throws IllegalArgumentException {
102         return rpcs.addRpcImplementation(rpcType, implementation);
103     }
104
105     public Set<QName> getSupportedRpcs() {
106         return rpcs.getSupportedRpcs();
107     }
108
109     
110     public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
111         return rpcs.invokeRpc(rpc, input);
112     }
113
114     public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener) {
115         return rpcs.addRpcRegistrationListener(listener);
116     }
117
118
119     @Override
120     public Future<RpcResult<CompositeNode>> rpc(QName type, CompositeNode input) {
121         // TODO Auto-generated method stub
122         return null;
123     }
124
125     @Override
126     public DataModificationTransaction beginTransaction() {
127         return dataReader.beginTransaction();
128     }
129
130     @Override
131     public ListenerRegistration<DataChangeListener> registerDataChangeListener(InstanceIdentifier path,
132             DataChangeListener listener) {
133         return dataReader.registerDataChangeListener(path, listener);
134     }
135
136     @Override
137     public void sendNotification(CompositeNode notification) {
138         publish(notification);
139     }
140     
141     @Override
142     public Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registerCommitHandler(
143             InstanceIdentifier path, DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
144         return dataReader.registerCommitHandler(path, commitHandler);
145     }
146     
147     @Override
148     public void removeRefresher(DataStoreIdentifier store, DataRefresher refresher) {
149      // NOOP
150     }
151     
152     @Override
153     public void addRefresher(DataStoreIdentifier store, DataRefresher refresher) {
154      // NOOP
155     }
156     
157     @Override
158     public void addValidator(DataStoreIdentifier store, DataValidator validator) {
159      // NOOP
160     }
161     @Override
162     public void removeValidator(DataStoreIdentifier store, DataValidator validator) {
163         // NOOP
164     }
165     
166     public SchemaContext getSchemaContext() {
167         return schemaContext;
168     }
169
170     public void setSchemaContext(SchemaContext schemaContext) {
171         this.schemaContext = schemaContext;
172     }
173
174     class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
175         
176         
177         private InstanceIdentifier shortenPath(InstanceIdentifier path) {
178             InstanceIdentifier ret = null;
179             if(mountPath.contains(path)) {
180                 List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
181                 ret = new InstanceIdentifier(newArgs);
182             }
183             return ret;
184         }
185         
186         @Override
187         public CompositeNode readConfigurationData(InstanceIdentifier path) {
188             InstanceIdentifier newPath = shortenPath(path);
189             if(newPath == null) {
190                 return null;
191             }
192             return MountPointImpl.this.readConfigurationData(newPath);
193         }
194         
195         @Override
196         public CompositeNode readOperationalData(InstanceIdentifier path) {
197             InstanceIdentifier newPath = shortenPath(path);
198             if(newPath == null) {
199                 return null;
200             }
201             return MountPointImpl.this.readOperationalData(newPath);
202         }
203     }
204
205     @Override
206     public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
207             RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
208         return dataReader.registerCommitHandlerListener(commitHandlerListener);
209     }
210 }