Search in sources :

Example 1 with SnmpTransportListChangedEvent

use of org.thingsboard.server.transport.snmp.event.SnmpTransportListChangedEvent in project thingsboard by thingsboard.

the class SnmpTransportBalancingService method recalculatePartitions.

private void recalculatePartitions(List<ServiceInfo> otherServices, ServiceInfo currentService) {
    log.info("Recalculating partitions for SNMP transports");
    List<ServiceInfo> snmpTransports = Stream.concat(otherServices.stream(), Stream.of(currentService)).filter(service -> service.getTransportsList().contains(snmpTransportService.getName())).sorted(Comparator.comparing(ServiceInfo::getServiceId)).collect(Collectors.toList());
    log.trace("Found SNMP transports: {}", snmpTransports);
    int previousCurrentTransportPartitionIndex = currentTransportPartitionIndex;
    int previousSnmpTransportsCount = snmpTransportsCount;
    if (!snmpTransports.isEmpty()) {
        for (int i = 0; i < snmpTransports.size(); i++) {
            if (snmpTransports.get(i).equals(currentService)) {
                currentTransportPartitionIndex = i;
                break;
            }
        }
        snmpTransportsCount = snmpTransports.size();
    }
    if (snmpTransportsCount != previousSnmpTransportsCount || currentTransportPartitionIndex != previousCurrentTransportPartitionIndex) {
        log.info("SNMP transports partitions have changed: transports count = {}, current transport partition index = {}", snmpTransportsCount, currentTransportPartitionIndex);
        eventPublisher.publishEvent(new SnmpTransportListChangedEvent());
    } else {
        log.info("SNMP transports partitions have not changed");
    }
}
Also used : ServiceInfo(org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo) SnmpTransportListChangedEvent(org.thingsboard.server.transport.snmp.event.SnmpTransportListChangedEvent)

Aggregations

ServiceInfo (org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo)1 SnmpTransportListChangedEvent (org.thingsboard.server.transport.snmp.event.SnmpTransportListChangedEvent)1