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