Skip to content

Commit

Permalink
Add processing of onSendError callback.
Browse files Browse the repository at this point in the history
Report errors during send.

Signed-off-by: Achim Kraus <achim.kraus@bosch-si.com>
Also-by: Simon Bernard <sbernard@sierrawireless.com>
  • Loading branch information
Achim Kraus authored and sbernard31 committed Jan 5, 2018
1 parent 1a8cd91 commit 83ed30e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
Expand Up @@ -12,6 +12,9 @@
*
* Contributors:
* Sierra Wireless - initial API and implementation
* Achim Kraus (Bosch Software Innovations GmbH) - redirect onSendError
* to error callback.
* Simon Bernard - use specific exception for onSendError
*******************************************************************************/
package org.eclipse.leshan.core.californium;

Expand All @@ -25,6 +28,7 @@
import org.eclipse.californium.core.coap.Response;
import org.eclipse.leshan.core.request.exception.RequestCanceledException;
import org.eclipse.leshan.core.request.exception.RequestRejectedException;
import org.eclipse.leshan.core.request.exception.SendFailedException;
import org.eclipse.leshan.core.response.ErrorCallback;
import org.eclipse.leshan.core.response.LwM2mResponse;
import org.eclipse.leshan.core.response.ResponseCallback;
Expand Down Expand Up @@ -105,7 +109,7 @@ public void onReject() {
@Override
public void onSendError(Throwable error) {
cleaningTask.cancel(false);
errorCallback.onError(new Exception(String.format("Unable to send request %s", coapRequest.getURI()), error));
errorCallback.onError(new SendFailedException(error, "Unable to send request %s", coapRequest.getURI()));
}

private ScheduledExecutorService getExecutor() {
Expand Down
Expand Up @@ -12,6 +12,8 @@
*
* Contributors:
* Sierra Wireless - initial API and implementation
* Achim Kraus (Bosch Software Innovations GmbH) - set exception in onSendError
* Simon Bernard - use specific exception for onSendError
*******************************************************************************/
package org.eclipse.leshan.core.californium;

Expand All @@ -23,6 +25,7 @@
import org.eclipse.californium.core.coap.Request;
import org.eclipse.californium.core.coap.Response;
import org.eclipse.leshan.core.request.exception.RequestRejectedException;
import org.eclipse.leshan.core.request.exception.SendFailedException;
import org.eclipse.leshan.core.response.LwM2mResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -75,6 +78,12 @@ public void onReject() {
latch.countDown();
}

@Override
public void onSendError(Throwable error) {
exception.set(new SendFailedException(error, "Request %s cannot be sent", coapRequest, error.getMessage()));
latch.countDown();
}

public T waitForResponse() throws InterruptedException {
try {
boolean timeElapsed = false;
Expand Down
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2017 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Sierra Wireless - initial API and implementation
*******************************************************************************/
package org.eclipse.leshan.core.request.exception;

/**
* Thrown to indicate that the request has failed to be sent.
*/
public class SendFailedException extends RuntimeException {

private static final long serialVersionUID = 1L;

public SendFailedException() {
}

public SendFailedException(String m) {
super(m);
}

public SendFailedException(String m, Object... args) {
super(String.format(m, args));
}

public SendFailedException(Throwable e) {
super(e);
}

public SendFailedException(String m, Throwable e) {
super(m, e);
}

public SendFailedException(Throwable e, String m, Object... args) {
super(String.format(m, args), e);
}
}

0 comments on commit 83ed30e

Please sign in to comment.