Skip to content

Commit

Permalink
Use session in bootstrap request sender.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Nov 14, 2019
1 parent 1205159 commit 7baf5b6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import org.eclipse.leshan.core.node.codec.LwM2mNodeDecoder;
import org.eclipse.leshan.core.node.codec.LwM2mNodeEncoder;
import org.eclipse.leshan.core.request.DownlinkRequest;
import org.eclipse.leshan.core.request.Identity;
import org.eclipse.leshan.core.response.ErrorCallback;
import org.eclipse.leshan.core.response.LwM2mResponse;
import org.eclipse.leshan.core.response.ResponseCallback;
import org.eclipse.leshan.server.bootstrap.BootstrapSession;
import org.eclipse.leshan.server.bootstrap.LwM2mBootstrapRequestSender;
import org.eclipse.leshan.server.californium.request.RequestSender;
import org.slf4j.Logger;
Expand All @@ -44,16 +44,21 @@ public CaliforniumLwM2mBootstrapRequestSender(Endpoint secureEndpoint, Endpoint
}

@Override
public <T extends LwM2mResponse> T send(final String endpointName, final Identity destination,
final DownlinkRequest<T> request, long timeout) throws InterruptedException {
return sender.sendLwm2mRequest(endpointName, destination, null, model, null, request, timeout);
public <T extends LwM2mResponse> T send(BootstrapSession destination, DownlinkRequest<T> request, long timeout)
throws InterruptedException {
return sender.sendLwm2mRequest(destination.getEndpoint(), destination.getIdentity(), destination.getId(), model,
null, request, timeout);
}

@Override
public <T extends LwM2mResponse> void send(final String endpointName, final Identity destination,
final DownlinkRequest<T> request, final long timeout, ResponseCallback<T> responseCallback,
ErrorCallback errorCallback) {
sender.sendLwm2mRequest(endpointName, destination, null, model, null, request, timeout, responseCallback,
errorCallback);
public <T extends LwM2mResponse> void send(BootstrapSession destination, DownlinkRequest<T> request, long timeout,
ResponseCallback<T> responseCallback, ErrorCallback errorCallback) {
sender.sendLwm2mRequest(destination.getEndpoint(), destination.getIdentity(), destination.getId(), model, null,
request, timeout, responseCallback, errorCallback);
}

@Override
public void cancelOngoingRequests(BootstrapSession destination) {
sender.cancelRequests(destination.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,7 @@ protected void afterBootstrapFinished(BootstrapSession session, BootstrapConfig

protected <T extends LwM2mResponse> void send(BootstrapSession session, DownlinkRequest<T> request,
ResponseCallback<T> responseCallback, ErrorCallback errorCallback) {
sender.send(session.getEndpoint(), session.getIdentity(), request, requestTimeout, responseCallback,
errorCallback);
sender.send(session, request, requestTimeout, responseCallback, errorCallback);
}

protected abstract class SafeResponseCallback<T extends LwM2mResponse> implements ResponseCallback<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.eclipse.leshan.server.bootstrap;

import org.eclipse.leshan.core.request.DownlinkRequest;
import org.eclipse.leshan.core.request.Identity;
import org.eclipse.leshan.core.response.ErrorCallback;
import org.eclipse.leshan.core.response.LwM2mResponse;
import org.eclipse.leshan.core.response.ResponseCallback;
Expand All @@ -28,12 +27,19 @@ public interface LwM2mBootstrapRequestSender {
* @return the LWM2M response. The response can be <code>null</code> if the timeout (given parameter or CoAP
* timeout) expires.
*/
<T extends LwM2mResponse> T send(String clientEndpoint, Identity client, DownlinkRequest<T> request, long timeout)
<T extends LwM2mResponse> T send(BootstrapSession destination, DownlinkRequest<T> request, long timeout)
throws InterruptedException;

/**
* Send a Lightweight M2M request asynchronously.
*/
<T extends LwM2mResponse> void send(String clientEndpoint, Identity client, DownlinkRequest<T> request,
long timeout, ResponseCallback<T> responseCallback, ErrorCallback errorCallback);
<T extends LwM2mResponse> void send(BootstrapSession destination, DownlinkRequest<T> request, long timeout,
ResponseCallback<T> responseCallback, ErrorCallback errorCallback);

/**
* cancel all ongoing requests for a given bootstrap session.
*
* @param session the bootstrap session for which we need to cancel requests.
*/
void cancelOngoingRequests(BootstrapSession session);
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ public MockRequestSender(Mode mode) {
}

@Override
public <T extends LwM2mResponse> T send(String clientEndpoint, Identity destination, DownlinkRequest<T> request,
long timeout) throws InterruptedException {
public <T extends LwM2mResponse> T send(BootstrapSession session, DownlinkRequest<T> request, long timeout)
throws InterruptedException {
return null;
}

Expand All @@ -199,9 +199,8 @@ public void setMode(Mode mode) {

@SuppressWarnings("unchecked")
@Override
public <T extends LwM2mResponse> void send(String clientEndpoint, Identity destination,
DownlinkRequest<T> request, long timeout, ResponseCallback<T> responseCallback,
ErrorCallback errorCallback) {
public <T extends LwM2mResponse> void send(BootstrapSession session, DownlinkRequest<T> request, long timeout,
ResponseCallback<T> responseCallback, ErrorCallback errorCallback) {
// no response, no callback call
if (mode == Mode.NO_RESPONSE) {
return;
Expand Down Expand Up @@ -231,6 +230,10 @@ public <T extends LwM2mResponse> void send(String clientEndpoint, Identity desti
}
}
}

@Override
public void cancelOngoingRequests(BootstrapSession destination) {
}
}

private static class MockBootstrapSessionManager implements BootstrapSessionManager {
Expand Down

0 comments on commit 7baf5b6

Please sign in to comment.