@@ -51,6 +51,7 @@ public class LeshanBootstrapServerBuilder {
51
51
private static final Logger LOG = LoggerFactory .getLogger (LeshanBootstrapServerBuilder .class );
52
52
53
53
private BootstrapConfigStore configStore ;
54
+ private BootstrapTaskProvider taskProvider ;
54
55
private BootstrapSecurityStore securityStore ;
55
56
private BootstrapSessionManager sessionManager ;
56
57
private BootstrapHandlerFactory bootstrapHandlerFactory ;
@@ -127,7 +128,22 @@ public <T extends Certificate> LeshanBootstrapServerBuilder setTrustedCertificat
127
128
}
128
129
129
130
/**
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.
131
147
* <p>
132
148
* By default an {@link InMemoryBootstrapConfigStore} is used.
133
149
* <p>
@@ -261,31 +277,55 @@ public BootstrapHandler create(BootstrapDownlinkRequestSender sender,
261
277
return new DefaultBootstrapHandler (sender , sessionManager , listener );
262
278
}
263
279
};
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
+
282
281
if (encoder == null )
283
282
encoder = new DefaultLwM2mEncoder ();
284
283
if (decoder == null )
285
284
decoder = new DefaultLwM2mDecoder ();
286
285
if (linkParser == null )
287
286
linkParser = new DefaultLwM2mLinkParser ();
288
287
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
+ }
289
329
return createBootstrapServer (endpointsProvider , sessionManager , bootstrapHandlerFactory , encoder , decoder ,
290
330
linkParser , securityStore ,
291
331
new ServerSecurityInfo (privateKey , publicKey , certificateChain , trustedCertificates ));
0 commit comments