-
Notifications
You must be signed in to change notification settings - Fork 405
/
DownlinkRequestSender.java
105 lines (100 loc) · 6 KB
/
DownlinkRequestSender.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*******************************************************************************
* Copyright (c) 2013-2015 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.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
* Bosch Software Innovations GmbH - extension of ticket based asynchronous call.
*******************************************************************************/
package org.eclipse.leshan.server.request;
import org.eclipse.leshan.core.node.codec.CodecException;
import org.eclipse.leshan.core.request.DownlinkRequest;
import org.eclipse.leshan.core.request.exception.ClientSleepingException;
import org.eclipse.leshan.core.request.exception.InvalidResponseException;
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.request.exception.TimeoutException;
import org.eclipse.leshan.core.request.exception.UnconnectedPeerException;
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.registration.Registration;
/**
* A {@link DownlinkRequestSender} is responsible to send LWM2M {@link DownlinkRequest} for a given
* {@link Registration}.
*/
public interface DownlinkRequestSender {
/**
* Send a Lightweight M2M request synchronously. Will block until a response is received from the remote server.
* <p>
* The synchronous way could block a thread during a long time so it is more recommended to use the asynchronous
* way.
*
* @param destination The {@link Registration} associate to the device we want to sent the request.
* @param request The request to send to the client.
* @param lowerLayerConfig to tweak lower layer request (e.g. coap request)
* @param timeoutInMs The global timeout to wait in milliseconds (see
* https://github.com/eclipse/leshan/wiki/Request-Timeout)
* @param <T> The expected type of the response received.
* @return the LWM2M response. The response can be <code>null</code> if the timeout expires (see
* https://github.com/eclipse/leshan/wiki/Request-Timeout).
*
* @throws CodecException if request payload can not be encoded.
* @throws InterruptedException if the thread was interrupted.
* @throws RequestRejectedException if the request is rejected by foreign peer.
* @throws RequestCanceledException if the request is cancelled.
* @throws SendFailedException if the request can not be sent. E.g. error at CoAP or DTLS/UDP layer.
* @throws InvalidResponseException if the response received is malformed.
* @throws UnconnectedPeerException if client is not connected (no dtls connection available).
* @throws ClientSleepingException if client is currently sleeping.
*/
<T extends LwM2mResponse> T send(Registration destination, DownlinkRequest<T> request,
LowerLayerConfig lowerLayerConfig, long timeoutInMs) throws InterruptedException;
/**
* Send a Lightweight M2M {@link DownlinkRequest} asynchronously to a LWM2M client.
*
* {@link ResponseCallback} and {@link ErrorCallback} are exclusively called.
*
* @param destination The {@link Registration} associate to the device we want to sent the request.
* @param request The request to send to the client.
* @param lowerLayerConfig to tweak lower layer request (e.g. coap request)
* @param timeoutInMs The global timeout to wait in milliseconds (see
* https://github.com/eclipse/leshan/wiki/Request-Timeout)
* @param responseCallback a callback called when a response is received (successful or error response). This
* callback MUST NOT be null.
* @param <T> The expected type of the response received.
* @param errorCallback a callback called when an error or exception occurred when response is received. It can be :
* <ul>
* <li>{@link RequestRejectedException} if the request is rejected by foreign peer.</li>
* <li>{@link RequestCanceledException} if the request is cancelled.</li>
* <li>{@link SendFailedException} if the request can not be sent. E.g. error at CoAP or DTLS/UDP layer.</li>
* <li>{@link InvalidResponseException} if the response received is malformed.</li>
* <li>{@link UnconnectedPeerException} if client is not connected (no dtls connection available).</li>
* <li>{@link ClientSleepingException} if client is currently sleeping.</li>
* <li>{@link TimeoutException} if the timeout expires (see
* https://github.com/eclipse/leshan/wiki/Request-Timeout).</li>
* <li>or any other RuntimeException for unexpected issue.
* </ul>
* This callback MUST NOT be null.
* @throws CodecException if request payload can not be encoded.
*/
<T extends LwM2mResponse> void send(Registration destination, DownlinkRequest<T> request,
LowerLayerConfig lowerLayerConfig, long timeoutInMs, ResponseCallback<T> responseCallback,
ErrorCallback errorCallback);
/**
* cancel all ongoing messages for a LWM2M client identified by the registration identifier. In case a client
* de-registers, the consumer can use this method to cancel all ongoing messages for the given client.
*
* @param registration client registration meta data of a LWM2M client.
*/
void cancelOngoingRequests(Registration registration);
}