Search in sources :

Example 21 with TbProtoQueueMsg

use of org.thingsboard.server.queue.common.TbProtoQueueMsg in project thingsboard by thingsboard.

the class DefaultTransportService method process.

@Override
public void process(TransportProtos.ValidateDeviceLwM2MCredentialsRequestMsg requestMsg, TransportServiceCallback<ValidateDeviceCredentialsResponse> callback) {
    log.trace("Processing msg: {}", requestMsg);
    TbProtoQueueMsg<TransportApiRequestMsg> protoMsg = new TbProtoQueueMsg<>(UUID.randomUUID(), TransportApiRequestMsg.newBuilder().setValidateDeviceLwM2MCredentialsRequestMsg(requestMsg).build());
    ListenableFuture<ValidateDeviceCredentialsResponse> response = Futures.transform(transportApiRequestTemplate.send(protoMsg), tmp -> {
        TransportProtos.ValidateDeviceCredentialsResponseMsg msg = tmp.getValue().getValidateCredResponseMsg();
        ValidateDeviceCredentialsResponse.ValidateDeviceCredentialsResponseBuilder result = ValidateDeviceCredentialsResponse.builder();
        if (msg.hasDeviceInfo()) {
            result.credentials(msg.getCredentialsBody());
            TransportDeviceInfo tdi = getTransportDeviceInfo(msg.getDeviceInfo());
            result.deviceInfo(tdi);
            ByteString profileBody = msg.getProfileBody();
            if (!profileBody.isEmpty()) {
                DeviceProfile profile = deviceProfileCache.getOrCreate(tdi.getDeviceProfileId(), profileBody);
                result.deviceProfile(profile);
            }
        }
        return result.build();
    }, MoreExecutors.directExecutor());
    AsyncCallbackTemplate.withCallback(response, callback::onSuccess, callback::onError, transportCallbackExecutor);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) TransportApiRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg) TransportDeviceInfo(org.thingsboard.server.common.transport.auth.TransportDeviceInfo) ByteString(com.google.protobuf.ByteString) TbProtoQueueMsg(org.thingsboard.server.queue.common.TbProtoQueueMsg) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) ValidateDeviceCredentialsResponse(org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse)

Aggregations

TbProtoQueueMsg (org.thingsboard.server.queue.common.TbProtoQueueMsg)21 UUID (java.util.UUID)9 ByteString (com.google.protobuf.ByteString)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 TopicPartitionInfo (org.thingsboard.server.common.msg.queue.TopicPartitionInfo)6 ToCoreNotificationMsg (org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)5 List (java.util.List)4 Optional (java.util.Optional)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 TimeUnit (java.util.concurrent.TimeUnit)4 PostConstruct (javax.annotation.PostConstruct)4 Slf4j (lombok.extern.slf4j.Slf4j)4 TbQueueConsumer (org.thingsboard.server.queue.TbQueueConsumer)4 ExecutorService (java.util.concurrent.ExecutorService)3 Executors (java.util.concurrent.Executors)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 PreDestroy (javax.annotation.PreDestroy)3 Value (org.springframework.beans.factory.annotation.Value)3