-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1027: Add TaskProvider which provides requests to send during bootstrap
The DefaultBootstrapSessionManager delegates knowledge of requests to send to BootstrapTaskProvider. A SimpleBootstrapStoreTaskProvider use BootstrapConfigStore to know which requests must be sent from BootstrapConfig.
- Loading branch information
1 parent
0edf18c
commit e6f87b2
Showing
7 changed files
with
199 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...e/src/main/java/org/eclipse/leshan/server/bootstrap/BootstrapConfigStoreTaskProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 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 | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.server.bootstrap; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import org.eclipse.leshan.core.response.LwM2mResponse; | ||
|
||
/** | ||
* An implementation of {@link BootstrapTaskProvider} which use a {@link BootstrapConfigStore} to know which requests to | ||
* send during a {@link BootstrapSession}. | ||
*/ | ||
public class BootstrapConfigStoreTaskProvider implements BootstrapTaskProvider { | ||
|
||
private BootstrapConfigStore store; | ||
|
||
public BootstrapConfigStoreTaskProvider(BootstrapConfigStore store) { | ||
this.store = store; | ||
} | ||
|
||
@Override | ||
public Tasks getTasks(BootstrapSession session, List<LwM2mResponse> previousResponse) { | ||
|
||
BootstrapConfig config = store.get(session.getEndpoint(), session.getIdentity(), session); | ||
if (config == null) | ||
return null; | ||
|
||
Tasks tasks = new Tasks(); | ||
// create requests from config | ||
tasks.requestsToSend = BootstrapUtil.toRequests(config, session.getContentFormat()); | ||
|
||
// We add model for Security(0), Server(0) and ACL(2) which are the only one supported by BootstrapConfig | ||
// We use default 1.0 model as currently BootstrapConfig support only this model version (which should be | ||
// compatible with models of LWM2M v1.1 but without new resources) | ||
tasks.supportedObjects = new HashMap<>(); | ||
tasks.supportedObjects.put(0, "1.0"); | ||
tasks.supportedObjects.put(1, "1.0"); | ||
tasks.supportedObjects.put(2, "1.0"); | ||
|
||
return tasks; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/BootstrapTaskProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 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 | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.server.bootstrap; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.leshan.core.model.LwM2mModel; | ||
import org.eclipse.leshan.core.request.BootstrapDiscoverRequest; | ||
import org.eclipse.leshan.core.request.BootstrapDownlinkRequest; | ||
import org.eclipse.leshan.core.request.BootstrapWriteRequest; | ||
import org.eclipse.leshan.core.response.LwM2mResponse; | ||
|
||
/** | ||
* A class responsible to return tasks to do during a {@link BootstrapSession} | ||
* <p> | ||
* This class is used by {@link DefaultBootstrapSessionManager}. | ||
* <p> | ||
* {@link #getTasks(BootstrapSession, List)} must return requests to send to the client. During 1 session, | ||
* {@link #getTasks(BootstrapSession, List)} can be called several time. Responses received for first batch of requests | ||
* can be used to determine next request to send. E.g. first batch of Requests could be a | ||
* {@link BootstrapDiscoverRequest} or a BootstrapReadRequest and response can be used to determine which | ||
* {@link BootstrapWriteRequest} to Send. | ||
* | ||
* @see BootstrapConfigStoreTaskProvider | ||
*/ | ||
public interface BootstrapTaskProvider { | ||
|
||
/** | ||
* a batch of requests to send. | ||
* | ||
*/ | ||
public class Tasks { | ||
/** | ||
* the list of request to send | ||
*/ | ||
public List<BootstrapDownlinkRequest<? extends LwM2mResponse>> requestsToSend; | ||
|
||
/** | ||
* Object (with version) supported by the client. {@link LwM2mModel} needed to encode/decode payload of request | ||
* will be created from this data | ||
*/ | ||
public Map<Integer, String> supportedObjects; | ||
|
||
/** | ||
* if true {@link BootstrapTaskProvider#getTasks(BootstrapSession, List)} will not be called again for this | ||
* session | ||
*/ | ||
public boolean last = true; | ||
} | ||
|
||
/** | ||
* @param previousResponses a list of {@link LwM2mResponse} received from previous executed {@link Tasks}. It can be | ||
* <code>null</code> if this is the first call for this session. | ||
* @return next tasks to do (next requests to send), returning <code>null</code> means there is nothing to do with | ||
* this client. | ||
*/ | ||
Tasks getTasks(BootstrapSession session, List<LwM2mResponse> previousResponses); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters