Browse Source

Refactoring of MQTT Transport and removing data structures

pull/1166/head
Andrew Shvayka 8 years ago
parent
commit
52ef95ac1b
  1. 15
      application/src/main/java/org/thingsboard/server/actors/device/DeviceActorMessageProcessor.java
  2. 1
      application/src/main/java/org/thingsboard/server/actors/service/DefaultActorService.java
  3. 35
      application/src/main/java/org/thingsboard/server/actors/shared/SessionTimeoutMsg.java
  4. 7
      application/src/main/java/org/thingsboard/server/controller/TelemetryController.java
  5. 3
      application/src/main/java/org/thingsboard/server/service/rpc/ToServerRpcResponseActorMsg.java
  6. 8
      application/src/main/java/org/thingsboard/server/service/transport/RemoteTransportApiService.java
  7. 22
      common/message/src/main/java/org/thingsboard/server/common/msg/aware/SessionAwareMsg.java
  8. 30
      common/message/src/main/java/org/thingsboard/server/common/msg/core/ActorSystemToDeviceSessionActorMsg.java
  9. 29
      common/message/src/main/java/org/thingsboard/server/common/msg/core/AttributesSubscribeMsg.java
  10. 30
      common/message/src/main/java/org/thingsboard/server/common/msg/core/AttributesUnsubscribeMsg.java
  11. 47
      common/message/src/main/java/org/thingsboard/server/common/msg/core/AttributesUpdateNotification.java
  12. 28
      common/message/src/main/java/org/thingsboard/server/common/msg/core/AttributesUpdateRequest.java
  13. 63
      common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicAttributesUpdateRequest.java
  14. 45
      common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicCommandAckResponse.java
  15. 59
      common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicGetAttributesRequest.java
  16. 40
      common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicGetAttributesResponse.java
  17. 36
      common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicRequest.java
  18. 79
      common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicResponseMsg.java
  19. 42
      common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicStatusCodeResponse.java
  20. 66
      common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicTelemetryUploadRequest.java
  21. 29
      common/message/src/main/java/org/thingsboard/server/common/msg/core/GetAttributesRequest.java
  22. 22
      common/message/src/main/java/org/thingsboard/server/common/msg/core/GetAttributesResponse.java
  23. 33
      common/message/src/main/java/org/thingsboard/server/common/msg/core/ResponseMsg.java
  24. 30
      common/message/src/main/java/org/thingsboard/server/common/msg/core/RpcSubscribeMsg.java
  25. 30
      common/message/src/main/java/org/thingsboard/server/common/msg/core/RpcUnsubscribeMsg.java
  26. 43
      common/message/src/main/java/org/thingsboard/server/common/msg/core/RuleEngineError.java
  27. 53
      common/message/src/main/java/org/thingsboard/server/common/msg/core/RuleEngineErrorMsg.java
  28. 30
      common/message/src/main/java/org/thingsboard/server/common/msg/core/SessionCloseMsg.java
  29. 38
      common/message/src/main/java/org/thingsboard/server/common/msg/core/SessionCloseNotification.java
  30. 32
      common/message/src/main/java/org/thingsboard/server/common/msg/core/SessionOpenMsg.java
  31. 20
      common/message/src/main/java/org/thingsboard/server/common/msg/core/StatusCodeResponse.java
  32. 29
      common/message/src/main/java/org/thingsboard/server/common/msg/core/TelemetryUploadRequest.java
  33. 41
      common/message/src/main/java/org/thingsboard/server/common/msg/core/ToDeviceRpcRequestMsg.java
  34. 36
      common/message/src/main/java/org/thingsboard/server/common/msg/core/ToDeviceRpcResponseMsg.java
  35. 36
      common/message/src/main/java/org/thingsboard/server/common/msg/core/ToServerRpcRequestMsg.java
  36. 11
      common/message/src/main/java/org/thingsboard/server/common/msg/core/ToServerRpcResponseMsg.java
  37. 22
      common/message/src/main/java/org/thingsboard/server/common/msg/session/AdaptorToSessionActorMsg.java
  38. 32
      common/message/src/main/java/org/thingsboard/server/common/msg/session/BasicAdaptorToSessionActorMsg.java
  39. 32
      common/message/src/main/java/org/thingsboard/server/common/msg/session/BasicSessionActorToAdaptorMsg.java
  40. 42
      common/message/src/main/java/org/thingsboard/server/common/msg/session/BasicSessionMsg.java
  41. 73
      common/message/src/main/java/org/thingsboard/server/common/msg/session/BasicTransportToDeviceSessionActorMsg.java
  42. 24
      common/message/src/main/java/org/thingsboard/server/common/msg/session/FromDeviceMsg.java
  43. 25
      common/message/src/main/java/org/thingsboard/server/common/msg/session/FromDeviceRequestMsg.java
  44. 22
      common/message/src/main/java/org/thingsboard/server/common/msg/session/SessionActorToAdaptorMsg.java
  45. 8
      common/message/src/main/java/org/thingsboard/server/common/msg/session/SessionContext.java
  46. 23
      common/message/src/main/java/org/thingsboard/server/common/msg/session/SessionCtrlMsg.java
  47. 24
      common/message/src/main/java/org/thingsboard/server/common/msg/session/SessionMsg.java
  48. 22
      common/message/src/main/java/org/thingsboard/server/common/msg/session/SessionType.java
  49. 26
      common/message/src/main/java/org/thingsboard/server/common/msg/session/ToDeviceMsg.java
  50. 28
      common/message/src/main/java/org/thingsboard/server/common/msg/session/TransportToDeviceSessionActorMsg.java
  51. 67
      common/message/src/main/java/org/thingsboard/server/common/msg/session/ctrl/SessionCloseMsg.java
  52. 1
      common/transport/src/main/java/org/thingsboard/server/common/transport/SessionMsgProcessor.java
  53. 190
      common/transport/src/main/java/org/thingsboard/server/common/transport/adaptor/JsonConverter.java
  54. 2
      common/transport/src/main/java/org/thingsboard/server/common/transport/session/DeviceAwareSessionContext.java
  55. 2
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbCopyAttributesToEntityViewNode.java
  56. 2
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNode.java
  57. 7
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgTimeseriesNode.java
  58. 6
      transport/coap/src/main/java/org/thingsboard/server/transport/coap/adaptors/JsonCoapAdaptor.java
  59. 4
      transport/coap/src/main/java/org/thingsboard/server/transport/coap/session/CoapSessionCtx.java
  60. 11
      transport/coap/src/test/java/org/thingsboard/server/transport/coap/CoapServerTest.java
  61. 14
      transport/http/src/main/java/org/thingsboard/server/transport/http/DeviceApiController.java
  62. 8
      transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportContext.java
  63. 8
      transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java
  64. 8
      transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/adaptors/JsonMqttAdaptor.java
  65. 56
      transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/session/DeviceSessionCtx.java
  66. 12
      transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/session/GatewayDeviceSessionCtx.java
  67. 8
      transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/session/GatewaySessionCtx.java
  68. 5
      transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/session/MqttDeviceAwareSessionContext.java
  69. 60
      transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/session/MqttSessionId.java
  70. 10
      transport/mqtt-transport/src/main/java/org/thingsboard/server/mqtt/service/MqttTransportService.java
  71. 4
      transport/pom.xml

15
application/src/main/java/org/thingsboard/server/actors/device/DeviceActorMessageProcessor.java

@ -42,12 +42,8 @@ import org.thingsboard.server.common.msg.TbMsgDataType;
import org.thingsboard.server.common.msg.TbMsgMetaData;
import org.thingsboard.server.common.msg.cluster.ClusterEventMsg;
import org.thingsboard.server.common.msg.cluster.ServerAddress;
import org.thingsboard.server.common.msg.core.ActorSystemToDeviceSessionActorMsg;
import org.thingsboard.server.common.msg.core.RuleEngineError;
import org.thingsboard.server.common.msg.core.RuleEngineErrorMsg;
import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.ToDeviceMsg;
import org.thingsboard.server.common.msg.timeout.DeviceActorClientSideRpcTimeoutMsg;
import org.thingsboard.server.common.msg.timeout.DeviceActorServerSideRpcTimeoutMsg;
import org.thingsboard.server.gen.transport.TransportProtos;
@ -481,17 +477,6 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso
}
}
private void sendMsgToSessionActor(ActorSystemToDeviceSessionActorMsg response, Optional<ServerAddress> sessionAddress) {
if (sessionAddress.isPresent()) {
ServerAddress address = sessionAddress.get();
logger.debug("{} Forwarding msg: {}", address, response);
systemContext.getRpcService().tell(systemContext.getEncodingService()
.convertToProtoDataMessage(sessionAddress.get(), response));
} else {
// systemContext.getSessionManagerActor().tell(response, ActorRef.noSender());
}
}
void processCredentialsUpdate() {
sessions.forEach(this::closeSession);
attributeSubscriptions.clear();

1
application/src/main/java/org/thingsboard/server/actors/service/DefaultActorService.java

@ -37,7 +37,6 @@ import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
import org.thingsboard.server.common.msg.TbActorMsg;
import org.thingsboard.server.common.msg.aware.SessionAwareMsg;
import org.thingsboard.server.common.msg.cluster.ClusterEventMsg;
import org.thingsboard.server.common.msg.cluster.SendToClusterMsg;
import org.thingsboard.server.common.msg.cluster.ServerAddress;

35
application/src/main/java/org/thingsboard/server/actors/shared/SessionTimeoutMsg.java

@ -1,35 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.actors.shared;
import lombok.Data;
import org.thingsboard.server.common.msg.MsgType;
import org.thingsboard.server.common.msg.TbActorMsg;
import java.io.Serializable;
@Data
public class SessionTimeoutMsg implements Serializable, TbActorMsg {
private static final long serialVersionUID = 1L;
private final SessionId sessionId;
@Override
public MsgType getMsgType() {
return MsgType.SESSION_TIMEOUT_MSG;
}
}

7
application/src/main/java/org/thingsboard/server/controller/TelemetryController.java

@ -59,7 +59,6 @@ import org.thingsboard.server.common.data.kv.ReadTsKvQuery;
import org.thingsboard.server.common.data.kv.StringDataEntry;
import org.thingsboard.server.common.data.kv.TsKvEntry;
import org.thingsboard.server.common.msg.cluster.SendToClusterMsg;
import org.thingsboard.server.common.msg.core.TelemetryUploadRequest;
import org.thingsboard.server.common.transport.adaptor.JsonConverter;
import org.thingsboard.server.dao.attributes.AttributesService;
import org.thingsboard.server.dao.timeseries.TimeseriesService;
@ -352,7 +351,7 @@ public class TelemetryController extends BaseController {
}
private DeferredResult<ResponseEntity> saveTelemetry(EntityId entityIdSrc, String requestBody, long ttl) throws ThingsboardException {
TelemetryUploadRequest telemetryRequest;
Map<Long, List<KvEntry>> telemetryRequest;
JsonElement telemetryJson;
try {
telemetryJson = new JsonParser().parse(requestBody);
@ -360,12 +359,12 @@ public class TelemetryController extends BaseController {
return getImmediateDeferredResult("Unable to parse timeseries payload: Invalid JSON body!", HttpStatus.BAD_REQUEST);
}
try {
telemetryRequest = JsonConverter.convertToTelemetry(telemetryJson);
telemetryRequest = JsonConverter.convertToTelemetry(telemetryJson, System.currentTimeMillis());
} catch (Exception e) {
return getImmediateDeferredResult("Unable to parse timeseries payload. Invalid JSON body: " + e.getMessage(), HttpStatus.BAD_REQUEST);
}
List<TsKvEntry> entries = new ArrayList<>();
for (Map.Entry<Long, List<KvEntry>> entry : telemetryRequest.getData().entrySet()) {
for (Map.Entry<Long, List<KvEntry>> entry : telemetryRequest.entrySet()) {
for (KvEntry kv : entry.getValue()) {
entries.add(new BasicTsKvEntry(entry.getKey(), kv));
}

3
application/src/main/java/org/thingsboard/server/service/rpc/ToServerRpcResponseActorMsg.java

@ -22,11 +22,8 @@ import org.thingsboard.rule.engine.api.msg.ToDeviceActorNotificationMsg;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.msg.MsgType;
import org.thingsboard.server.common.msg.cluster.ServerAddress;
import org.thingsboard.server.common.msg.core.ToServerRpcResponseMsg;
import java.util.Optional;
/**
* Created by ashvayka on 16.04.18.
*/

8
application/src/main/java/org/thingsboard/server/service/transport/RemoteTransportApiService.java

@ -1,12 +1,12 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

22
common/message/src/main/java/org/thingsboard/server/common/msg/aware/SessionAwareMsg.java

@ -1,22 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.aware;
public interface SessionAwareMsg {
SessionId getSessionId();
}

30
common/message/src/main/java/org/thingsboard/server/common/msg/core/ActorSystemToDeviceSessionActorMsg.java

@ -1,30 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import org.thingsboard.server.common.msg.TbActorMsg;
import org.thingsboard.server.common.msg.aware.SessionAwareMsg;
import org.thingsboard.server.common.msg.session.ToDeviceMsg;
import java.io.Serializable;
/**
* @author Andrew Shvayka
*/
public interface ActorSystemToDeviceSessionActorMsg extends SessionAwareMsg, Serializable, TbActorMsg {
ToDeviceMsg getMsg();
}

29
common/message/src/main/java/org/thingsboard/server/common/msg/core/AttributesSubscribeMsg.java

@ -1,29 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
/**
* @author Andrew Shvayka
*/
public class AttributesSubscribeMsg implements FromDeviceMsg {
@Override
public SessionMsgType getMsgType() {
return SessionMsgType.SUBSCRIBE_ATTRIBUTES_REQUEST;
}
}

30
common/message/src/main/java/org/thingsboard/server/common/msg/core/AttributesUnsubscribeMsg.java

@ -1,30 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
/**
* @author Andrew Shvayka
*/
public class AttributesUnsubscribeMsg implements FromDeviceMsg {
@Override
public SessionMsgType getMsgType() {
return SessionMsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST;
}
}

47
common/message/src/main/java/org/thingsboard/server/common/msg/core/AttributesUpdateNotification.java

@ -1,47 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import lombok.ToString;
import org.thingsboard.server.common.msg.kv.AttributesKVMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.ToDeviceMsg;
@ToString
public class AttributesUpdateNotification implements ToDeviceMsg {
private static final long serialVersionUID = 1L;
private AttributesKVMsg data;
public AttributesUpdateNotification(AttributesKVMsg data) {
this.data = data;
}
@Override
public boolean isSuccess() {
return true;
}
public SessionMsgType getSessionMsgType() {
return SessionMsgType.ATTRIBUTES_UPDATE_NOTIFICATION;
}
public AttributesKVMsg getData() {
return data;
}
}

28
common/message/src/main/java/org/thingsboard/server/common/msg/core/AttributesUpdateRequest.java

@ -1,28 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import java.util.Set;
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg;
public interface AttributesUpdateRequest extends FromDeviceRequestMsg {
Set<AttributeKvEntry> getAttributes();
}

63
common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicAttributesUpdateRequest.java

@ -1,63 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
import org.thingsboard.server.common.msg.session.SessionMsgType;
public class BasicAttributesUpdateRequest extends BasicRequest implements AttributesUpdateRequest {
private static final long serialVersionUID = 1L;
private final Set<AttributeKvEntry> data;
public BasicAttributesUpdateRequest() {
this(DEFAULT_REQUEST_ID);
}
public BasicAttributesUpdateRequest(Integer requestId) {
super(requestId);
this.data = new LinkedHashSet<>();
}
public void add(AttributeKvEntry entry) {
this.data.add(entry);
}
public void add(Collection<AttributeKvEntry> entries) {
this.data.addAll(entries);
}
@Override
public SessionMsgType getMsgType() {
return SessionMsgType.POST_ATTRIBUTES_REQUEST;
}
@Override
public Set<AttributeKvEntry> getAttributes() {
return data;
}
@Override
public String toString() {
return "BasicAttributesUpdateRequest [data=" + data + "]";
}
}

45
common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicCommandAckResponse.java

@ -1,45 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
public class BasicCommandAckResponse extends BasicResponseMsg<Integer> implements StatusCodeResponse {
private static final long serialVersionUID = 1L;
public static BasicCommandAckResponse onSuccess(SessionMsgType requestMsgType, Integer requestId) {
return BasicCommandAckResponse.onSuccess(requestMsgType, requestId, 200);
}
public static BasicCommandAckResponse onSuccess(SessionMsgType requestMsgType, Integer requestId, Integer code) {
return new BasicCommandAckResponse(requestMsgType, requestId, true, null, code);
}
public static BasicCommandAckResponse onError(SessionMsgType requestMsgType, Integer requestId, Exception error) {
return new BasicCommandAckResponse(requestMsgType, requestId, false, error, null);
}
private BasicCommandAckResponse(SessionMsgType requestMsgType, Integer requestId, boolean success, Exception error, Integer code) {
super(requestMsgType, requestId, SessionMsgType.TO_DEVICE_RPC_RESPONSE_ACK, success, error, code);
}
@Override
public String toString() {
return "BasicStatusCodeResponse []";
}
}

59
common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicGetAttributesRequest.java

@ -1,59 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import lombok.ToString;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
@ToString
public class BasicGetAttributesRequest extends BasicRequest implements GetAttributesRequest {
private static final long serialVersionUID = 1L;
private final Set<String> clientKeys;
private final Set<String> sharedKeys;
public BasicGetAttributesRequest(Integer requestId) {
this(requestId, Collections.emptySet(), Collections.emptySet());
}
public BasicGetAttributesRequest(Integer requestId, Set<String> clientKeys, Set<String> sharedKeys) {
super(requestId);
this.clientKeys = clientKeys;
this.sharedKeys = sharedKeys;
}
@Override
public SessionMsgType getMsgType() {
return SessionMsgType.GET_ATTRIBUTES_REQUEST;
}
@Override
public Optional<Set<String>> getClientAttributeNames() {
return Optional.ofNullable(clientKeys);
}
@Override
public Optional<Set<String>> getSharedAttributeNames() {
return Optional.ofNullable(sharedKeys);
}
}

40
common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicGetAttributesResponse.java

@ -1,40 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import lombok.ToString;
import org.thingsboard.server.common.msg.kv.AttributesKVMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
@ToString
public class BasicGetAttributesResponse extends BasicResponseMsg<AttributesKVMsg> implements GetAttributesResponse {
private static final long serialVersionUID = 1L;
public static BasicGetAttributesResponse onSuccess(SessionMsgType requestMsgType, int requestId, AttributesKVMsg code) {
return new BasicGetAttributesResponse(requestMsgType, requestId, true, null, code);
}
public static BasicGetAttributesResponse onError(SessionMsgType requestMsgType, int requestId, Exception error) {
return new BasicGetAttributesResponse(requestMsgType, requestId, false, error, null);
}
private BasicGetAttributesResponse(SessionMsgType requestMsgType, int requestId, boolean success, Exception error, AttributesKVMsg code) {
super(requestMsgType, requestId, SessionMsgType.GET_ATTRIBUTES_RESPONSE, success, error, code);
}
}

36
common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicRequest.java

@ -1,36 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import java.io.Serializable;
/**
* @author Andrew Shvayka
*/
public class BasicRequest implements Serializable {
public static final Integer DEFAULT_REQUEST_ID = 0;
private final Integer requestId;
public BasicRequest(Integer requestId) {
this.requestId = requestId;
}
public Integer getRequestId() {
return requestId;
}
}

79
common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicResponseMsg.java

@ -1,79 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import java.io.Serializable;
import java.util.Optional;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
public class BasicResponseMsg<T extends Serializable> implements ResponseMsg<T> {
private static final long serialVersionUID = 1L;
private final SessionMsgType requestMsgType;
private final Integer requestId;
private final SessionMsgType sessionMsgType;
private final boolean success;
private final T data;
private final Exception error;
protected BasicResponseMsg(SessionMsgType requestMsgType, Integer requestId, SessionMsgType sessionMsgType, boolean success, Exception error, T data) {
super();
this.requestMsgType = requestMsgType;
this.requestId = requestId;
this.sessionMsgType = sessionMsgType;
this.success = success;
this.error = error;
this.data = data;
}
@Override
public SessionMsgType getRequestMsgType() {
return requestMsgType;
}
@Override
public Integer getRequestId() {
return requestId;
}
@Override
public boolean isSuccess() {
return success;
}
@Override
public Optional<Exception> getError() {
return Optional.ofNullable(error);
}
@Override
public Optional<T> getData() {
return Optional.ofNullable(data);
}
@Override
public String toString() {
return "BasicResponseMsg [success=" + success + ", data=" + data + ", error=" + error + "]";
}
public SessionMsgType getSessionMsgType() {
return sessionMsgType;
}
}

42
common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicStatusCodeResponse.java

@ -1,42 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import lombok.ToString;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
@ToString
public class BasicStatusCodeResponse extends BasicResponseMsg<Integer> implements StatusCodeResponse {
private static final long serialVersionUID = 1L;
public static BasicStatusCodeResponse onSuccess(SessionMsgType requestMsgType, Integer requestId) {
return BasicStatusCodeResponse.onSuccess(requestMsgType, requestId, 0);
}
public static BasicStatusCodeResponse onSuccess(SessionMsgType requestMsgType, Integer requestId, Integer code) {
return new BasicStatusCodeResponse(requestMsgType, requestId, true, null, code);
}
public static BasicStatusCodeResponse onError(SessionMsgType requestMsgType, Integer requestId, Exception error) {
return new BasicStatusCodeResponse(requestMsgType, requestId, false, error, null);
}
private BasicStatusCodeResponse(SessionMsgType requestMsgType, Integer requestId, boolean success, Exception error, Integer code) {
super(requestMsgType, requestId, SessionMsgType.STATUS_CODE_RESPONSE, success, error, code);
}
}

66
common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicTelemetryUploadRequest.java

@ -1,66 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.thingsboard.server.common.data.kv.KvEntry;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
public class BasicTelemetryUploadRequest extends BasicRequest implements TelemetryUploadRequest {
private static final long serialVersionUID = 1L;
private final Map<Long, List<KvEntry>> data;
public BasicTelemetryUploadRequest() {
this(DEFAULT_REQUEST_ID);
}
public BasicTelemetryUploadRequest(Integer requestId) {
super(requestId);
this.data = new HashMap<>();
}
public void add(long ts, KvEntry entry) {
List<KvEntry> tsEntries = data.get(ts);
if (tsEntries == null) {
tsEntries = new ArrayList<>();
data.put(ts, tsEntries);
}
tsEntries.add(entry);
}
@Override
public SessionMsgType getMsgType() {
return SessionMsgType.POST_TELEMETRY_REQUEST;
}
@Override
public Map<Long, List<KvEntry>> getData() {
return data;
}
@Override
public String toString() {
return "BasicTelemetryUploadRequest [data=" + data + "]";
}
}

29
common/message/src/main/java/org/thingsboard/server/common/msg/core/GetAttributesRequest.java

@ -1,29 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import java.util.Optional;
import java.util.Set;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg;
public interface GetAttributesRequest extends FromDeviceRequestMsg {
Optional<Set<String>> getClientAttributeNames();
Optional<Set<String>> getSharedAttributeNames();
}

22
common/message/src/main/java/org/thingsboard/server/common/msg/core/GetAttributesResponse.java

@ -1,22 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import org.thingsboard.server.common.msg.kv.AttributesKVMsg;
public interface GetAttributesResponse extends ResponseMsg<AttributesKVMsg> {
}

33
common/message/src/main/java/org/thingsboard/server/common/msg/core/ResponseMsg.java

@ -1,33 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import java.io.Serializable;
import java.util.Optional;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.ToDeviceMsg;
public interface ResponseMsg<T extends Serializable> extends ToDeviceMsg {
SessionMsgType getRequestMsgType();
Integer getRequestId();
Optional<Exception> getError();
Optional<T> getData();
}

30
common/message/src/main/java/org/thingsboard/server/common/msg/core/RpcSubscribeMsg.java

@ -1,30 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
/**
* @author Andrew Shvayka
*/
public class RpcSubscribeMsg implements FromDeviceMsg {
@Override
public SessionMsgType getMsgType() {
return SessionMsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST;
}
}

30
common/message/src/main/java/org/thingsboard/server/common/msg/core/RpcUnsubscribeMsg.java

@ -1,30 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
/**
* @author Andrew Shvayka
*/
public class RpcUnsubscribeMsg implements FromDeviceMsg {
@Override
public SessionMsgType getMsgType() {
return SessionMsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST;
}
}

43
common/message/src/main/java/org/thingsboard/server/common/msg/core/RuleEngineError.java

@ -1,43 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
/**
* @author Andrew Shvayka
*/
public enum RuleEngineError {
QUEUE_PUT_TIMEOUT(true), SERVER_ERROR(true), TIMEOUT;
private final boolean critical;
RuleEngineError() {
this(false);
}
RuleEngineError(boolean critical) {
this.critical = critical;
}
public boolean isCritical() {
return critical;
}
public int getPriority() {
return ordinal();
}
}

53
common/message/src/main/java/org/thingsboard/server/common/msg/core/RuleEngineErrorMsg.java

@ -1,53 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import lombok.Data;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.ToDeviceMsg;
/**
* @author Andrew Shvayka
*/
@Data
public class RuleEngineErrorMsg implements ToDeviceMsg {
private final SessionMsgType inSessionMsgType;
private final RuleEngineError error;
@Override
public boolean isSuccess() {
return false;
}
public SessionMsgType getSessionMsgType() {
return SessionMsgType.RULE_ENGINE_ERROR;
}
public String getErrorMsg() {
switch (error) {
case QUEUE_PUT_TIMEOUT:
return "Timeout during persistence of the message to the queue!";
case SERVER_ERROR:
return "Error during processing of message by the server!";
case TIMEOUT:
return "Timeout during processing of message by the server!";
default:
throw new RuntimeException("Error " + error + " is not supported!");
}
}
}

30
common/message/src/main/java/org/thingsboard/server/common/msg/core/SessionCloseMsg.java

@ -1,30 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
/**
* @author Andrew Shvayka
*/
public class SessionCloseMsg implements FromDeviceMsg {
@Override
public SessionMsgType getMsgType() {
return SessionMsgType.SESSION_CLOSE;
}
}

38
common/message/src/main/java/org/thingsboard/server/common/msg/core/SessionCloseNotification.java

@ -1,38 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import lombok.ToString;
import org.thingsboard.server.common.msg.kv.AttributesKVMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.ToDeviceMsg;
@ToString
public class SessionCloseNotification implements ToDeviceMsg {
private static final long serialVersionUID = 1L;
@Override
public boolean isSuccess() {
return true;
}
public SessionMsgType getSessionMsgType() {
return SessionMsgType.SESSION_CLOSE;
}
}

32
common/message/src/main/java/org/thingsboard/server/common/msg/core/SessionOpenMsg.java

@ -1,32 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import lombok.Data;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
/**
* @author Andrew Shvayka
*/
@Data
public class SessionOpenMsg implements FromDeviceMsg {
@Override
public SessionMsgType getMsgType() {
return SessionMsgType.SESSION_OPEN;
}
}

20
common/message/src/main/java/org/thingsboard/server/common/msg/core/StatusCodeResponse.java

@ -1,20 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
public interface StatusCodeResponse extends ResponseMsg<Integer>{
}

29
common/message/src/main/java/org/thingsboard/server/common/msg/core/TelemetryUploadRequest.java

@ -1,29 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import java.util.List;
import java.util.Map;
import org.thingsboard.server.common.data.kv.KvEntry;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg;
public interface TelemetryUploadRequest extends FromDeviceRequestMsg {
Map<Long, List<KvEntry>> getData();
}

41
common/message/src/main/java/org/thingsboard/server/common/msg/core/ToDeviceRpcRequestMsg.java

@ -1,41 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import lombok.Data;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.ToDeviceMsg;
/**
* @author Andrew Shvayka
*/
@Data
public class ToDeviceRpcRequestMsg implements ToDeviceMsg {
private final int requestId;
private final String method;
private final String params;
public SessionMsgType getSessionMsgType() {
return SessionMsgType.TO_DEVICE_RPC_REQUEST;
}
@Override
public boolean isSuccess() {
return true;
}
}

36
common/message/src/main/java/org/thingsboard/server/common/msg/core/ToDeviceRpcResponseMsg.java

@ -1,36 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import lombok.Data;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
/**
* @author Andrew Shvayka
*/
@Data
public class ToDeviceRpcResponseMsg implements FromDeviceMsg {
private final int requestId;
private final String data;
@Override
public SessionMsgType getMsgType() {
return SessionMsgType.TO_DEVICE_RPC_RESPONSE;
}
}

36
common/message/src/main/java/org/thingsboard/server/common/msg/core/ToServerRpcRequestMsg.java

@ -1,36 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.core;
import lombok.Data;
import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
/**
* @author Andrew Shvayka
*/
@Data
public class ToServerRpcRequestMsg implements FromDeviceRequestMsg {
private final Integer requestId;
private final String method;
private final String params;
@Override
public SessionMsgType getMsgType() {
return SessionMsgType.TO_SERVER_RPC_REQUEST;
}
}

11
common/message/src/main/java/org/thingsboard/server/common/msg/core/ToServerRpcResponseMsg.java

@ -16,25 +16,16 @@
package org.thingsboard.server.common.msg.core;
import lombok.Data;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.ToDeviceMsg;
/**
* @author Andrew Shvayka
*/
@Data
public class ToServerRpcResponseMsg implements ToDeviceMsg {
public class ToServerRpcResponseMsg {
private final int requestId;
private final String data;
public SessionMsgType getSessionMsgType() {
return SessionMsgType.TO_SERVER_RPC_RESPONSE;
}
@Override
public boolean isSuccess() {
return true;
}

22
common/message/src/main/java/org/thingsboard/server/common/msg/session/AdaptorToSessionActorMsg.java

@ -1,22 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
public interface AdaptorToSessionActorMsg extends SessionMsg {
FromDeviceMsg getMsg();
}

32
common/message/src/main/java/org/thingsboard/server/common/msg/session/BasicAdaptorToSessionActorMsg.java

@ -1,32 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
public class BasicAdaptorToSessionActorMsg extends BasicSessionMsg implements AdaptorToSessionActorMsg {
private final FromDeviceMsg msg;
public BasicAdaptorToSessionActorMsg(SessionContext ctx, FromDeviceMsg msg) {
super(ctx);
this.msg = msg;
}
@Override
public FromDeviceMsg getMsg() {
return msg;
}
}

32
common/message/src/main/java/org/thingsboard/server/common/msg/session/BasicSessionActorToAdaptorMsg.java

@ -1,32 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
public class BasicSessionActorToAdaptorMsg extends BasicSessionMsg implements SessionActorToAdaptorMsg {
private final ToDeviceMsg msg;
public BasicSessionActorToAdaptorMsg(SessionContext ctx, ToDeviceMsg msg) {
super(ctx);
this.msg = msg;
}
@Override
public ToDeviceMsg getMsg() {
return msg;
}
}

42
common/message/src/main/java/org/thingsboard/server/common/msg/session/BasicSessionMsg.java

@ -1,42 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
public class BasicSessionMsg implements SessionMsg {
private final SessionContext ctx;
public BasicSessionMsg(SessionContext ctx) {
super();
this.ctx = ctx;
}
@Override
public SessionId getSessionId() {
return ctx.getSessionId();
}
@Override
public SessionContext getSessionContext() {
return ctx;
}
@Override
public String toString() {
return "BasicSessionMsg [ctx=" + ctx + "]";
}
}

73
common/message/src/main/java/org/thingsboard/server/common/msg/session/BasicTransportToDeviceSessionActorMsg.java

@ -1,73 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.msg.MsgType;
public class BasicTransportToDeviceSessionActorMsg implements TransportToDeviceSessionActorMsg {
private final TenantId tenantId;
private final CustomerId customerId;
private final DeviceId deviceId;
private final AdaptorToSessionActorMsg msg;
public BasicTransportToDeviceSessionActorMsg(Device device, AdaptorToSessionActorMsg msg) {
super();
this.tenantId = device.getTenantId();
this.customerId = device.getCustomerId();
this.deviceId = device.getId();
this.msg = msg;
}
@Override
public DeviceId getDeviceId() {
return deviceId;
}
@Override
public CustomerId getCustomerId() {
return customerId;
}
public TenantId getTenantId() {
return tenantId;
}
@Override
public SessionId getSessionId() {
return msg.getSessionId();
}
@Override
public AdaptorToSessionActorMsg getSessionMsg() {
return msg;
}
@Override
public String toString() {
return "BasicTransportToDeviceSessionActorMsg [tenantId=" + tenantId + ", customerId=" + customerId + ", deviceId=" + deviceId + ", msg=" + msg
+ "]";
}
@Override
public MsgType getMsgType() {
return MsgType.TRANSPORT_TO_DEVICE_SESSION_ACTOR_MSG;
}
}

24
common/message/src/main/java/org/thingsboard/server/common/msg/session/FromDeviceMsg.java

@ -1,24 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
import java.io.Serializable;
public interface FromDeviceMsg extends Serializable {
SessionMsgType getMsgType();
}

25
common/message/src/main/java/org/thingsboard/server/common/msg/session/FromDeviceRequestMsg.java

@ -1,25 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
/**
* @author Andrew Shvayka
*/
public interface FromDeviceRequestMsg extends FromDeviceMsg {
Integer getRequestId();
}

22
common/message/src/main/java/org/thingsboard/server/common/msg/session/SessionActorToAdaptorMsg.java

@ -1,22 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
public interface SessionActorToAdaptorMsg extends SessionMsg {
ToDeviceMsg getMsg();
}

8
common/message/src/main/java/org/thingsboard/server/common/msg/session/SessionContext.java

@ -1,12 +1,12 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

23
common/message/src/main/java/org/thingsboard/server/common/msg/session/SessionCtrlMsg.java

@ -1,23 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
import org.thingsboard.server.common.msg.TbActorMsg;
import org.thingsboard.server.common.msg.aware.SessionAwareMsg;
public interface SessionCtrlMsg extends SessionAwareMsg, TbActorMsg {
}

24
common/message/src/main/java/org/thingsboard/server/common/msg/session/SessionMsg.java

@ -1,24 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
import org.thingsboard.server.common.msg.aware.SessionAwareMsg;
public interface SessionMsg extends SessionAwareMsg {
SessionContext getSessionContext();
}

22
common/message/src/main/java/org/thingsboard/server/common/msg/session/SessionType.java

@ -1,22 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
public enum SessionType {
SYNC, ASYNC;
}

26
common/message/src/main/java/org/thingsboard/server/common/msg/session/ToDeviceMsg.java

@ -1,26 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
import java.io.Serializable;
public interface ToDeviceMsg extends Serializable {
boolean isSuccess();
SessionMsgType getSessionMsgType();
}

28
common/message/src/main/java/org/thingsboard/server/common/msg/session/TransportToDeviceSessionActorMsg.java

@ -1,28 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session;
import org.thingsboard.server.common.msg.TbActorMsg;
import org.thingsboard.server.common.msg.aware.CustomerAwareMsg;
import org.thingsboard.server.common.msg.aware.DeviceAwareMsg;
import org.thingsboard.server.common.msg.aware.SessionAwareMsg;
import org.thingsboard.server.common.msg.aware.TenantAwareMsg;
public interface TransportToDeviceSessionActorMsg extends DeviceAwareMsg, CustomerAwareMsg, TenantAwareMsg, SessionAwareMsg, TbActorMsg {
AdaptorToSessionActorMsg getSessionMsg();
}

67
common/message/src/main/java/org/thingsboard/server/common/msg/session/ctrl/SessionCloseMsg.java

@ -1,67 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.msg.session.ctrl;
import org.thingsboard.server.common.msg.MsgType;
import org.thingsboard.server.common.msg.session.SessionCtrlMsg;
public class SessionCloseMsg implements SessionCtrlMsg {
private final SessionId sessionId;
private final boolean revoked;
private final boolean timeout;
public static SessionCloseMsg onDisconnect(SessionId sessionId) {
return new SessionCloseMsg(sessionId, false, false);
}
public static SessionCloseMsg onError(SessionId sessionId) {
return new SessionCloseMsg(sessionId, false, false);
}
public static SessionCloseMsg onTimeout(SessionId sessionId) {
return new SessionCloseMsg(sessionId, false, true);
}
public static SessionCloseMsg onCredentialsRevoked(SessionId sessionId) {
return new SessionCloseMsg(sessionId, true, false);
}
private SessionCloseMsg(SessionId sessionId, boolean unauthorized, boolean timeout) {
super();
this.sessionId = sessionId;
this.revoked = unauthorized;
this.timeout = timeout;
}
@Override
public SessionId getSessionId() {
return sessionId;
}
public boolean isCredentialsRevoked() {
return revoked;
}
public boolean isTimeout() {
return timeout;
}
@Override
public MsgType getMsgType() {
return MsgType.SESSION_CTRL_MSG;
}
}

1
common/transport/src/main/java/org/thingsboard/server/common/transport/SessionMsgProcessor.java

@ -16,7 +16,6 @@
package org.thingsboard.server.common.transport;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.msg.aware.SessionAwareMsg;
public interface SessionMsgProcessor {

190
common/transport/src/main/java/org/thingsboard/server/common/transport/adaptor/JsonConverter.java

@ -1,12 +1,12 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -31,12 +31,6 @@ import org.thingsboard.server.common.data.kv.DoubleDataEntry;
import org.thingsboard.server.common.data.kv.KvEntry;
import org.thingsboard.server.common.data.kv.LongDataEntry;
import org.thingsboard.server.common.data.kv.StringDataEntry;
import org.thingsboard.server.common.msg.core.AttributesUpdateRequest;
import org.thingsboard.server.common.msg.core.BasicAttributesUpdateRequest;
import org.thingsboard.server.common.msg.core.BasicRequest;
import org.thingsboard.server.common.msg.core.BasicTelemetryUploadRequest;
import org.thingsboard.server.common.msg.core.TelemetryUploadRequest;
import org.thingsboard.server.common.msg.core.ToDeviceRpcRequestMsg;
import org.thingsboard.server.common.msg.kv.AttributesKVMsg;
import org.thingsboard.server.gen.transport.TransportProtos;
import org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg;
@ -49,8 +43,12 @@ import org.thingsboard.server.gen.transport.TransportProtos.TsKvListProto;
import org.thingsboard.server.gen.transport.TransportProtos.TsKvProto;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@ -60,18 +58,6 @@ public class JsonConverter {
private static final String CAN_T_PARSE_VALUE = "Can't parse value: ";
private static final String DEVICE_PROPERTY = "device";
public static TelemetryUploadRequest convertToTelemetry(JsonElement jsonObject) throws JsonSyntaxException {
return convertToTelemetry(jsonObject, BasicRequest.DEFAULT_REQUEST_ID);
}
public static TelemetryUploadRequest convertToTelemetry(JsonElement jsonObject, long ts) throws JsonSyntaxException {
return convertToTelemetry(jsonObject, ts, BasicRequest.DEFAULT_REQUEST_ID);
}
public static TelemetryUploadRequest convertToTelemetry(JsonElement jsonObject, int requestId) throws JsonSyntaxException {
return convertToTelemetry(jsonObject, System.currentTimeMillis(), requestId);
}
public static PostTelemetryMsg convertToTelemetryProto(JsonElement jsonObject) throws JsonSyntaxException {
long systemTs = System.currentTimeMillis();
PostTelemetryMsg.Builder builder = PostTelemetryMsg.newBuilder();
@ -170,74 +156,11 @@ public class JsonConverter {
return result;
}
private static TelemetryUploadRequest convertToTelemetry(JsonElement jsonObject, long systemTs, int requestId) throws JsonSyntaxException {
BasicTelemetryUploadRequest request = new BasicTelemetryUploadRequest(requestId);
if (jsonObject.isJsonObject()) {
parseObject(request, systemTs, jsonObject);
} else if (jsonObject.isJsonArray()) {
jsonObject.getAsJsonArray().forEach(je -> {
if (je.isJsonObject()) {
parseObject(request, systemTs, je.getAsJsonObject());
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + je);
}
});
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + jsonObject);
}
return request;
}
public static TransportProtos.ToServerRpcRequestMsg convertToServerRpcRequest(JsonElement json, int requestId) throws JsonSyntaxException {
JsonObject object = json.getAsJsonObject();
return TransportProtos.ToServerRpcRequestMsg.newBuilder().setRequestId(requestId).setMethodName(object.get("method").getAsString()).setParams(GSON.toJson(object.get("params"))).build();
}
private static void parseObject(BasicTelemetryUploadRequest request, long systemTs, JsonElement jsonObject) {
JsonObject jo = jsonObject.getAsJsonObject();
if (jo.has("ts") && jo.has("values")) {
parseWithTs(request, jo);
} else {
parseWithoutTs(request, systemTs, jo);
}
}
private static void parseWithoutTs(BasicTelemetryUploadRequest request, long systemTs, JsonObject jo) {
for (KvEntry entry : parseValues(jo)) {
request.add(systemTs, entry);
}
}
public static void parseWithTs(BasicTelemetryUploadRequest request, JsonObject jo) {
long ts = jo.get("ts").getAsLong();
JsonObject valuesObject = jo.get("values").getAsJsonObject();
for (KvEntry entry : parseValues(valuesObject)) {
request.add(ts, entry);
}
}
public static List<KvEntry> parseValues(JsonObject valuesObject) {
List<KvEntry> result = new ArrayList<>();
for (Entry<String, JsonElement> valueEntry : valuesObject.entrySet()) {
JsonElement element = valueEntry.getValue();
if (element.isJsonPrimitive()) {
JsonPrimitive value = element.getAsJsonPrimitive();
if (value.isString()) {
result.add(new StringDataEntry(valueEntry.getKey(), value.getAsString()));
} else if (value.isBoolean()) {
result.add(new BooleanDataEntry(valueEntry.getKey(), value.getAsBoolean()));
} else if (value.isNumber()) {
parseNumericValue(result, valueEntry, value);
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + value);
}
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + element);
}
}
return result;
}
private static void parseNumericValue(List<KvEntry> result, Entry<String, JsonElement> valueEntry, JsonPrimitive value) {
if (value.getAsString().contains(".")) {
result.add(new DoubleDataEntry(valueEntry.getKey(), value.getAsDouble()));
@ -251,21 +174,6 @@ public class JsonConverter {
}
}
public static AttributesUpdateRequest convertToAttributes(JsonElement element) {
return convertToAttributes(element, BasicRequest.DEFAULT_REQUEST_ID);
}
public static AttributesUpdateRequest convertToAttributes(JsonElement element, int requestId) {
if (element.isJsonObject()) {
BasicAttributesUpdateRequest request = new BasicAttributesUpdateRequest(requestId);
long ts = System.currentTimeMillis();
request.add(parseValues(element.getAsJsonObject()).stream().map(kv -> new BaseAttributeKvEntry(kv, ts)).collect(Collectors.toList()));
return request;
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + element);
}
}
public static JsonObject toJson(GetAttributeResponseMsg payload) {
JsonObject result = new JsonObject();
if (payload.getClientAttributeListCount() > 0) {
@ -425,16 +333,6 @@ public class JsonConverter {
};
}
public static JsonObject toJson(ToDeviceRpcRequestMsg msg, boolean includeRequestId) {
JsonObject result = new JsonObject();
if (includeRequestId) {
result.addProperty("id", msg.getRequestId());
}
result.addProperty("method", msg.getMethod());
result.add("params", new JsonParser().parse(msg.getParams()));
return result;
}
public static JsonElement toJson(TransportProtos.ToServerRpcResponseMsg msg) {
if (StringUtils.isEmpty(msg.getError())) {
return new JsonParser().parse(msg.getPayload());
@ -457,4 +355,76 @@ public class JsonConverter {
result.add("data", JsonConverter.toJson(rpcRequest, true));
return result;
}
public static Set<AttributeKvEntry> convertToAttributes(JsonElement element) {
Set<AttributeKvEntry> result = new HashSet<>();
long ts = System.currentTimeMillis();
result.addAll(parseValues(element.getAsJsonObject()).stream().map(kv -> new BaseAttributeKvEntry(kv, ts)).collect(Collectors.toList()));
return result;
}
private static List<KvEntry> parseValues(JsonObject valuesObject) {
List<KvEntry> result = new ArrayList<>();
for (Entry<String, JsonElement> valueEntry : valuesObject.entrySet()) {
JsonElement element = valueEntry.getValue();
if (element.isJsonPrimitive()) {
JsonPrimitive value = element.getAsJsonPrimitive();
if (value.isString()) {
result.add(new StringDataEntry(valueEntry.getKey(), value.getAsString()));
} else if (value.isBoolean()) {
result.add(new BooleanDataEntry(valueEntry.getKey(), value.getAsBoolean()));
} else if (value.isNumber()) {
parseNumericValue(result, valueEntry, value);
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + value);
}
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + element);
}
}
return result;
}
public static Map<Long, List<KvEntry>> convertToTelemetry(JsonElement jsonObject, long systemTs) throws JsonSyntaxException {
Map<Long, List<KvEntry>> result = new HashMap<>();
if (jsonObject.isJsonObject()) {
parseObject(result, systemTs, jsonObject);
} else if (jsonObject.isJsonArray()) {
jsonObject.getAsJsonArray().forEach(je -> {
if (je.isJsonObject()) {
parseObject(result, systemTs, je.getAsJsonObject());
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + je);
}
});
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + jsonObject);
}
return result;
}
private static void parseObject(Map<Long, List<KvEntry>> result, long systemTs, JsonElement jsonObject) {
JsonObject jo = jsonObject.getAsJsonObject();
if (jo.has("ts") && jo.has("values")) {
parseWithTs(result, jo);
} else {
parseWithoutTs(result, systemTs, jo);
}
}
private static void parseWithoutTs(Map<Long, List<KvEntry>> result, long systemTs, JsonObject jo) {
for (KvEntry entry : parseValues(jo)) {
result.computeIfAbsent(systemTs, tmp -> new ArrayList<>()).add(entry);
}
}
public static void parseWithTs(Map<Long, List<KvEntry>> result, JsonObject jo) {
long ts = jo.get("ts").getAsLong();
JsonObject valuesObject = jo.get("values").getAsJsonObject();
for (KvEntry entry : parseValues(valuesObject)) {
result.computeIfAbsent(ts, tmp -> new ArrayList<>()).add(entry);
}
}
}

2
common/transport/src/main/java/org/thingsboard/server/common/transport/session/DeviceAwareSessionContext.java

@ -29,6 +29,8 @@ import java.util.UUID;
@Data
public abstract class DeviceAwareSessionContext implements SessionContext {
@Getter
protected final UUID sessionId;
@Getter
private volatile DeviceId deviceId;
@Getter

2
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbCopyAttributesToEntityViewNode.java

@ -84,7 +84,7 @@ public class TbCopyAttributesToEntityViewNode implements TbNode {
long endTime = entityView.getEndTimeMs();
if ((endTime != 0 && endTime > now && startTime < now) || (endTime == 0 && startTime < now)) {
Set<AttributeKvEntry> attributes =
JsonConverter.convertToAttributes(new JsonParser().parse(msg.getData())).getAttributes();
JsonConverter.convertToAttributes(new JsonParser().parse(msg.getData()));
List<AttributeKvEntry> filteredAttributes =
attributes.stream()
.filter(attr -> {

2
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNode.java

@ -63,7 +63,7 @@ public class TbMsgAttributesNode implements TbNode {
}
String src = msg.getData();
Set<AttributeKvEntry> attributes = JsonConverter.convertToAttributes(new JsonParser().parse(src)).getAttributes();
Set<AttributeKvEntry> attributes = JsonConverter.convertToAttributes(new JsonParser().parse(src));
ctx.getTelemetryService().saveAndNotify(msg.getOriginator(), config.getScope(), new ArrayList<>(attributes), new TelemetryNodeCallback(ctx, msg));
if (msg.getOriginator().getEntityType() == EntityType.DEVICE && DataConstants.SHARED_SCOPE.equals(config.getScope())) {
ctx.getTelemetryService().onSharedAttributesUpdate(ctx.getTenantId(), new DeviceId(msg.getOriginator().getId()), attributes);

7
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgTimeseriesNode.java

@ -29,7 +29,6 @@ import org.thingsboard.server.common.data.kv.KvEntry;
import org.thingsboard.server.common.data.kv.TsKvEntry;
import org.thingsboard.server.common.data.plugin.ComponentType;
import org.thingsboard.server.common.msg.TbMsg;
import org.thingsboard.server.common.msg.core.TelemetryUploadRequest;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.transport.adaptor.JsonConverter;
@ -68,13 +67,13 @@ public class TbMsgTimeseriesNode implements TbNode {
if (!StringUtils.isEmpty(tsStr)) {
try {
ts = Long.parseLong(tsStr);
} catch (NumberFormatException e) {}
} catch (NumberFormatException e) {
}
} else {
ts = System.currentTimeMillis();
}
String src = msg.getData();
TelemetryUploadRequest telemetryUploadRequest = JsonConverter.convertToTelemetry(new JsonParser().parse(src), ts);
Map<Long, List<KvEntry>> tsKvMap = telemetryUploadRequest.getData();
Map<Long, List<KvEntry>> tsKvMap = JsonConverter.convertToTelemetry(new JsonParser().parse(src), ts);
if (tsKvMap == null) {
ctx.tellFailure(msg, new IllegalArgumentException("Msg body is empty: " + src));
return;

6
transport/coap/src/main/java/org/thingsboard/server/transport/coap/adaptors/JsonCoapAdaptor.java

@ -17,7 +17,6 @@ package org.thingsboard.server.transport.coap.adaptors;
import java.util.*;
import com.google.gson.JsonElement;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.californium.core.coap.CoAP.ResponseCode;
import org.eclipse.californium.core.coap.Request;
@ -25,13 +24,8 @@ import org.eclipse.californium.core.coap.Response;
import org.springframework.util.StringUtils;
import org.thingsboard.server.common.msg.core.*;
import org.thingsboard.server.common.msg.kv.AttributesKVMsg;
import org.thingsboard.server.common.msg.session.AdaptorToSessionActorMsg;
import org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.msg.session.SessionActorToAdaptorMsg;
import org.thingsboard.server.common.msg.session.SessionContext;
import org.thingsboard.server.common.msg.session.ToDeviceMsg;
import org.thingsboard.server.common.msg.session.ex.ProcessingTimeoutException;
import org.thingsboard.server.common.transport.adaptor.AdaptorException;
import org.thingsboard.server.common.transport.adaptor.JsonConverter;

4
transport/coap/src/main/java/org/thingsboard/server/transport/coap/session/CoapSessionCtx.java

@ -20,10 +20,6 @@ import org.eclipse.californium.core.coap.CoAP.ResponseCode;
import org.eclipse.californium.core.coap.Request;
import org.eclipse.californium.core.coap.Response;
import org.eclipse.californium.core.server.resources.CoapExchange;
import org.thingsboard.server.common.msg.session.SessionActorToAdaptorMsg;
import org.thingsboard.server.common.msg.session.SessionCtrlMsg;
import org.thingsboard.server.common.msg.session.SessionType;
import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg;
import org.thingsboard.server.common.msg.session.ex.SessionException;
import org.thingsboard.server.common.transport.SessionMsgProcessor;
import org.thingsboard.server.common.transport.adaptor.AdaptorException;

11
transport/coap/src/test/java/org/thingsboard/server/transport/coap/CoapServerTest.java

@ -34,26 +34,15 @@ import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry;
import org.thingsboard.server.common.data.kv.LongDataEntry;
import org.thingsboard.server.common.data.kv.StringDataEntry;
import org.thingsboard.server.common.data.security.DeviceCredentialsFilter;
import org.thingsboard.server.common.data.security.DeviceCredentialsType;
import org.thingsboard.server.common.data.security.DeviceTokenCredentials;
import org.thingsboard.server.common.msg.aware.SessionAwareMsg;
import org.thingsboard.server.common.msg.core.BasicGetAttributesResponse;
import org.thingsboard.server.common.msg.core.BasicRequest;
import org.thingsboard.server.common.msg.core.BasicStatusCodeResponse;
import org.thingsboard.server.common.msg.kv.BasicAttributeKVMsg;
import org.thingsboard.server.common.msg.session.*;
import org.thingsboard.server.common.transport.SessionMsgProcessor;
import org.thingsboard.server.common.transport.auth.DeviceAuthResult;
import org.thingsboard.server.common.transport.auth.DeviceAuthService;
import org.thingsboard.server.common.transport.quota.host.HostRequestsQuotaService;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

14
transport/http/src/main/java/org/thingsboard/server/transport/http/DeviceApiController.java

@ -15,34 +15,20 @@
*/
package org.thingsboard.server.transport.http;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;
import org.thingsboard.server.common.data.security.DeviceTokenCredentials;
import org.thingsboard.server.common.msg.core.*;
import org.thingsboard.server.common.msg.session.AdaptorToSessionActorMsg;
import org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg;
import org.thingsboard.server.common.msg.session.BasicTransportToDeviceSessionActorMsg;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.common.transport.SessionMsgProcessor;
import org.thingsboard.server.common.transport.adaptor.JsonConverter;
import org.thingsboard.server.common.transport.auth.DeviceAuthService;
import org.thingsboard.server.common.transport.quota.QuotaService;
import org.thingsboard.server.common.transport.quota.host.HostRequestsQuotaService;
import org.thingsboard.server.transport.http.session.HttpSessionCtx;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* @author Andrew Shvayka

8
transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportContext.java

@ -1,12 +1,12 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

8
transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java

@ -1,12 +1,12 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

8
transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/adaptors/JsonMqttAdaptor.java

@ -1,12 +1,12 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

56
transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/session/DeviceSessionCtx.java

@ -1,12 +1,12 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,13 +16,9 @@
package org.thingsboard.server.transport.mqtt.session;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.mqtt.*;
import io.netty.handler.codec.mqtt.MqttMessage;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.thingsboard.server.common.msg.session.SessionActorToAdaptorMsg;
import org.thingsboard.server.common.msg.session.SessionCtrlMsg;
import org.thingsboard.server.common.msg.session.SessionType;
import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg;
import org.thingsboard.server.common.msg.session.ex.SessionException;
import org.thingsboard.server.common.transport.adaptor.AdaptorException;
@ -36,29 +32,12 @@ import java.util.concurrent.atomic.AtomicInteger;
@Slf4j
public class DeviceSessionCtx extends MqttDeviceAwareSessionContext {
private final UUID sessionId;
@Getter
private ChannelHandlerContext channel;
private AtomicInteger msgIdSeq = new AtomicInteger(0);
public DeviceSessionCtx(UUID sessionId, ConcurrentMap<String, Integer> mqttQoSMap) {
super(null, null, mqttQoSMap);
this.sessionId = sessionId;
}
@Override
public SessionType getSessionType() {
return SessionType.ASYNC;
}
@Override
public void onMsg(SessionActorToAdaptorMsg msg) throws SessionException {
// try {
// adaptor.convertToAdaptorMsg(this, msg).ifPresent(this::pushToNetwork);
// } catch (AdaptorException e) {
// //TODO: close channel with disconnect;
// logAndWrap(e);
// }
super(sessionId, mqttQoSMap);
}
private void logAndWrap(AdaptorException e) throws SessionException {
@ -70,29 +49,6 @@ public class DeviceSessionCtx extends MqttDeviceAwareSessionContext {
channel.writeAndFlush(msg);
}
@Override
public void onMsg(SessionCtrlMsg msg) throws SessionException {
if (msg instanceof SessionCloseMsg) {
pushToNetwork(new MqttMessage(new MqttFixedHeader(MqttMessageType.DISCONNECT, false, MqttQoS.AT_MOST_ONCE, false, 0)));
channel.close();
}
}
@Override
public boolean isClosed() {
return false;
}
@Override
public long getTimeout() {
return 0;
}
@Override
public UUID getSessionId() {
return sessionId;
}
public void setChannel(ChannelHandlerContext channel) {
this.channel = channel;
}

12
transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/session/GatewayDeviceSessionCtx.java

@ -1,12 +1,12 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -31,13 +31,11 @@ import java.util.concurrent.ConcurrentMap;
public class GatewayDeviceSessionCtx extends MqttDeviceAwareSessionContext implements SessionMsgListener {
private final GatewaySessionCtx parent;
private final UUID sessionId;
private final SessionInfoProto sessionInfo;
public GatewayDeviceSessionCtx(GatewaySessionCtx parent, DeviceInfoProto deviceInfo, ConcurrentMap<String, Integer> mqttQoSMap) {
super(mqttQoSMap);
super(UUID.randomUUID(), mqttQoSMap);
this.parent = parent;
this.sessionId = UUID.randomUUID();
this.sessionInfo = SessionInfoProto.newBuilder()
.setNodeId(parent.getNodeId())
.setSessionIdMSB(sessionId.getMostSignificantBits())

8
transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/session/GatewaySessionCtx.java

@ -1,12 +1,12 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

5
transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/session/MqttDeviceAwareSessionContext.java

@ -22,6 +22,7 @@ import org.thingsboard.server.common.transport.auth.DeviceAuthService;
import org.thingsboard.server.common.transport.session.DeviceAwareSessionContext;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
/**
@ -31,8 +32,8 @@ public abstract class MqttDeviceAwareSessionContext extends DeviceAwareSessionCo
private final ConcurrentMap<String, Integer> mqttQoSMap;
public MqttDeviceAwareSessionContext(ConcurrentMap<String, Integer> mqttQoSMap) {
super();
public MqttDeviceAwareSessionContext(UUID sessionId, ConcurrentMap<String, Integer> mqttQoSMap) {
super(sessionId);
this.mqttQoSMap = mqttQoSMap;
}

60
transport/mqtt-common/src/main/java/org/thingsboard/server/transport/mqtt/session/MqttSessionId.java

@ -1,60 +0,0 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.transport.mqtt.session;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author Andrew Shvayka
*/
public class MqttSessionId implements SessionId {
private static final AtomicLong idSeq = new AtomicLong();
private final long id;
public MqttSessionId() {
this.id = idSeq.incrementAndGet();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MqttSessionId that = (MqttSessionId) o;
return id == that.id;
}
@Override
public String toString() {
return "MqttSessionId{" +
"id=" + id +
'}';
}
@Override
public int hashCode() {
return (int) (id ^ (id >>> 32));
}
@Override
public String toUidStr() {
return "mqtt" + id;
}
}

10
transport/mqtt-transport/src/main/java/org/thingsboard/server/mqtt/service/MqttTransportService.java

@ -1,12 +1,12 @@
/**
* Copyright © 2016-2018 The Thingsboard Authors
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -231,7 +231,7 @@ public class MqttTransportService implements TransportService {
@Override
public void process(GetOrCreateDeviceFromGatewayRequestMsg msg, TransportServiceCallback<GetOrCreateDeviceFromGatewayResponseMsg> callback) {
AsyncCallbackTemplate.withCallback(transportApiTemplate.post(msg.getTenantIdMSB() + msg.getTenantIdLSB() + msg.getDeviceName(),
AsyncCallbackTemplate.withCallback(transportApiTemplate.post(msg.getDeviceName(),
TransportApiRequestMsg.newBuilder().setGetOrCreateDeviceRequestMsg(msg).build()),
response -> callback.onSuccess(response.getGetOrCreateDeviceResponseMsg()), callback::onError, transportCallbackExecutor);
}

4
transport/pom.xml

@ -35,8 +35,8 @@
</properties>
<modules>
<module>http</module>
<module>coap</module>
<!--<module>http</module>-->
<!--<module>coap</module>-->
<module>mqtt-common</module>
<module>mqtt-transport</module>
</modules>

Loading…
Cancel
Save