ThrottledNotificationsOfferer should not be generic 05/20605/1
authorRobert Varga <rovarga@cisco.com>
Sat, 16 May 2015 16:36:14 +0000 (18:36 +0200)
committerRobert Varga <rovarga@cisco.com>
Sat, 16 May 2015 16:43:31 +0000 (18:43 +0200)
The only use of the type argument is to bind method arguments -- which
we can spell out. This way we can reuse an offerer across multiple types
without incurring warnings.

Change-Id: Ie003f6c9ebe00f1abae4f8171086a7240843a14c
Signed-off-by: Robert Varga <rovarga@cisco.com>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/connection/ThrottledNotificationsOfferer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ThrottledNotificationsOffererImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java

index 3fae497d7a79d9962387afa79372be01c74bdde3..4c42fa7ebb4bf4e8798c1dd31bec5bf5a3f903c4 100644 (file)
@@ -10,15 +10,16 @@ package org.opendaylight.openflowplugin.api.openflow.connection;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Queue;
+import org.opendaylight.yangtools.yang.binding.Notification;
 
 /**
  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 8.5.2015.
  */
-public interface ThrottledNotificationsOfferer<T> extends AutoCloseable {
+public interface ThrottledNotificationsOfferer extends AutoCloseable {
 
-    ListenableFuture<Void> applyThrottlingOnConnection(Queue<T> notificationsQueue);
+    ListenableFuture<Void> applyThrottlingOnConnection(Queue<? extends Notification> notificationsQueue);
 
-    boolean isThrottlingEffective(Queue<T> notificationsQueue);
+    boolean isThrottlingEffective(Queue<? extends Notification> notificationsQueue);
 
     @Override
     void close() throws SecurityException;
index 85403b8024c56be6efeb0bbd51d2fdfe7d2c4c4a..92e80a45aad15a8d8bbf96c40d7c775bfdef16b4 100644 (file)
@@ -27,10 +27,10 @@ import org.slf4j.LoggerFactory;
 /**
  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 8.5.2015.
  */
-public class ThrottledNotificationsOffererImpl<T extends Notification> implements ThrottledNotificationsOfferer<T>, Runnable {
+public class ThrottledNotificationsOffererImpl implements ThrottledNotificationsOfferer, Runnable {
 
     private static final Logger LOG = LoggerFactory.getLogger(ThrottledNotificationsOffererImpl.class);
-    private final Map<Queue<T>, SettableFuture<Void>> throttledQueues = new ConcurrentHashMap<>();
+    private final Map<Queue<? extends Notification>, SettableFuture<Void>> throttledQueues = new ConcurrentHashMap<>();
     private final ThreadPoolLoggingExecutor throttleWorkerPool;
     private final NotificationPublishService notificationPublishService;
     private final MessageSpy messageIntelligenceAgency;
@@ -51,7 +51,7 @@ public class ThrottledNotificationsOffererImpl<T extends Notification> implement
     }
 
     @Override
-    public ListenableFuture<Void> applyThrottlingOnConnection(final Queue<T> notificationsQueue) {
+    public ListenableFuture<Void> applyThrottlingOnConnection(final Queue<? extends Notification> notificationsQueue) {
         SettableFuture<Void> throttleWatching = SettableFuture.create();
         throttledQueues.put(notificationsQueue, throttleWatching);
         synchronized (throttledQueues) {
@@ -77,9 +77,9 @@ public class ThrottledNotificationsOffererImpl<T extends Notification> implement
                     // NOOP
                 }
             } else {
-                for (Map.Entry<Queue<T>, SettableFuture<Void>> throttledTuple : throttledQueues.entrySet()) {
-                    Queue<T> key = throttledTuple.getKey();
-                    T notification = key.poll();
+                for (Map.Entry<Queue<? extends Notification>, SettableFuture<Void>> throttledTuple : throttledQueues.entrySet()) {
+                    Queue<? extends Notification> key = throttledTuple.getKey();
+                    Notification notification = key.poll();
                     if (notification == null) {
                         synchronized (key) {
                             // free throttling and announce via future
@@ -106,7 +106,7 @@ public class ThrottledNotificationsOffererImpl<T extends Notification> implement
     }
 
     @Override
-    public boolean isThrottlingEffective(final Queue<T> notificationsQueue) {
+    public boolean isThrottlingEffective(final Queue<? extends Notification> notificationsQueue) {
         return throttledQueues.containsKey(notificationsQueue);
     }
 
index ee2ea6daa34b0f21627c66e4823d20a4232312b7..57d876f1d3d3da75cd155216a85072090ee31dbc 100644 (file)
@@ -75,7 +75,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.MultipartReplyBody;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCase;
@@ -115,7 +114,7 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
     private DeviceInitializationPhaseHandler deviceInitPhaseHandler;
     private NotificationService notificationService;
     private NotificationPublishService notificationPublishService;
-    private ThrottledNotificationsOfferer<PacketInMessage> throttledNotificationsOfferer;
+    private ThrottledNotificationsOfferer throttledNotificationsOfferer;
 
     private final List<DeviceContext> deviceContexts = new ArrayList<DeviceContext>();
     private final MessageIntelligenceAgency messageIntelligenceAgency;
@@ -509,6 +508,6 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
         spyPool = new ScheduledThreadPoolExecutor(1);
         spyPool.scheduleAtFixedRate(messageIntelligenceAgency, spyRate, spyRate, TimeUnit.SECONDS);
 
-        throttledNotificationsOfferer = new ThrottledNotificationsOffererImpl<>(notificationPublishService, messageIntelligenceAgency);
+        throttledNotificationsOfferer = new ThrottledNotificationsOffererImpl(notificationPublishService, messageIntelligenceAgency);
     }
 }