-
Notifications
You must be signed in to change notification settings - Fork 407
Dynamic awake time for Queue mode
In this page it is explained how to create a dynamic awake time provider, where the client awake time is not fixed since the beginning. The client specifies this time as an attribute in the update message. Leshan saves all the additional parameters that comes in the registration/update messages as a Map
called additionalRegistrationAttributes
.
The ClientAwakeTimeProvider
API provides an interface that can be used to provide this dynamic provider. This API contains the method getClientAwakeTime(Registration reg)
which takes a Registration
object as a parameter, and returns the corresponding awake time for that client. Therefore, the additionalRegistrationAttributes
can be taken from the Registration
object, and the awake time attribute can be read, like:
clientAwakeTime = Integer.valueOf(reg.getAdditionalRegistrationAttributes().get("at"));
This additional attributes will be updated with the update messages (implemented in #481), and therefore the client can change the awake time dynamically.
Then, the class implementing this dynamic awake time provider will look like:
public class DynamicClientAwakeTimeProvider implements ClientAwakeTimeProvider {
int clientAwakeTime;
public DynamicClientAwakeTimeProvider() {
this.clientAwakeTime = 93000;
}
public DynamicClientAwakeTimeProvider(int defaultClientAwakeTime) {
this.clientAwakeTime = defaultClientAwakeTime;
}
@Override
public int getClientAwakeTime(Registration reg) {
if (reg.getAdditionalRegistrationAttributes().containsKey("at")) {
this.clientAwakeTime = Integer.valueOf(reg.getAdditionalRegistrationAttributes().get("at"));
}
// Returns the last awake time that was included in the registration message. If no awake time was ever included
// in this message, returns the default one.
return this.clientAwakeTime;
}
}
See also #1397-comment-1422371246 for more information about this.
All contributions you make to our web site (including this wiki) are governed by our Terms of Use, so please take the time to actually read it. Your interactions with the Eclipse Foundation web properties and any information you may provide us about yourself are governed by our Privacy Policy.