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;
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.",
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
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;
}
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;
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
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);
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;
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);
}