From 2360c06ec47235dff72d480292cc50abebcea418 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 16 Feb 2014 11:22:45 +0100 Subject: [PATCH] Cleanup warnings Change-Id: I26d45b3f3856ddd893b54089521b5366deb34db3 Signed-off-by: Robert Varga --- .../broker/event/RemoteDataChangeEvent.java | 135 +++++++++--------- .../broker/impl/NotificationServiceImpl.java | 26 ++-- 2 files changed, 84 insertions(+), 77 deletions(-) diff --git a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/event/RemoteDataChangeEvent.java b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/event/RemoteDataChangeEvent.java index 5fad76ff08..9dfd262da2 100644 --- a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/event/RemoteDataChangeEvent.java +++ b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/event/RemoteDataChangeEvent.java @@ -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,DataObject> { - - - private final DataChangedNotification dataChangedNotification; - - - public RemoteDataChangeEvent(DataChangedNotification dataChangedNotification){ - - this.dataChangedNotification = dataChangedNotification; + private final Map, DataObject> createdConfig, createdOper, origConfig, origOper, updatedConfig, updatedOper; + private final Set> removedConfig, removedOper; + + public RemoteDataChangeEvent(DataChangedNotification dataChangedNotification) { + final Map, DataObject> createdConfig = new HashMap<>(); + final Map, DataObject> createdOper = new HashMap<>(); + final Map, DataObject> origConfig = new HashMap<>(); + final Map, DataObject> origOper = new HashMap<>(); + final Map, DataObject> updatedConfig = new HashMap<>(); + final Map, DataObject> updatedOper = new HashMap<>(); + final Set> removedConfig = new HashSet<>(); + final Set> 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, DataObject> getCreatedOperationalData() { - return new HashMap, 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, DataObject> getCreatedConfigurationData() { - return new HashMap, 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, DataObject> getUpdatedOperationalData() { - return new HashMap, 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, DataObject> getUpdatedConfigurationData() { - return new HashMap, 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> getRemovedConfigurationData() { - return 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()){ - if (d.getOperation().getIntValue() == 2 && d.getStore().getIntValue() == 0){ - add(d.getPath()); - } - } - }}; + return removedConfig; } @Override public Set> getRemovedOperationalData() { - return 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()){ - if (d.getOperation().getIntValue() == 2 && d.getStore().getIntValue() == 1){ - add(d.getPath()); - } - } - }}; + return removedOper; } @Override public Map, DataObject> getOriginalConfigurationData() { - return new HashMap, 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, DataObject> getOriginalOperationalData() { - return new HashMap, 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; } } diff --git a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/NotificationServiceImpl.java b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/NotificationServiceImpl.java index a0162395f5..3272ce5670 100644 --- a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/NotificationServiceImpl.java +++ b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/NotificationServiceImpl.java @@ -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,NotificationListener> listeners; private ExecutorService _executor; @@ -82,9 +84,8 @@ public class NotificationServiceImpl implements NotificationService { String notificationStreamName = RemoteStreamTools.createNotificationStream(salRemoteService, notifications); final Map 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(listenerRegistration); } @Override @@ -92,14 +93,13 @@ public class NotificationServiceImpl implements NotificationService { //TODO implementation using sal-remote String notificationStreamName = RemoteStreamTools.createNotificationStream(salRemoteService, null); final Map 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 implements Registration>{ - private Registration registration; + private final Registration registration; - public SalNotificationRegistration(ListenerRegistration listenerRegistration){ + public SalNotificationRegistration(ListenerRegistration listenerRegistration){ this.registration = listenerRegistration; } -- 2.36.6