use of org.thingsboard.server.common.data.DeviceTransportType in project thingsboard by thingsboard.
the class SnmpTransportContext method onDeviceUpdatedOrCreated.
@EventListener(DeviceUpdatedEvent.class)
public void onDeviceUpdatedOrCreated(DeviceUpdatedEvent deviceUpdatedEvent) {
Device device = deviceUpdatedEvent.getDevice();
log.trace("Got creating or updating device event for device {}", device);
DeviceTransportType transportType = Optional.ofNullable(device.getDeviceData().getTransportConfiguration()).map(DeviceTransportConfiguration::getType).orElse(null);
if (!allSnmpDevicesIds.contains(device.getId())) {
if (transportType != DeviceTransportType.SNMP) {
return;
}
allSnmpDevicesIds.add(device.getId());
if (balancingService.isManagedByCurrentTransport(device.getId().getId())) {
establishDeviceSession(device);
}
} else {
if (balancingService.isManagedByCurrentTransport(device.getId().getId())) {
DeviceSessionContext sessionContext = sessions.get(device.getId());
if (transportType == DeviceTransportType.SNMP) {
if (sessionContext != null) {
updateDeviceSession(sessionContext, device, deviceProfileCache.get(device.getDeviceProfileId()));
} else {
establishDeviceSession(device);
}
} else {
log.trace("Transport type was changed to {}", transportType);
destroyDeviceSession(sessionContext);
}
}
}
}
Aggregations