Search in sources :

Example 1 with AfterStartUp

use of org.thingsboard.server.queue.util.AfterStartUp in project thingsboard by thingsboard.

the class SnmpTransportContext method fetchDevicesAndEstablishSessions.

@AfterStartUp(order = Integer.MAX_VALUE)
public void fetchDevicesAndEstablishSessions() {
    log.info("Initializing SNMP devices sessions");
    int batchIndex = 0;
    int batchSize = 512;
    boolean nextBatchExists = true;
    while (nextBatchExists) {
        TransportProtos.GetSnmpDevicesResponseMsg snmpDevicesResponse = protoEntityService.getSnmpDevicesIds(batchIndex, batchSize);
        snmpDevicesResponse.getIdsList().stream().map(id -> new DeviceId(UUID.fromString(id))).peek(allSnmpDevicesIds::add).filter(deviceId -> balancingService.isManagedByCurrentTransport(deviceId.getId())).map(protoEntityService::getDeviceById).forEach(device -> getExecutor().execute(() -> establishDeviceSession(device)));
        nextBatchExists = snmpDevicesResponse.getHasNextPage();
        batchIndex++;
    }
    log.debug("Found all SNMP devices ids: {}", allSnmpDevicesIds);
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) AfterStartUp(org.thingsboard.server.queue.util.AfterStartUp)

Aggregations

DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)1 AfterStartUp (org.thingsboard.server.queue.util.AfterStartUp)1