Skip to content

Commit

Permalink
Fix #623 issue about observation reset by starting only one cleaningTask
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Dec 4, 2018
1 parent 3a565f8 commit 9b497b2
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public CoapAsyncRequestObserver(Request coapRequest, CoapResponseCallback respon

@Override
public void onResponse(Response coapResponse) {
LOG.debug("Received coap response: {}", coapResponse);
LOG.debug("Received coap response: {} for {}", coapResponse, coapRequest);
try {
cleaningTask.cancel(false);
responseCallback.onResponse(coapResponse);
Expand Down Expand Up @@ -104,13 +104,16 @@ public void onSendError(Throwable error) {

private synchronized void scheduleCleaningTask() {
if (!cancelled)
cleaningTask = getExecutor().schedule(new Runnable() {
@Override
public void run() {
responseTimedOut.set(true);
coapRequest.cancel();
}
}, timeoutInMs, TimeUnit.MILLISECONDS);
if (cleaningTask == null) {
LOG.trace("Schedule Cleaning Task for {}", coapRequest);
cleaningTask = getExecutor().schedule(new Runnable() {
@Override
public void run() {
responseTimedOut.set(true);
coapRequest.cancel();
}
}, timeoutInMs, TimeUnit.MILLISECONDS);
}
}

private synchronized void cancelCleaningTask() {
Expand Down

0 comments on commit 9b497b2

Please sign in to comment.