Skip to content

Commit

Permalink
mark response as sent just after "exchange.respond"
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Feb 3, 2017
1 parent 03aa641 commit 3155c31
Showing 1 changed file with 3 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,6 @@ private void handleRegister(CoapExchange exchange, Request request) {
registerRequest, serverEndpoint);
RegisterResponse response = sendableResponse.getResponse();

// Mark the response as sended when the exchange is complete
exchange.advanced().setObserver(new ExchangeObserverAdapter() {
@Override
public void completed(Exchange exchange) {
sendableResponse.sent();

}
});

// Create CoAP Response from LwM2m request
// -------------------------------
if (response.getCode() == org.eclipse.leshan.ResponseCode.CREATED) {
Expand All @@ -209,6 +200,7 @@ public void completed(Exchange exchange) {
} else {
exchange.respond(fromLwM2mCode(response.getCode()), response.getErrorMessage());
}
sendableResponse.sent();
}

private void handleUpdate(CoapExchange exchange, Request request, String registrationId) {
Expand Down Expand Up @@ -238,16 +230,9 @@ private void handleUpdate(CoapExchange exchange, Request request, String registr
final SendableResponse<UpdateResponse> sendableResponse = registrationHandler.update(sender, updateRequest);
UpdateResponse updateResponse = sendableResponse.getResponse();

// Mark the response as sended when the exchange is complete
exchange.advanced().setObserver(new ExchangeObserverAdapter() {
@Override
public void completed(Exchange exchange) {
sendableResponse.sent();
}
});

// Create CoAP Response from LwM2m request
exchange.respond(fromLwM2mCode(updateResponse.getCode()), updateResponse.getErrorMessage());
sendableResponse.sent();
}

private void handleDeregister(CoapExchange exchange, String registrationId) {
Expand All @@ -262,16 +247,9 @@ private void handleDeregister(CoapExchange exchange, String registrationId) {
deregisterRequest);
DeregisterResponse deregisterResponse = sendableResponse.getResponse();

// Mark the response as sended when the exchange is complete
exchange.advanced().setObserver(new ExchangeObserverAdapter() {
@Override
public void completed(Exchange exchange) {
sendableResponse.sent();
}
});

// Create CoAP Response from LwM2m request
exchange.respond(fromLwM2mCode(deregisterResponse.getCode()), deregisterResponse.getErrorMessage());
sendableResponse.sent();
}

// Since the V1_0-20150615-D version of specification, the registration update should be a CoAP POST.
Expand Down

0 comments on commit 3155c31

Please sign in to comment.