import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.Timeout;
-import io.netty.util.TimerTask;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nonnull;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.openflowplugin.api.ConnectionException;
import org.opendaylight.openflowplugin.api.openflow.OFPContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.Timeout;
+import io.netty.util.TimerTask;
public class StatisticsManagerImpl implements StatisticsManager, StatisticsManagerControlService {
private final ConcurrentMap<DeviceInfo, StatisticsContext> contexts = new ConcurrentHashMap<>();
- private static final long basicTimerDelay = 3000;
- private static long currentTimerDelay = basicTimerDelay;
- private static final long maximumTimerDelay = 900000; //wait max 15 minutes for next statistics
+ private static long basicTimerDelay;
+ private static long currentTimerDelay;
+ private static long maximumTimerDelay; //wait time for next statistics
private StatisticsWorkMode workMode = StatisticsWorkMode.COLLECTALL;
private final Semaphore workModeGuard = new Semaphore(1, true);
public StatisticsManagerImpl(final RpcProviderRegistry rpcProviderRegistry,
final boolean isStatisticsPollingOn,
final HashedWheelTimer hashedWheelTimer,
- final ConvertorExecutor convertorExecutor) {
+ final ConvertorExecutor convertorExecutor,
+ final long basicTimerDelay,
+ final long maximumTimerDelay) {
Preconditions.checkArgument(rpcProviderRegistry != null);
this.converterExecutor = convertorExecutor;
this.controlServiceRegistration = Preconditions.checkNotNull(
rpcProviderRegistry.addRpcImplementation(StatisticsManagerControlService.class, this)
);
this.isStatisticsPollingOn = isStatisticsPollingOn;
+ this.basicTimerDelay = basicTimerDelay;
+ this.currentTimerDelay = basicTimerDelay;
+ this.maximumTimerDelay = maximumTimerDelay;
this.hashedWheelTimer = hashedWheelTimer;
}
LOG.trace("Gathering for node {} failure: ", deviceInfo.getLOGValue(), throwable);
}
calculateTimerDelay(timeCounter);
- if (throwable instanceof IllegalStateException) {
+ if (throwable instanceof ConnectionException) {
+ // ConnectionException is raised by StatisticsContextImpl class when the connections
+ // move to RIP state. In this particular case, there is no need to reschedule
+ // because this statistics manager should be closed soon
+ LOG.warn("Node {} is no more connected, stopping the statistics collection",
+ deviceInfo.getLOGValue(),throwable);
stopScheduling(deviceInfo);
} else {
+ LOG.warn("Unexpected error occurred during statistics collection for node {}, rescheduling " +
+ "statistics collections", deviceInfo.getLOGValue(),throwable);
scheduleNextPolling(deviceState, deviceInfo, statisticsContext, timeCounter);
}
}
contexts.remove(deviceInfo);
LOG.debug("Statistics context removed for node {}", deviceInfo.getLOGValue());
}
+
+ @Override
+ public void setBasicTimerDelay(final long basicTimerDelay) {
+ this.basicTimerDelay = basicTimerDelay;
+ }
+
+ @Override
+ public void setMaximumTimerDelay(final long maximumTimerDelay) {
+ this.maximumTimerDelay = maximumTimerDelay;
+ }
}