OPNFLWPLUG-1073 : Using ofppool executor for role change service request callbacks 46/82546/6
authorSomashekhar Javalagi <somashekhar.manohara.javalagi@ericsson.com>
Tue, 18 Jun 2019 11:51:49 +0000 (17:21 +0530)
committerSomashekhar Javalagi <somashekhar.manohara.javalagi@ericsson.com>
Mon, 8 Jul 2019 10:57:27 +0000 (16:27 +0530)
Change-Id: I79d24d1d12484e9859968fa3ab6e1b7f79f4e18d
Signed-off-by: Somashekhar Javalagi <somashekhar.manohara.javalagi@ericsson.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleContextImplTest.java

index 9367ebba4c63e5126c22082a67e710ac072cbb08..a5432a176cb4bc3acac8824aa1fb45c1bbde6675 100644 (file)
@@ -268,7 +268,7 @@ public class OpenFlowPluginProviderImpl implements
                 convertorManager,
                 executorService);
 
-        roleManager = new RoleManagerImpl(hashedWheelTimer, config);
+        roleManager = new RoleManagerImpl(hashedWheelTimer, config, executorService);
 
         contextChainHolder = new ContextChainHolderImpl(
                 executorService,
index 4e5ea5ad8a2501a398c35c432c70e737458038f1..7bebbd5fa3bef2f21f476f6202e8d5ec4d60a68c 100644 (file)
@@ -10,14 +10,13 @@ package org.opendaylight.openflowplugin.impl.role;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.MoreExecutors;
 import io.netty.util.HashedWheelTimer;
 import io.netty.util.Timeout;
 import io.netty.util.TimerTask;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.concurrent.CancellationException;
-import java.util.concurrent.Executors;
+import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 import javax.annotation.Nonnull;
@@ -54,16 +53,19 @@ public class RoleContextImpl implements RoleContext {
     private final Collection<RequestContext<?>> requestContexts = new HashSet<>();
     private final Timeout slaveTask;
     private final OpenflowProviderConfig config;
+    private final ExecutorService executorService;
     private ContextChainMastershipWatcher contextChainMastershipWatcher;
     private SalRoleService roleService;
 
     RoleContextImpl(@Nonnull final DeviceInfo deviceInfo,
                     @Nonnull final HashedWheelTimer timer,
                     final long checkRoleMasterTimeout,
-                    final OpenflowProviderConfig config) {
+                    final OpenflowProviderConfig config,
+                    final ExecutorService executorService) {
         this.deviceInfo = deviceInfo;
         this.timer = timer;
         this.config = config;
+        this.executorService = executorService;
         slaveTask = timer.newTimeout((timerTask) -> makeDeviceSlave(), checkRoleMasterTimeout, TimeUnit.MILLISECONDS);
 
         LOG.info("Started timer for setting SLAVE role on device {} if no role will be set in {}s.",
@@ -98,7 +100,7 @@ public class RoleContextImpl implements RoleContext {
     public void instantiateServiceInstance() {
         final ListenableFuture<RpcResult<SetRoleOutput>> future = sendRoleChangeToDevice(OfpRole.BECOMEMASTER);
         changeLastRoleFuture(future);
-        Futures.addCallback(future, new MasterRoleCallback(), Executors.newSingleThreadExecutor());
+        Futures.addCallback(future, new MasterRoleCallback(), executorService);
     }
 
     @Override
@@ -140,7 +142,7 @@ public class RoleContextImpl implements RoleContext {
     private ListenableFuture<RpcResult<SetRoleOutput>> makeDeviceSlave() {
         final ListenableFuture<RpcResult<SetRoleOutput>> future = sendRoleChangeToDevice(OfpRole.BECOMESLAVE);
         changeLastRoleFuture(future);
-        Futures.addCallback(future, new SlaveRoleCallback(), MoreExecutors.directExecutor());
+        Futures.addCallback(future, new SlaveRoleCallback(), executorService);
         return future;
     }
 
index c6dbd42aec55ce2debdf045eefc56eb54e1e616a..2f2eba2edc32f741eff163ffb1c96dc6c1c09797 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.openflowplugin.impl.role;
 import io.netty.util.HashedWheelTimer;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutorService;
 import javax.annotation.Nonnull;
 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
@@ -27,11 +28,14 @@ public class RoleManagerImpl implements RoleManager {
     private final ConcurrentMap<DeviceInfo, RoleContext> contexts = new ConcurrentHashMap<>();
     private final HashedWheelTimer timer;
     private final OpenflowProviderConfig config;
+    private final ExecutorService executorService;
 
     public RoleManagerImpl(final HashedWheelTimer timer,
-                           final OpenflowProviderConfig config) {
+                           final OpenflowProviderConfig config,
+                           final ExecutorService executorService) {
         this.timer = timer;
         this.config = config;
+        this.executorService = executorService;
     }
 
     @Override
@@ -39,7 +43,7 @@ public class RoleManagerImpl implements RoleManager {
         final DeviceInfo deviceInfo = deviceContext.getDeviceInfo();
         final RoleContextImpl roleContext = new RoleContextImpl(
                 deviceContext.getDeviceInfo(),
-                timer, CHECK_ROLE_MASTER_TIMEOUT, config);
+                timer, CHECK_ROLE_MASTER_TIMEOUT, config, executorService);
 
         roleContext.setRoleService(new SalRoleServiceImpl(roleContext, deviceContext));
         contexts.put(deviceInfo, roleContext);
index 4918f910c3f9335511bdb279d9fa5234bfbfbc07..7818bf9eddea147176a070ba8371f3b2e72e6a67 100644 (file)
@@ -16,6 +16,7 @@ import static org.mockito.Mockito.when;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import io.netty.util.HashedWheelTimer;
+import java.util.concurrent.Executors;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -63,7 +64,8 @@ public class RoleContextImplTest {
         when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
         when(roleService.setRole(any())).thenReturn(Futures.immediateFuture(null));
 
-        roleContext = new RoleContextImpl(deviceInfo, new HashedWheelTimer(), 20000, config);
+        roleContext = new RoleContextImpl(deviceInfo, new HashedWheelTimer(), 20000, config,
+                Executors.newSingleThreadExecutor());
         roleContext.registerMastershipWatcher(contextChainMastershipWatcher);
         roleContext.setRoleService(roleService);
     }