|
|
|
@ -23,7 +23,6 @@ import com.google.common.util.concurrent.FutureCallback; |
|
|
|
import com.google.common.util.concurrent.Futures; |
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.google.gson.JsonArray; |
|
|
|
import com.google.gson.JsonObject; |
|
|
|
import com.google.gson.JsonParser; |
|
|
|
import org.thingsboard.server.actors.ActorSystemContext; |
|
|
|
@ -47,7 +46,7 @@ import org.thingsboard.server.common.msg.core.AttributesUpdateRequest; |
|
|
|
import org.thingsboard.server.common.msg.core.BasicCommandAckResponse; |
|
|
|
import org.thingsboard.server.common.msg.core.BasicGetAttributesResponse; |
|
|
|
import org.thingsboard.server.common.msg.core.BasicStatusCodeResponse; |
|
|
|
import org.thingsboard.server.common.msg.core.BasicToDeviceSessionActorMsg; |
|
|
|
import org.thingsboard.server.common.msg.core.BasicActorSystemToDeviceSessionActorMsg; |
|
|
|
import org.thingsboard.server.common.msg.core.GetAttributesRequest; |
|
|
|
import org.thingsboard.server.common.msg.core.RuleEngineError; |
|
|
|
import org.thingsboard.server.common.msg.core.RuleEngineErrorMsg; |
|
|
|
@ -57,13 +56,12 @@ import org.thingsboard.server.common.msg.core.SessionOpenMsg; |
|
|
|
import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; |
|
|
|
import org.thingsboard.server.common.msg.core.ToDeviceRpcRequestMsg; |
|
|
|
import org.thingsboard.server.common.msg.core.ToDeviceRpcResponseMsg; |
|
|
|
import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; |
|
|
|
import org.thingsboard.server.common.msg.core.ActorSystemToDeviceSessionActorMsg; |
|
|
|
import org.thingsboard.server.common.msg.core.ToServerRpcRequestMsg; |
|
|
|
import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
|
|
|
import org.thingsboard.server.common.msg.kv.BasicAttributeKVMsg; |
|
|
|
import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
|
|
|
import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
|
|
|
import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
|
|
|
import org.thingsboard.server.common.msg.session.SessionMsgType; |
|
|
|
import org.thingsboard.server.common.msg.session.SessionType; |
|
|
|
import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
|
|
|
@ -74,7 +72,6 @@ import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotific |
|
|
|
import org.thingsboard.server.extensions.api.device.DeviceNameOrTypeUpdateMsg; |
|
|
|
import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
|
|
|
import org.thingsboard.server.extensions.api.plugins.msg.RpcError; |
|
|
|
import org.thingsboard.server.gen.cluster.ClusterAPIProtos; |
|
|
|
import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg; |
|
|
|
import org.thingsboard.server.service.rpc.ToServerRpcResponseActorMsg; |
|
|
|
|
|
|
|
@ -156,7 +153,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
|
|
|
boolean sent = rpcSubscriptions.size() > 0; |
|
|
|
Set<SessionId> syncSessionSet = new HashSet<>(); |
|
|
|
rpcSubscriptions.entrySet().forEach(sub -> { |
|
|
|
ToDeviceSessionActorMsg response = new BasicToDeviceSessionActorMsg(rpcRequest, sub.getKey()); |
|
|
|
ActorSystemToDeviceSessionActorMsg response = new BasicActorSystemToDeviceSessionActorMsg(rpcRequest, sub.getKey()); |
|
|
|
sendMsgToSessionActor(response, sub.getValue().getServer()); |
|
|
|
if (SessionType.SYNC == sub.getValue().getType()) { |
|
|
|
syncSessionSet.add(sub.getKey()); |
|
|
|
@ -198,7 +195,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
|
|
|
if (data != null) { |
|
|
|
logger.debug("[{}] Queue put [{}] timeout detected!", deviceId, msg.getId()); |
|
|
|
ToDeviceMsg toDeviceMsg = new RuleEngineErrorMsg(data.getSessionMsgType(), RuleEngineError.QUEUE_PUT_TIMEOUT); |
|
|
|
sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(toDeviceMsg, data.getSessionId()), data.getServerAddress()); |
|
|
|
sendMsgToSessionActor(new BasicActorSystemToDeviceSessionActorMsg(toDeviceMsg, data.getSessionId()), data.getServerAddress()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -210,7 +207,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
|
|
|
logger.debug("[{}] Queue put [{}] ack detected. Remaining acks: {}!", deviceId, msg.getId(), remainingAcks); |
|
|
|
if (remainingAcks == 0) { |
|
|
|
ToDeviceMsg toDeviceMsg = BasicStatusCodeResponse.onSuccess(data.getSessionMsgType(), data.getRequestId()); |
|
|
|
sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(toDeviceMsg, data.getSessionId()), data.getServerAddress()); |
|
|
|
sendMsgToSessionActor(new BasicActorSystemToDeviceSessionActorMsg(toDeviceMsg, data.getSessionId()), data.getServerAddress()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -248,7 +245,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
|
|
|
body.getMethod(), |
|
|
|
body.getParams() |
|
|
|
); |
|
|
|
ToDeviceSessionActorMsg response = new BasicToDeviceSessionActorMsg(rpcRequest, sessionId); |
|
|
|
ActorSystemToDeviceSessionActorMsg response = new BasicActorSystemToDeviceSessionActorMsg(rpcRequest, sessionId); |
|
|
|
sendMsgToSessionActor(response, server); |
|
|
|
}; |
|
|
|
} |
|
|
|
@ -302,14 +299,14 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
|
|
|
public void onSuccess(@Nullable List<List<AttributeKvEntry>> result) { |
|
|
|
BasicGetAttributesResponse response = BasicGetAttributesResponse.onSuccess(request.getMsgType(), |
|
|
|
request.getRequestId(), BasicAttributeKVMsg.from(result.get(0), result.get(1))); |
|
|
|
sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(response, src.getSessionId()), src.getServerAddress()); |
|
|
|
sendMsgToSessionActor(new BasicActorSystemToDeviceSessionActorMsg(response, src.getSessionId()), src.getServerAddress()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Throwable t) { |
|
|
|
if (t instanceof Exception) { |
|
|
|
ToDeviceMsg toDeviceMsg = BasicStatusCodeResponse.onError(SessionMsgType.GET_ATTRIBUTES_REQUEST, request.getRequestId(), (Exception) t); |
|
|
|
sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(toDeviceMsg, src.getSessionId()), src.getServerAddress()); |
|
|
|
sendMsgToSessionActor(new BasicActorSystemToDeviceSessionActorMsg(toDeviceMsg, src.getSessionId()), src.getServerAddress()); |
|
|
|
} else { |
|
|
|
logger.error("[{}] Failed to process attributes request", deviceId, t); |
|
|
|
} |
|
|
|
@ -391,14 +388,14 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
|
|
|
if (data != null) { |
|
|
|
logger.debug("[{}] Client side RPC request [{}] timeout detected!", deviceId, msg.getId()); |
|
|
|
ToDeviceMsg toDeviceMsg = new RuleEngineErrorMsg(SessionMsgType.TO_SERVER_RPC_REQUEST, RuleEngineError.TIMEOUT); |
|
|
|
sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(toDeviceMsg, data.getSessionId()), data.getServer()); |
|
|
|
sendMsgToSessionActor(new BasicActorSystemToDeviceSessionActorMsg(toDeviceMsg, data.getSessionId()), data.getServer()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void processToServerRPCResponse(ActorContext context, ToServerRpcResponseActorMsg msg) { |
|
|
|
ToServerRpcRequestMetadata data = toServerRpcPendingMap.remove(msg.getMsg().getRequestId()); |
|
|
|
if (data != null) { |
|
|
|
sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(msg.getMsg(), data.getSessionId()), data.getServer()); |
|
|
|
sendMsgToSessionActor(new BasicActorSystemToDeviceSessionActorMsg(msg.getMsg(), data.getSessionId()), data.getServer()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -409,7 +406,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
|
|
|
pendingMsgs.put(tbMsg.getId(), pendingMsgData); |
|
|
|
scheduleMsgWithDelay(context, new DeviceActorQueueTimeoutMsg(tbMsg.getId(), systemContext.getQueuePersistenceTimeout()), systemContext.getQueuePersistenceTimeout()); |
|
|
|
} else { |
|
|
|
ToDeviceSessionActorMsg response = new BasicToDeviceSessionActorMsg(BasicStatusCodeResponse.onSuccess(sessionMsgType, requestId), pendingMsgData.getSessionId()); |
|
|
|
ActorSystemToDeviceSessionActorMsg response = new BasicActorSystemToDeviceSessionActorMsg(BasicStatusCodeResponse.onSuccess(sessionMsgType, requestId), pendingMsgData.getSessionId()); |
|
|
|
sendMsgToSessionActor(response, pendingMsgData.getServerAddress()); |
|
|
|
} |
|
|
|
context.parent().tell(new DeviceActorToRuleEngineMsg(context.self(), tbMsg), context.self()); |
|
|
|
@ -436,7 +433,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
|
|
|
if (notification != null) { |
|
|
|
ToDeviceMsg finalNotification = notification; |
|
|
|
attributeSubscriptions.entrySet().forEach(sub -> { |
|
|
|
ToDeviceSessionActorMsg response = new BasicToDeviceSessionActorMsg(finalNotification, sub.getKey()); |
|
|
|
ActorSystemToDeviceSessionActorMsg response = new BasicActorSystemToDeviceSessionActorMsg(finalNotification, sub.getKey()); |
|
|
|
sendMsgToSessionActor(response, sub.getValue().getServer()); |
|
|
|
}); |
|
|
|
} |
|
|
|
@ -462,7 +459,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
|
|
|
BasicCommandAckResponse response = success |
|
|
|
? BasicCommandAckResponse.onSuccess(SessionMsgType.TO_DEVICE_RPC_REQUEST, responseMsg.getRequestId()) |
|
|
|
: BasicCommandAckResponse.onError(SessionMsgType.TO_DEVICE_RPC_REQUEST, responseMsg.getRequestId(), new TimeoutException()); |
|
|
|
sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(response, msg.getSessionId()), msg.getServerAddress()); |
|
|
|
sendMsgToSessionActor(new BasicActorSystemToDeviceSessionActorMsg(response, msg.getSessionId()), msg.getServerAddress()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -517,7 +514,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void sendMsgToSessionActor(ToDeviceSessionActorMsg response, Optional<ServerAddress> sessionAddress) { |
|
|
|
private void sendMsgToSessionActor(ActorSystemToDeviceSessionActorMsg response, Optional<ServerAddress> sessionAddress) { |
|
|
|
if (sessionAddress.isPresent()) { |
|
|
|
ServerAddress address = sessionAddress.get(); |
|
|
|
logger.debug("{} Forwarding msg: {}", address, response); |
|
|
|
@ -530,7 +527,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
|
|
|
|
|
|
|
void processCredentialsUpdate() { |
|
|
|
sessions.forEach((k, v) -> { |
|
|
|
sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(new SessionCloseNotification(), k), v.getServer()); |
|
|
|
sendMsgToSessionActor(new BasicActorSystemToDeviceSessionActorMsg(new SessionCloseNotification(), k), v.getServer()); |
|
|
|
}); |
|
|
|
attributeSubscriptions.clear(); |
|
|
|
rpcSubscriptions.clear(); |
|
|
|
|