|
|
|
@ -58,6 +58,9 @@ import org.thingsboard.server.service.queue.TbClusterService; |
|
|
|
import org.thingsboard.server.service.state.DeviceStateService; |
|
|
|
|
|
|
|
import java.util.UUID; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentMap; |
|
|
|
import java.util.concurrent.locks.Lock; |
|
|
|
import java.util.concurrent.locks.ReentrantLock; |
|
|
|
|
|
|
|
/** |
|
|
|
@ -92,7 +95,7 @@ public class DefaultTransportApiService implements TransportApiService { |
|
|
|
@Autowired |
|
|
|
protected TbClusterService tbClusterService; |
|
|
|
|
|
|
|
private ReentrantLock deviceCreationLock = new ReentrantLock(); |
|
|
|
private final ConcurrentMap<String, ReentrantLock> deviceCreationLocks = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
@Override |
|
|
|
public ListenableFuture<TbProtoQueueMsg<TransportApiResponseMsg>> handle(TbProtoQueueMsg<TransportApiRequestMsg> tbProtoQueueMsg) { |
|
|
|
@ -125,6 +128,7 @@ public class DefaultTransportApiService implements TransportApiService { |
|
|
|
DeviceId gatewayId = new DeviceId(new UUID(requestMsg.getGatewayIdMSB(), requestMsg.getGatewayIdLSB())); |
|
|
|
ListenableFuture<Device> gatewayFuture = deviceService.findDeviceByIdAsync(TenantId.SYS_TENANT_ID, gatewayId); |
|
|
|
return Futures.transform(gatewayFuture, gateway -> { |
|
|
|
Lock deviceCreationLock = deviceCreationLocks.computeIfAbsent(requestMsg.getDeviceName(), id -> new ReentrantLock()); |
|
|
|
deviceCreationLock.lock(); |
|
|
|
try { |
|
|
|
Device device = deviceService.findDeviceByTenantIdAndName(gateway.getTenantId(), requestMsg.getDeviceName()); |
|
|
|
|