WIP: Bump upstreams
[openflowplugin.git] / test-common / src / main / java / org / opendaylight / openflowplugin / testcommon / DropTestRpcSender.java
index fac568b683802cb7fa32f504ba4b6a76d72c0579..8906f8bf38a89a18b230fd68b404aac519e4f480 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -9,12 +9,9 @@ package org.opendaylight.openflowplugin.testcommon;
 
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
-import java.math.BigInteger;
 import org.opendaylight.mdsal.binding.api.NotificationService;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
@@ -25,9 +22,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.I
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,49 +36,32 @@ import org.slf4j.LoggerFactory;
  */
 public class DropTestRpcSender extends AbstractDropTest {
     private static final Logger LOG = LoggerFactory.getLogger(DropTestRpcSender.class);
+    private static final ThreadLocal<AddFlowInputBuilder> BUILDER = ThreadLocal.withInitial(() -> {
+        final var cookie = new FlowCookie(Uint64.TEN);
+        return new AddFlowInputBuilder()
+            .setPriority(PRIORITY)
+            .setBufferId(BUFFER_ID)
+            .setCookie(cookie)
+            .setCookieMask(cookie)
+            .setTableId(TABLE_ID)
+            .setHardTimeout(HARD_TIMEOUT)
+            .setIdleTimeout(IDLE_TIMEOUT)
+            .setFlags(new FlowModFlags(false, false, false, false, false));
+    });
 
-    private SalFlowService flowService;
+    private NotificationService notificationService = null;
+    private Registration notificationRegistration = null;
+    private SalFlowService flowService = null;
 
     public void setFlowService(final SalFlowService flowService) {
         this.flowService = flowService;
     }
 
-    private static final ThreadLocal<AddFlowInputBuilder> BUILDER = ThreadLocal.withInitial(() -> {
-        final AddFlowInputBuilder fb = new AddFlowInputBuilder();
-
-        fb.setPriority(PRIORITY);
-        fb.setBufferId(BUFFER_ID);
-
-        final FlowCookie cookie = new FlowCookie(BigInteger.TEN);
-        fb.setCookie(cookie);
-        fb.setCookieMask(cookie);
-        fb.setTableId(TABLE_ID);
-        fb.setHardTimeout(HARD_TIMEOUT);
-        fb.setIdleTimeout(IDLE_TIMEOUT);
-        fb.setFlags(new FlowModFlags(false, false, false, false, false));
-
-        return fb;
-    });
-
-    private NotificationService notificationService;
-
-    private ListenerRegistration<DropTestRpcSender> notificationRegistration;
-
     /**
      * Start listening on packetIn.
      */
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void start() {
-        final SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK,
-                STARTUP_LOOP_MAX_RETRIES);
-        try {
-            notificationRegistration = looper.loopUntilNoException(
-                () -> notificationService.registerNotificationListener(DropTestRpcSender.this));
-        } catch (Exception e) {
-            LOG.warn("DropTest sender notification listener registration fail!");
-            LOG.debug("DropTest sender notification listener registration fail! ..", e);
-            throw new IllegalStateException("DropTest startup fail! Try again later.", e);
-        }
+        notificationRegistration = notificationService.registerListener(PacketReceived.class, this);
     }
 
     @Override
@@ -97,11 +79,8 @@ public class DropTestRpcSender extends AbstractDropTest {
 
         // Add flow
         final AddFlowInput flow = fb.build();
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("onPacketReceived - About to write flow (via SalFlowService) {}", flow);
-        }
-        ListenableFuture<RpcResult<AddFlowOutput>> result =
-                JdkFutureAdapters.listenInPoolThread(flowService.addFlow(flow));
+        LOG.debug("onPacketReceived - About to write flow (via SalFlowService) {}", flow);
+        ListenableFuture<RpcResult<AddFlowOutput>> result = flowService.addFlow(flow);
         Futures.addCallback(result, new FutureCallback<RpcResult<AddFlowOutput>>() {
             @Override
             public void onSuccess(final RpcResult<AddFlowOutput> result) {
@@ -120,17 +99,11 @@ public class DropTestRpcSender extends AbstractDropTest {
     }
 
     @Override
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void close() {
         super.close();
-        try {
-            LOG.debug("DropTestProvider stopped.");
-            if (notificationRegistration != null) {
-                notificationRegistration.close();
-            }
-        } catch (RuntimeException e) {
-            LOG.warn("unregistration of notification listener failed: {}", e.getMessage());
-            LOG.debug("unregistration of notification listener failed.. ", e);
+        LOG.debug("DropTestProvider stopped.");
+        if (notificationRegistration != null) {
+            notificationRegistration.close();
         }
     }
 }