Search in sources :

Example 1 with FromDeviceRpcResponseActorMsg

use of org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg in project thingsboard by thingsboard.

the class DeviceEdgeProcessor method processDeviceRpcCallResponseFromEdge.

public ListenableFuture<Void> processDeviceRpcCallResponseFromEdge(TenantId tenantId, DeviceRpcCallMsg deviceRpcCallMsg) {
    log.trace("[{}] processDeviceRpcCallResponseMsg [{}]", tenantId, deviceRpcCallMsg);
    SettableFuture<Void> futureToSet = SettableFuture.create();
    UUID requestUuid = new UUID(deviceRpcCallMsg.getRequestUuidMSB(), deviceRpcCallMsg.getRequestUuidLSB());
    DeviceId deviceId = new DeviceId(new UUID(deviceRpcCallMsg.getDeviceIdMSB(), deviceRpcCallMsg.getDeviceIdLSB()));
    FromDeviceRpcResponse response;
    if (!StringUtils.isEmpty(deviceRpcCallMsg.getResponseMsg().getError())) {
        response = new FromDeviceRpcResponse(requestUuid, null, RpcError.valueOf(deviceRpcCallMsg.getResponseMsg().getError()));
    } else {
        response = new FromDeviceRpcResponse(requestUuid, deviceRpcCallMsg.getResponseMsg().getResponse(), null);
    }
    TbQueueCallback callback = new TbQueueCallback() {

        @Override
        public void onSuccess(TbQueueMsgMetadata metadata) {
            futureToSet.set(null);
        }

        @Override
        public void onFailure(Throwable t) {
            log.error("Can't process push notification to core [{}]", deviceRpcCallMsg, t);
            futureToSet.setException(t);
        }
    };
    FromDeviceRpcResponseActorMsg msg = new FromDeviceRpcResponseActorMsg(deviceRpcCallMsg.getRequestId(), tenantId, deviceId, response);
    tbClusterService.pushMsgToCore(msg, callback);
    return futureToSet;
}
Also used : FromDeviceRpcResponse(org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse) TbQueueCallback(org.thingsboard.server.queue.TbQueueCallback) DeviceId(org.thingsboard.server.common.data.id.DeviceId) TbQueueMsgMetadata(org.thingsboard.server.queue.TbQueueMsgMetadata) UUID(java.util.UUID) FromDeviceRpcResponseActorMsg(org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg)

Aggregations

UUID (java.util.UUID)1 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 FromDeviceRpcResponse (org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse)1 TbQueueCallback (org.thingsboard.server.queue.TbQueueCallback)1 TbQueueMsgMetadata (org.thingsboard.server.queue.TbQueueMsgMetadata)1 FromDeviceRpcResponseActorMsg (org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg)1