Skip to content

Commit

Permalink
Make easier to custom start & stop bootstrap in DefaultBootstrapHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Apr 2, 2019
1 parent 4ffc79c commit be20408
Showing 1 changed file with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ public BootstrapResponse bootstrap(Identity sender, BootstrapRequest request) {
e.execute(new Runnable() {
@Override
public void run() {
delete(session, cfg);
startBootstrap(session, cfg);
}
});

return BootstrapResponse.success();
}

protected void startBootstrap(BootstrapSession session, BootstrapConfig cfg) {
delete(session, cfg);
}

protected void delete(final BootstrapSession session, final BootstrapConfig cfg) {

final BootstrapDeleteRequest deleteRequest = new BootstrapDeleteRequest();
Expand Down Expand Up @@ -234,26 +238,31 @@ public void onError(Exception e) {
}
});
} else {
final BootstrapFinishRequest finishBootstrapRequest = new BootstrapFinishRequest();
send(session, finishBootstrapRequest, new ResponseCallback<BootstrapFinishResponse>() {
// we are done, send bootstrap finished.
bootstrapFinished(session, cfg);
}
}

@Override
public void onResponse(BootstrapFinishResponse response) {
LOG.trace("Bootstrap Finished {} return code {}", session.getEndpoint(), response.getCode());
if (response.isSuccess()) {
sessionManager.end(session);
} else {
sessionManager.failed(session, FINISHED_WITH_ERROR, finishBootstrapRequest);
}
}
}, new ErrorCallback() {
@Override
public void onError(Exception e) {
LOG.debug(String.format("Error during bootstrap finished on %s", session.getEndpoint()), e);
sessionManager.failed(session, SEND_FINISH_FAILED, finishBootstrapRequest);
protected void bootstrapFinished(final BootstrapSession session, final BootstrapConfig cfg) {

final BootstrapFinishRequest finishBootstrapRequest = new BootstrapFinishRequest();
send(session, finishBootstrapRequest, new ResponseCallback<BootstrapFinishResponse>() {
@Override
public void onResponse(BootstrapFinishResponse response) {
LOG.trace("Bootstrap Finished {} return code {}", session.getEndpoint(), response.getCode());
if (response.isSuccess()) {
sessionManager.end(session);
} else {
sessionManager.failed(session, FINISHED_WITH_ERROR, finishBootstrapRequest);
}
});
}
}
}, new ErrorCallback() {
@Override
public void onError(Exception e) {
LOG.debug(String.format("Error during bootstrap finished on %s", session.getEndpoint()), e);
sessionManager.failed(session, SEND_FINISH_FAILED, finishBootstrapRequest);
}
});
}

protected <T extends LwM2mResponse> void send(BootstrapSession session, DownlinkRequest<T> request,
Expand Down

0 comments on commit be20408

Please sign in to comment.