*/
package org.opendaylight.controller.sal.restconf.broker.event;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+
+import javax.annotation.concurrent.ThreadSafe;
+
import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.DataChangedNotification;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+@ThreadSafe
public class RemoteDataChangeEvent implements DataChangeEvent<InstanceIdentifier<? extends DataObject>,DataObject> {
-
-
- private final DataChangedNotification dataChangedNotification;
-
-
- public RemoteDataChangeEvent(DataChangedNotification dataChangedNotification){
-
- this.dataChangedNotification = dataChangedNotification;
+ private final Map<InstanceIdentifier<?>, DataObject> createdConfig, createdOper, origConfig, origOper, updatedConfig, updatedOper;
+ private final Set<InstanceIdentifier<?>> removedConfig, removedOper;
+
+ public RemoteDataChangeEvent(DataChangedNotification dataChangedNotification) {
+ final Map<InstanceIdentifier<?>, DataObject> createdConfig = new HashMap<>();
+ final Map<InstanceIdentifier<?>, DataObject> createdOper = new HashMap<>();
+ final Map<InstanceIdentifier<?>, DataObject> origConfig = new HashMap<>();
+ final Map<InstanceIdentifier<?>, DataObject> origOper = new HashMap<>();
+ final Map<InstanceIdentifier<?>, DataObject> updatedConfig = new HashMap<>();
+ final Map<InstanceIdentifier<?>, DataObject> updatedOper = new HashMap<>();
+ final Set<InstanceIdentifier<?>> removedConfig = new HashSet<>();
+ final Set<InstanceIdentifier<?>> removedOper = new HashSet<>();
+
+ for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.data.changed.notification.DataChangeEvent d :dataChangedNotification.getDataChangeEvent()) {
+ switch (d.getOperation()) {
+ case Created:
+ switch (d.getStore()) {
+ case Config:
+ createdConfig.put(d.getPath(), d);
+ break;
+ case Operation:
+ createdOper.put(d.getPath(), d);
+ break;
+ }
+ break;
+ case Deleted:
+ switch (d.getStore()) {
+ case Config:
+ removedConfig.add(d.getPath());
+ break;
+ case Operation:
+ removedOper.add(d.getPath());
+ break;
+ }
+ break;
+ case Updated:
+ switch (d.getStore()) {
+ case Config:
+ origConfig.put(d.getPath(), d);
+ updatedConfig.put(d.getPath(), d);
+ break;
+ case Operation:
+ origOper.put(d.getPath(),d);
+ updatedOper.put(d.getPath(),d);
+ break;
+ }
+ break;
+ }
+ }
+
+ this.createdConfig = Collections.unmodifiableMap(createdConfig);
+ this.createdOper = Collections.unmodifiableMap(createdOper);
+ this.origConfig = Collections.unmodifiableMap(origConfig);
+ this.origOper = Collections.unmodifiableMap(origOper);
+ this.updatedConfig = Collections.unmodifiableMap(updatedConfig);
+ this.updatedOper = Collections.unmodifiableMap(updatedOper);
+ this.removedConfig = Collections.unmodifiableSet(removedConfig);
+ this.removedOper = Collections.unmodifiableSet(removedOper);
}
@Override
@Override
public Map<InstanceIdentifier<?>, DataObject> getCreatedOperationalData() {
- return new HashMap<InstanceIdentifier<?>, DataObject>(){{
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.data.changed.notification.DataChangeEvent d :dataChangedNotification.getDataChangeEvent()){
- if (d.getOperation().getIntValue() == 0 && d.getStore().getIntValue() == 1){
- put(d.getPath(),d);
- }
- }
- }};
+ return createdOper;
}
@Override
public Map<InstanceIdentifier<?>, DataObject> getCreatedConfigurationData() {
- return new HashMap<InstanceIdentifier<?>, DataObject>(){{
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.data.changed.notification.DataChangeEvent d :dataChangedNotification.getDataChangeEvent()){
- if (d.getOperation().getIntValue() == 0 && d.getStore().getIntValue() == 0){
- put(d.getPath(),d);
- }
- }
- }};
+ return createdConfig;
}
@Override
public Map<InstanceIdentifier<?>, DataObject> getUpdatedOperationalData() {
- return new HashMap<InstanceIdentifier<?>, DataObject>(){{
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.data.changed.notification.DataChangeEvent d :dataChangedNotification.getDataChangeEvent()){
- if (d.getOperation().getIntValue() == 1 && d.getStore().getIntValue() == 1){
- put(d.getPath(),d);
- }
- }
- }};
+ return updatedOper;
}
@Override
public Map<InstanceIdentifier<?>, DataObject> getUpdatedConfigurationData() {
- return new HashMap<InstanceIdentifier<?>, DataObject>(){{
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.data.changed.notification.DataChangeEvent d :dataChangedNotification.getDataChangeEvent()){
- if (d.getOperation().getIntValue() == 1 && d.getStore().getIntValue() == 0){
- put(d.getPath(),d);
- }
- }
- }};
+ return updatedConfig;
}
@Override
public Set<InstanceIdentifier<?>> getRemovedConfigurationData() {
- return new HashSet<InstanceIdentifier<?>>(){{
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.data.changed.notification.DataChangeEvent d :dataChangedNotification.getDataChangeEvent()){
- if (d.getOperation().getIntValue() == 2 && d.getStore().getIntValue() == 0){
- add(d.getPath());
- }
- }
- }};
+ return removedConfig;
}
@Override
public Set<InstanceIdentifier<?>> getRemovedOperationalData() {
- return new HashSet<InstanceIdentifier<?>>(){{
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.data.changed.notification.DataChangeEvent d :dataChangedNotification.getDataChangeEvent()){
- if (d.getOperation().getIntValue() == 2 && d.getStore().getIntValue() == 1){
- add(d.getPath());
- }
- }
- }};
+ return removedOper;
}
@Override
public Map<InstanceIdentifier<?>, DataObject> getOriginalConfigurationData() {
- return new HashMap<InstanceIdentifier<?>, DataObject>(){{
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.data.changed.notification.DataChangeEvent d :dataChangedNotification.getDataChangeEvent()){
- if (d.getOperation().getIntValue() == 1 && d.getStore().getIntValue() == 0){
- put(d.getPath(),d);
- }
- }
- }};
+ return origConfig;
}
@Override
public Map<InstanceIdentifier<?>, DataObject> getOriginalOperationalData() {
- return new HashMap<InstanceIdentifier<?>, DataObject>(){{
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.data.changed.notification.DataChangeEvent d :dataChangedNotification.getDataChangeEvent()){
- if (d.getOperation().getIntValue() == 1 && d.getStore().getIntValue() == 1){
- put(d.getPath(),d);
- }
- }
- }};
+ return origOper;
}
}
*/
package org.opendaylight.controller.sal.restconf.broker.impl;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Multimaps;
-import com.google.common.collect.SetMultimap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
+
import org.opendaylight.controller.sal.binding.api.NotificationListener;
import org.opendaylight.controller.sal.binding.api.NotificationService;
import org.opendaylight.controller.sal.restconf.broker.listeners.RemoteNotificationListener;
import org.opendaylight.yangtools.restconf.client.api.event.EventStreamInfo;
import org.opendaylight.yangtools.yang.binding.Notification;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+
public class NotificationServiceImpl implements NotificationService {
- private SalRemoteService salRemoteService;
- private RestconfClientContext restconfClientContext;
+ private final SalRemoteService salRemoteService;
+ private final RestconfClientContext restconfClientContext;
private final Multimap<Class<? extends Notification>,NotificationListener<? extends Object>> listeners;
private ExecutorService _executor;
String notificationStreamName = RemoteStreamTools.createNotificationStream(salRemoteService, notifications);
final Map<String,EventStreamInfo> desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext, notificationStreamName);
RemoteNotificationListener remoteNotificationListener = new RemoteNotificationListener(listener);
- ListenerRegistration listenerRegistration = restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName))).registerNotificationListener(remoteNotificationListener);
- SalNotificationRegistration salNotificationRegistration = new SalNotificationRegistration(listenerRegistration);
- return salNotificationRegistration;
+ ListenerRegistration<?> listenerRegistration = restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName))).registerNotificationListener(remoteNotificationListener);
+ return new SalNotificationRegistration<T>(listenerRegistration);
}
@Override
//TODO implementation using sal-remote
String notificationStreamName = RemoteStreamTools.createNotificationStream(salRemoteService, null);
final Map<String,EventStreamInfo> desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext, notificationStreamName);
- ListenerRegistration listenerRegistration = restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName))).registerNotificationListener(listener);
- return listenerRegistration;
+ return restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName))).registerNotificationListener(listener);
}
private class SalNotificationRegistration<T extends Notification> implements Registration<NotificationListener<T>>{
- private Registration registration;
+ private final Registration<?> registration;
- public SalNotificationRegistration(ListenerRegistration listenerRegistration){
+ public SalNotificationRegistration(ListenerRegistration<?> listenerRegistration){
this.registration = listenerRegistration;
}