Skip to content

Commit 868f8b3

Browse files
committed
Add setTaskProvider to LeshanBootstrapServerBuilder
1 parent be79632 commit 868f8b3

File tree

1 file changed

+59
-19
lines changed

1 file changed

+59
-19
lines changed

leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/LeshanBootstrapServerBuilder.java

+59-19
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class LeshanBootstrapServerBuilder {
5151
private static final Logger LOG = LoggerFactory.getLogger(LeshanBootstrapServerBuilder.class);
5252

5353
private BootstrapConfigStore configStore;
54+
private BootstrapTaskProvider taskProvider;
5455
private BootstrapSecurityStore securityStore;
5556
private BootstrapSessionManager sessionManager;
5657
private BootstrapHandlerFactory bootstrapHandlerFactory;
@@ -127,7 +128,22 @@ public <T extends Certificate> LeshanBootstrapServerBuilder setTrustedCertificat
127128
}
128129

129130
/**
130-
* Set the {@link BootstrapConfigStore} containing bootstrap configuration to apply to each devices.
131+
* Set the {@link BootstrapTaskProvider} which should return task to do during a bootstrap session to each clients.
132+
* <p>
133+
* By default an {@link BootstrapConfigStoreTaskProvider} is used with given {@link BootstrapConfigStore}. See
134+
* {@link #setConfigStore(BootstrapConfigStore)}.
135+
*
136+
* @param taskProvider the bootstrap tasks provider.
137+
* @return the builder for fluent Bootstrap Server creation.
138+
*
139+
*/
140+
public LeshanBootstrapServerBuilder setTaskProvider(BootstrapTaskProvider taskProvider) {
141+
this.taskProvider = taskProvider;
142+
return this;
143+
}
144+
145+
/**
146+
* Set the {@link BootstrapConfigStore} containing bootstrap configuration to apply to each clients.
131147
* <p>
132148
* By default an {@link InMemoryBootstrapConfigStore} is used.
133149
* <p>
@@ -261,31 +277,55 @@ public BootstrapHandler create(BootstrapDownlinkRequestSender sender,
261277
return new DefaultBootstrapHandler(sender, sessionManager, listener);
262278
}
263279
};
264-
if (configStore == null) {
265-
configStore = new InMemoryBootstrapConfigStore();
266-
} else if (sessionManager != null) {
267-
LOG.warn("configStore is set but you also provide a custom SessionManager so this store will not be used");
268-
}
269-
if (modelProvider == null) {
270-
modelProvider = new StandardBootstrapModelProvider();
271-
} else if (sessionManager != null) {
272-
LOG.warn(
273-
"modelProvider is set but you also provide a custom SessionManager so this provider will not be used");
274-
}
275-
if (sessionManager == null) {
276-
SecurityChecker securityChecker = new SecurityChecker();
277-
if (authorizer == null)
278-
authorizer = new DefaultBootstrapAuthorizer(securityStore, securityChecker);
279-
sessionManager = new DefaultBootstrapSessionManager(new BootstrapConfigStoreTaskProvider(configStore),
280-
modelProvider, authorizer);
281-
}
280+
282281
if (encoder == null)
283282
encoder = new DefaultLwM2mEncoder();
284283
if (decoder == null)
285284
decoder = new DefaultLwM2mDecoder();
286285
if (linkParser == null)
287286
linkParser = new DefaultLwM2mLinkParser();
288287

288+
// Handle class depending of Session Manager
289+
if (sessionManager == null) {
290+
if (modelProvider == null) {
291+
modelProvider = new StandardBootstrapModelProvider();
292+
}
293+
if (authorizer == null) {
294+
SecurityChecker securityChecker = new SecurityChecker();
295+
authorizer = new DefaultBootstrapAuthorizer(securityStore, securityChecker);
296+
}
297+
298+
// Handle class depending of Task Provider
299+
if (taskProvider == null) {
300+
if (configStore == null) {
301+
configStore = new InMemoryBootstrapConfigStore();
302+
}
303+
taskProvider = new BootstrapConfigStoreTaskProvider(configStore);
304+
} else {
305+
if (configStore != null) {
306+
LOG.warn(
307+
"configStore is set but you also provide a custom TaskProvider so this store will not be used");
308+
}
309+
}
310+
sessionManager = new DefaultBootstrapSessionManager(taskProvider, modelProvider, authorizer);
311+
} else {
312+
if (taskProvider != null) {
313+
LOG.warn(
314+
"taskProvider is set but you also provide a custom SessionManager so this provider will not be used");
315+
}
316+
if (configStore != null) {
317+
LOG.warn(
318+
"configStore is set but you also provide a custom SessionManager so this store will not be used");
319+
}
320+
if (modelProvider != null) {
321+
LOG.warn(
322+
"modelProvider is set but you also provide a custom SessionManager so this provider will not be used");
323+
}
324+
if (authorizer != null) {
325+
LOG.warn(
326+
"authorizer is set but you also provide a custom SessionManager so this authorizer will not be used");
327+
}
328+
}
289329
return createBootstrapServer(endpointsProvider, sessionManager, bootstrapHandlerFactory, encoder, decoder,
290330
linkParser, securityStore,
291331
new ServerSecurityInfo(privateKey, publicKey, certificateChain, trustedCertificates));

0 commit comments

Comments
 (0)