Merge pull request #79 from bsinno/optimize_simulator_throughput
Optimize simulator throughput
This commit is contained in:
@@ -62,8 +62,9 @@ public class DeviceSimulatorUpdater {
|
|||||||
device.setProgress(0.0);
|
device.setProgress(0.0);
|
||||||
device.setSwversion(swVersion);
|
device.setSwversion(swVersion);
|
||||||
eventbus.post(new InitUpdate(device));
|
eventbus.post(new InitUpdate(device));
|
||||||
|
|
||||||
threadPool.schedule(new DeviceSimulatorUpdateThread(device, spSenderService, actionId, eventbus, callback),
|
threadPool.schedule(new DeviceSimulatorUpdateThread(device, spSenderService, actionId, eventbus, callback),
|
||||||
2000, TimeUnit.MILLISECONDS);
|
2_000, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class DeviceSimulatorUpdateThread implements Runnable {
|
private static final class DeviceSimulatorUpdateThread implements Runnable {
|
||||||
@@ -91,7 +92,7 @@ public class DeviceSimulatorUpdater {
|
|||||||
if (newProgress < 1.0) {
|
if (newProgress < 1.0) {
|
||||||
threadPool.schedule(
|
threadPool.schedule(
|
||||||
new DeviceSimulatorUpdateThread(device, spSenderService, actionId, eventbus, callback),
|
new DeviceSimulatorUpdateThread(device, spSenderService, actionId, eventbus, callback),
|
||||||
rndSleep.nextInt(3000), TimeUnit.MILLISECONDS);
|
rndSleep.nextInt(5_000), TimeUnit.MILLISECONDS);
|
||||||
} else {
|
} else {
|
||||||
callback.updateFinished(device, actionId);
|
callback.updateFinished(device, actionId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,8 @@ import java.util.Map;
|
|||||||
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
|
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
|
||||||
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
|
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
|
||||||
import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
|
import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
|
||||||
import org.eclipse.hawkbit.dmf.json.model.ActionStatus;
|
|
||||||
import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest;
|
import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest;
|
||||||
import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice;
|
|
||||||
import org.eclipse.hawkbit.simulator.DeviceSimulatorUpdater;
|
import org.eclipse.hawkbit.simulator.DeviceSimulatorUpdater;
|
||||||
import org.eclipse.hawkbit.simulator.DeviceSimulatorUpdater.UpdaterCallback;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.core.Message;
|
||||||
@@ -139,31 +136,22 @@ public class SpReceiverService extends ReceiverService {
|
|||||||
DownloadAndUpdateRequest.class);
|
DownloadAndUpdateRequest.class);
|
||||||
final Long actionId = downloadAndUpdateRequest.getActionId();
|
final Long actionId = downloadAndUpdateRequest.getActionId();
|
||||||
|
|
||||||
try {
|
deviceUpdater.startUpdate(tenant, thingId, actionId,
|
||||||
Thread.sleep(1_000);
|
downloadAndUpdateRequest.getSoftwareModules().get(0).getModuleVersion(), (device, actionId1) -> {
|
||||||
} catch (final InterruptedException e) {
|
switch (device.getResponseStatus()) {
|
||||||
LOGGER.error("Sleep interrupted", e);
|
case SUCCESSFUL:
|
||||||
}
|
spSenderService.finishUpdateProcess(
|
||||||
|
new SimulatedUpdate(device.getTenant(), device.getId(), actionId1),
|
||||||
spSenderService.sendActionStatusMessage(tenant, ActionStatus.RUNNING,
|
"Simulation complete!");
|
||||||
"device Simulator retrieved update request. proceeding with simulation.", actionId);
|
break;
|
||||||
deviceUpdater.startUpdate(tenant, thingId, actionId, downloadAndUpdateRequest.getSoftwareModules().get(0)
|
case ERROR:
|
||||||
.getModuleVersion(), new UpdaterCallback() {
|
spSenderService.finishUpdateProcessWithError(
|
||||||
@Override
|
new SimulatedUpdate(device.getTenant(), device.getId(), actionId1),
|
||||||
public void updateFinished(final AbstractSimulatedDevice device, final Long actionId) {
|
"Simulation complete with error!");
|
||||||
switch (device.getResponseStatus()) {
|
break;
|
||||||
case SUCCESSFUL:
|
default:
|
||||||
spSenderService.finishUpdateProcess(new SimulatedUpdate(device.getTenant(), device.getId(),
|
break;
|
||||||
actionId), "Simulation complete!");
|
}
|
||||||
break;
|
});
|
||||||
case ERROR:
|
|
||||||
spSenderService.finishUpdateProcessWithError(new SimulatedUpdate(device.getTenant(),
|
|
||||||
device.getId(), actionId), "Simulation complete with error!");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user