Fix race condition - if the device manager is not ready when a packet arrives, drop it rather than NPE

Change-Id: I601b4ce1d449b169059a3390441dcfa58b800db3
This commit is contained in:
Ray Milkey 2017-11-16 16:46:04 -08:00 committed by Thomas Vachuska
parent 0b80972fa9
commit 2c142c5248
2 changed files with 5 additions and 1 deletions

View File

@ -61,6 +61,10 @@ public class PacketDriverProvider extends AbstractProvider implements PacketProv
}
private PacketProgrammable getPacketProgrammable(DeviceId deviceId) {
if (deviceService == null) {
log.debug("Packet encountered but device service is not ready, dropping");
return null;
}
Device device = deviceService.getDevice(deviceId);
if (device.is(PacketProgrammable.class)) {
return device.as(PacketProgrammable.class);

View File

@ -130,8 +130,8 @@ public class PacketManager
appId = coreService.getAppId(CoreService.CORE_APP_NAME);
store.setDelegate(delegate);
deviceService.addListener(deviceListener);
store.existingRequests().forEach(this::pushToAllDevices);
defaultProvider.init(deviceService);
store.existingRequests().forEach(this::pushToAllDevices);
log.info("Started");
}