Search in sources :

Example 1 with DeviceTransportType

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);
            }
        }
    }
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceSessionContext(org.thingsboard.server.transport.snmp.session.DeviceSessionContext) DeviceTransportType(org.thingsboard.server.common.data.DeviceTransportType) EventListener(org.springframework.context.event.EventListener)

Aggregations

EventListener (org.springframework.context.event.EventListener)1 Device (org.thingsboard.server.common.data.Device)1 DeviceTransportType (org.thingsboard.server.common.data.DeviceTransportType)1 DeviceSessionContext (org.thingsboard.server.transport.snmp.session.DeviceSessionContext)1