Cleanup warnings 55/5355/2
authorRobert Varga <rovarga@cisco.com>
Sun, 16 Feb 2014 10:22:45 +0000 (11:22 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 17 Feb 2014 09:58:01 +0000 (09:58 +0000)
Change-Id: I26d45b3f3856ddd893b54089521b5366deb34db3
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/event/RemoteDataChangeEvent.java
opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/NotificationServiceImpl.java

index 5fad76ff0831e089216337321ffaf57ed1d62989..9dfd262da2a99c55f899ea9b615ed9e911f5fa89 100644 (file)
@@ -7,24 +7,79 @@
  */
 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
@@ -49,89 +104,41 @@ public class RemoteDataChangeEvent implements DataChangeEvent<InstanceIdentifier
 
     @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;
     }
 }
index a0162395f57c6a88f529ab407d2ebe8578e194e3..3272ce56707eff0159efbab3d3106f281e188f1a 100644 (file)
@@ -7,14 +7,11 @@
  */
 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;
@@ -27,9 +24,14 @@ import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext;
 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;
@@ -82,9 +84,8 @@ public class NotificationServiceImpl implements NotificationService {
         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
@@ -92,14 +93,13 @@ public class NotificationServiceImpl implements NotificationService {
         //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;
         }