don't generate amqp devices at startup if amqp is disabled

Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
Michael Hirsch
2016-08-15 15:33:18 +02:00
parent 9d54aa8c34
commit 7164b33e94

View File

@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.simulator;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import org.eclipse.hawkbit.simulator.amqp.SpSenderService; import org.eclipse.hawkbit.simulator.amqp.AmqpProperties;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -32,24 +32,27 @@ public class SimulatorStartup implements ApplicationListener<ContextRefreshedEve
@Autowired @Autowired
private SimulationProperties simulationProperties; private SimulationProperties simulationProperties;
@Autowired
private SpSenderService spSenderService;
@Autowired @Autowired
private DeviceSimulatorRepository repository; private DeviceSimulatorRepository repository;
@Autowired @Autowired
private SimulatedDeviceFactory deviceFactory; private SimulatedDeviceFactory deviceFactory;
@Autowired
private AmqpProperties amqpProperties;
@Override @Override
public void onApplicationEvent(final ContextRefreshedEvent event) { public void onApplicationEvent(final ContextRefreshedEvent event) {
simulationProperties.getAutostarts().forEach(autostart -> { simulationProperties.getAutostarts().forEach(autostart -> {
for (int i = 0; i < autostart.getAmount(); i++) { for (int i = 0; i < autostart.getAmount(); i++) {
final String deviceId = autostart.getName() + i; final String deviceId = autostart.getName() + i;
try { try {
if (amqpProperties.isEnabled()) {
repository.add(deviceFactory.createSimulatedDevice(deviceId, autostart.getTenant(), repository.add(deviceFactory.createSimulatedDevice(deviceId, autostart.getTenant(),
autostart.getApi(), autostart.getPollDelay(), new URL(autostart.getEndpoint()), autostart.getApi(), autostart.getPollDelay(), new URL(autostart.getEndpoint()),
autostart.getGatewayToken())); autostart.getGatewayToken()));
}
} catch (final MalformedURLException e) { } catch (final MalformedURLException e) {
LOGGER.error("Creation of simulated device at startup failed.", e); LOGGER.error("Creation of simulated device at startup failed.", e);
} }