Skip to content

Commit

Permalink
Add bootstrapSession parameter to Success and failure callback
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jul 19, 2019
1 parent d3ab4e0 commit 3f0e136
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,34 @@ public enum BootstrapPolicy {
/**
* Called when we receive a successful response to a request.
*
* @param bsSession the bootstrap session concerned.
* @param request The request for which we get a successfull response.
*/
public void onResponseSuccess(LwM2mRequest<? extends LwM2mResponse> request);
public void onResponseSuccess(BootstrapSession bsSession, LwM2mRequest<? extends LwM2mResponse> request);

/**
* Called when we receive a error response to a request.
*
* @param bsSession the bootstrap session concerned.
* @param request The request for which we get a error response.
* @param response The response received.
*
* @return a {@link BootstrapPolicy} given the way to continue the bootstrap session.
*/
public BootstrapPolicy onResponseError(LwM2mRequest<? extends LwM2mResponse> request, LwM2mResponse response);
public BootstrapPolicy onResponseError(BootstrapSession bsSession, LwM2mRequest<? extends LwM2mResponse> request,
LwM2mResponse response);

/**
* Called when a request failed to be sent.
*
* @param bsSession the bootstrap session concerned.
* @param request The request which failed to be sent.
* @param exception The cause of the failure. Can be null.
*
* @return a {@link BootstrapPolicy} given the way to continue the bootstrap session.
*/
public BootstrapPolicy onRequestFailure(LwM2mRequest<? extends LwM2mResponse> request, Throwable cause);
public BootstrapPolicy onRequestFailure(BootstrapSession bsSession, LwM2mRequest<? extends LwM2mResponse> request,
Throwable cause);

/**
* Performs any housekeeping related to the successful ending of a Bootstrapping session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,19 @@ protected void delete(final BootstrapSession session, final BootstrapConfig cfg,
public void safeOnResponse(BootstrapDeleteResponse response) {
if (response.isSuccess()) {
LOG.trace("{} receives {} for {}", session, response, deleteRequest);
sessionManager.onResponseSuccess(deleteRequest);
sessionManager.onResponseSuccess(session, deleteRequest);
afterDelete(session, cfg, pathToDelete, BootstrapPolicy.CONTINUE);
} else {
LOG.debug("{} receives {} for {}", session, response, deleteRequest);
BootstrapPolicy policy = sessionManager.onResponseError(deleteRequest, response);
BootstrapPolicy policy = sessionManager.onResponseError(session, deleteRequest, response);
afterDelete(session, cfg, pathToDelete, policy);
}
}
}, new SafeErrorCallback(session) {
@Override
public void safeOnError(Exception e) {
LOG.debug("Error for {} while sending {} ", session, deleteRequest, e);
BootstrapPolicy policy = sessionManager.onRequestFailure(deleteRequest, e);
BootstrapPolicy policy = sessionManager.onRequestFailure(session, deleteRequest, e);
afterDelete(session, cfg, pathToDelete, policy);
}
});
Expand Down Expand Up @@ -232,19 +232,20 @@ protected void writeSecurities(final BootstrapSession session, final BootstrapCo
public void safeOnResponse(BootstrapWriteResponse response) {
if (response.isSuccess()) {
LOG.trace("{} receives {} for {}", session, response, writeBootstrapRequest);
sessionManager.onResponseSuccess(writeBootstrapRequest);
sessionManager.onResponseSuccess(session, writeBootstrapRequest);
afterWriteSecurities(session, cfg, securityInstancesToWrite, BootstrapPolicy.CONTINUE);
} else {
LOG.debug("{} receives {} for {}", session, response, writeBootstrapRequest);
BootstrapPolicy policy = sessionManager.onResponseError(writeBootstrapRequest, response);
BootstrapPolicy policy = sessionManager.onResponseError(session, writeBootstrapRequest,
response);
afterWriteSecurities(session, cfg, securityInstancesToWrite, policy);
}
}
}, new SafeErrorCallback(session) {
@Override
public void safeOnError(Exception e) {
LOG.debug("Error for {} while sending {} ", session, writeBootstrapRequest, e);
BootstrapPolicy policy = sessionManager.onRequestFailure(writeBootstrapRequest, e);
BootstrapPolicy policy = sessionManager.onRequestFailure(session, writeBootstrapRequest, e);
afterWriteSecurities(session, cfg, securityInstancesToWrite, policy);
}
});
Expand Down Expand Up @@ -298,19 +299,19 @@ protected void writeServers(final BootstrapSession session, final BootstrapConfi
public void safeOnResponse(BootstrapWriteResponse response) {
if (response.isSuccess()) {
LOG.trace("{} receives {} for {}", session, response, writeServerRequest);
sessionManager.onResponseSuccess(writeServerRequest);
sessionManager.onResponseSuccess(session, writeServerRequest);
afterWriteServers(session, cfg, serverInstancesToWrite, BootstrapPolicy.CONTINUE);
} else {
LOG.debug("{} receives {} for {}", session, response, writeServerRequest);
BootstrapPolicy policy = sessionManager.onResponseError(writeServerRequest, response);
BootstrapPolicy policy = sessionManager.onResponseError(session, writeServerRequest, response);
afterWriteServers(session, cfg, serverInstancesToWrite, policy);
}
}
}, new SafeErrorCallback(session) {
@Override
public void safeOnError(Exception e) {
LOG.debug("Error for {} while sending {} ", session, writeServerRequest, e);
BootstrapPolicy policy = sessionManager.onRequestFailure(writeServerRequest, e);
BootstrapPolicy policy = sessionManager.onRequestFailure(session, writeServerRequest, e);
afterWriteServers(session, cfg, serverInstancesToWrite, policy);
}
});
Expand Down Expand Up @@ -364,19 +365,19 @@ protected void writedAcls(final BootstrapSession session, final BootstrapConfig
public void safeOnResponse(BootstrapWriteResponse response) {
if (response.isSuccess()) {
LOG.trace("{} receives {} for {}", session, response, writeACLRequest);
sessionManager.onResponseSuccess(writeACLRequest);
sessionManager.onResponseSuccess(session, writeACLRequest);
afterWritedAcls(session, cfg, aclInstancesToWrite, BootstrapPolicy.CONTINUE);
} else {
LOG.debug("{} receives {} for {}", session, response, writeACLRequest);
BootstrapPolicy policy = sessionManager.onResponseError(writeACLRequest, response);
BootstrapPolicy policy = sessionManager.onResponseError(session, writeACLRequest, response);
afterWritedAcls(session, cfg, aclInstancesToWrite, policy);
}
}
}, new SafeErrorCallback(session) {
@Override
public void safeOnError(Exception e) {
LOG.debug("Error for {} while sending {} ", session, writeACLRequest, e);
BootstrapPolicy policy = sessionManager.onRequestFailure(writeACLRequest, e);
BootstrapPolicy policy = sessionManager.onRequestFailure(session, writeACLRequest, e);
afterWritedAcls(session, cfg, aclInstancesToWrite, policy);
}
});
Expand Down Expand Up @@ -418,19 +419,19 @@ protected void bootstrapFinished(final BootstrapSession session, final Bootstrap
public void safeOnResponse(BootstrapFinishResponse response) {
if (response.isSuccess()) {
LOG.trace("{} receives {} for {}", session, response, finishBootstrapRequest);
sessionManager.onResponseSuccess(finishBootstrapRequest);
sessionManager.onResponseSuccess(session, finishBootstrapRequest);
afterBootstrapFinished(session, cfg, BootstrapPolicy.CONTINUE);
} else {
LOG.debug("{} receives {} for {}", session, response, finishBootstrapRequest);
BootstrapPolicy policy = sessionManager.onResponseError(finishBootstrapRequest, response);
BootstrapPolicy policy = sessionManager.onResponseError(session, finishBootstrapRequest, response);
afterBootstrapFinished(session, cfg, policy);
}
}
}, new SafeErrorCallback(session) {
@Override
public void safeOnError(Exception e) {
LOG.debug("Error for {} while sending {} ", session, finishBootstrapRequest, e);
BootstrapPolicy policy = sessionManager.onRequestFailure(finishBootstrapRequest, e);
BootstrapPolicy policy = sessionManager.onRequestFailure(session, finishBootstrapRequest, e);
afterBootstrapFinished(session, cfg, policy);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,21 @@ public void failed(BootstrapSession bsSession, BootstrapFailureCause cause) {
}

@Override
public void onResponseSuccess(LwM2mRequest<? extends LwM2mResponse> request) {
public void onResponseSuccess(BootstrapSession bsSession, LwM2mRequest<? extends LwM2mResponse> request) {
}

@Override
public BootstrapPolicy onResponseError(LwM2mRequest<? extends LwM2mResponse> request, LwM2mResponse response) {
public BootstrapPolicy onResponseError(BootstrapSession bsSession, LwM2mRequest<? extends LwM2mResponse> request,
LwM2mResponse response) {
if (request instanceof BootstrapFinishRequest) {
return BootstrapPolicy.STOP;
}
return BootstrapPolicy.CONTINUE;
}

@Override
public BootstrapPolicy onRequestFailure(LwM2mRequest<? extends LwM2mResponse> request, Throwable cause) {
public BootstrapPolicy onRequestFailure(BootstrapSession bsSession, LwM2mRequest<? extends LwM2mResponse> request,
Throwable cause) {
return BootstrapPolicy.STOP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,22 @@ public void failed(BootstrapSession bsSession, BootstrapFailureCause cause) {
}

@Override
public void onResponseSuccess(LwM2mRequest<? extends LwM2mResponse> request) {
public void onResponseSuccess(BootstrapSession bsSession, LwM2mRequest<? extends LwM2mResponse> request) {

}

@Override
public BootstrapPolicy onResponseError(LwM2mRequest<? extends LwM2mResponse> request, LwM2mResponse response) {
public BootstrapPolicy onResponseError(BootstrapSession bsSession,
LwM2mRequest<? extends LwM2mResponse> request, LwM2mResponse response) {
if (request instanceof BootstrapFinishRequest) {
return BootstrapPolicy.STOP;
}
return BootstrapPolicy.CONTINUE;
}

@Override
public BootstrapPolicy onRequestFailure(LwM2mRequest<? extends LwM2mResponse> request, Throwable cause) {
public BootstrapPolicy onRequestFailure(BootstrapSession bsSession,
LwM2mRequest<? extends LwM2mResponse> request, Throwable cause) {
return BootstrapPolicy.STOP;
}

Expand Down

0 comments on commit 3f0e136

Please sign in to comment.