Commit b5da59e3b38e230ac50639020ab2c96b54cac5fa

Authored by YevhenBondarenko
1 parent 615f5173

fixed double sending rpc (private network)

@@ -117,6 +117,10 @@ public class LwM2mClient implements Serializable { @@ -117,6 +117,10 @@ public class LwM2mClient implements Serializable {
117 @Getter 117 @Getter
118 private final AtomicInteger retryAttempts; 118 private final AtomicInteger retryAttempts;
119 119
  120 + @Getter
  121 + @Setter
  122 + private Integer lastSentRpcId;
  123 +
120 public Object clone() throws CloneNotSupportedException { 124 public Object clone() throws CloneNotSupportedException {
121 return super.clone(); 125 return super.clone();
122 } 126 }
@@ -95,6 +95,9 @@ public class DefaultLwM2MRpcRequestHandler implements LwM2MRpcRequestHandler { @@ -95,6 +95,9 @@ public class DefaultLwM2MRpcRequestHandler implements LwM2MRpcRequestHandler {
95 this.sendErrorRpcResponse(sessionInfo, rpcRequest.getRequestId(), ResponseCode.INTERNAL_SERVER_ERROR, "Registration is empty"); 95 this.sendErrorRpcResponse(sessionInfo, rpcRequest.getRequestId(), ResponseCode.INTERNAL_SERVER_ERROR, "Registration is empty");
96 return; 96 return;
97 } 97 }
  98 + if (client.getLastSentRpcId() != null && client.getLastSentRpcId().equals(rpcRequest.getRequestId())) {
  99 + log.info("[{}] Rpc has already sent!", rpcRequest.getRequestId());
  100 + }
98 try { 101 try {
99 if (operationType.isHasObjectId()) { 102 if (operationType.isHasObjectId()) {
100 String objectId = getIdFromParameters(client, rpcRequest); 103 String objectId = getIdFromParameters(client, rpcRequest);
@@ -45,6 +45,7 @@ public abstract class RpcDownlinkRequestCallbackProxy<R, T> implements DownlinkR @@ -45,6 +45,7 @@ public abstract class RpcDownlinkRequestCallbackProxy<R, T> implements DownlinkR
45 45
46 @Override 46 @Override
47 public void onSent(R request) { 47 public void onSent(R request) {
  48 + client.setLastSentRpcId(this.request.getRequestId());
48 transportService.process(client.getSession(), this.request, RpcStatus.SENT, TransportServiceCallback.EMPTY); 49 transportService.process(client.getSession(), this.request, RpcStatus.SENT, TransportServiceCallback.EMPTY);
49 } 50 }
50 51
@@ -68,6 +69,7 @@ public abstract class RpcDownlinkRequestCallbackProxy<R, T> implements DownlinkR @@ -68,6 +69,7 @@ public abstract class RpcDownlinkRequestCallbackProxy<R, T> implements DownlinkR
68 @Override 69 @Override
69 public void onError(String params, Exception e) { 70 public void onError(String params, Exception e) {
70 if (e instanceof TimeoutException || e instanceof org.eclipse.leshan.core.request.exception.TimeoutException) { 71 if (e instanceof TimeoutException || e instanceof org.eclipse.leshan.core.request.exception.TimeoutException) {
  72 + client.setLastSentRpcId(null);
71 transportService.process(client.getSession(), this.request, RpcStatus.TIMEOUT, TransportServiceCallback.EMPTY); 73 transportService.process(client.getSession(), this.request, RpcStatus.TIMEOUT, TransportServiceCallback.EMPTY);
72 } else if (!(e instanceof ClientSleepingException)) { 74 } else if (!(e instanceof ClientSleepingException)) {
73 sendRpcReplyOnError(e); 75 sendRpcReplyOnError(e);