Search in sources :

Example 1 with TbLwM2MLatchCallback

use of org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MLatchCallback in project thingsboard by thingsboard.

the class DefaultLwM2mUplinkMsgHandler method sendObserveRequests.

private void sendObserveRequests(LwM2mClient lwM2MClient, Lwm2mDeviceProfileTransportConfiguration profile, Set<String> supportedObjects) {
    try {
        Set<String> targetIds = profile.getObserveAttr().getObserve();
        targetIds = targetIds.stream().filter(target -> isSupportedTargetId(supportedObjects, target)).collect(Collectors.toSet());
        CountDownLatch latch = new CountDownLatch(targetIds.size());
        targetIds.forEach(targetId -> sendObserveRequest(lwM2MClient, targetId, new TbLwM2MLatchCallback<>(latch, new TbLwM2MObserveCallback(this, logService, lwM2MClient, targetId))));
        latch.await();
    } catch (InterruptedException e) {
        log.error("[{}] Failed to await Observe requests!", lwM2MClient.getEndpoint(), e);
    } catch (Exception e) {
        log.error("[{}] Failed to process observe requests!", lwM2MClient.getEndpoint(), e);
        logService.log(lwM2MClient, "Failed to process observe requests. Possible profile misconfiguration.");
    }
}
Also used : TbLwM2MLatchCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MLatchCallback) TbLwM2MObserveCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveCallback) LwM2MTransportUtil.convertOtaUpdateValueToString(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertOtaUpdateValueToString) CountDownLatch(java.util.concurrent.CountDownLatch) LwM2MClientStateException(org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException)

Example 2 with TbLwM2MLatchCallback

use of org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MLatchCallback in project thingsboard by thingsboard.

the class DefaultLwM2mUplinkMsgHandler method sendReadRequests.

private void sendReadRequests(LwM2mClient lwM2MClient, Lwm2mDeviceProfileTransportConfiguration profile, Set<String> supportedObjects) {
    try {
        Set<String> targetIds = new HashSet<>(profile.getObserveAttr().getAttribute());
        targetIds.addAll(profile.getObserveAttr().getTelemetry());
        targetIds = diffSets(profile.getObserveAttr().getObserve(), targetIds);
        targetIds = targetIds.stream().filter(target -> isSupportedTargetId(supportedObjects, target)).collect(Collectors.toSet());
        CountDownLatch latch = new CountDownLatch(targetIds.size());
        targetIds.forEach(versionedId -> sendReadRequest(lwM2MClient, versionedId, new TbLwM2MLatchCallback<>(latch, new TbLwM2MReadCallback(this, logService, lwM2MClient, versionedId))));
        latch.await();
    } catch (InterruptedException e) {
        log.error("[{}] Failed to await Read requests!", lwM2MClient.getEndpoint(), e);
    } catch (Exception e) {
        log.error("[{}] Failed to process read requests!", lwM2MClient.getEndpoint(), e);
        logService.log(lwM2MClient, "Failed to process read requests. Possible profile misconfiguration.");
    }
}
Also used : TbLwM2MLatchCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MLatchCallback) TbLwM2MReadCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback) LwM2MTransportUtil.convertOtaUpdateValueToString(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertOtaUpdateValueToString) CountDownLatch(java.util.concurrent.CountDownLatch) LwM2MClientStateException(org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException) HashSet(java.util.HashSet)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)2 LwM2MClientStateException (org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException)2 TbLwM2MLatchCallback (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MLatchCallback)2 LwM2MTransportUtil.convertOtaUpdateValueToString (org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertOtaUpdateValueToString)2 HashSet (java.util.HashSet)1 TbLwM2MObserveCallback (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveCallback)1 TbLwM2MReadCallback (org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback)1