@@ -224,59 +224,6 @@ private int executeDeviceBatch(@NonNull IOConnection ioConnection,
224
224
return command_list .size ();
225
225
}
226
226
227
- private void startNetworkReceivers (boolean changed ) {
228
- // Get all ports of configured devices and add the additional_port if != 0
229
- Set <Integer > ports = dataService .connections .getAllUDPReceivePorts (this );
230
- ports .add (SharedPrefs .getInstance ().getDefaultReceivePort ());
231
-
232
- if (!changed && discoveryThreads .size () == ports .size ()) return ;
233
-
234
- boolean new_threads_started = false ;
235
- List <AnelReceiveUDP > unusedThreads = new ArrayList <>(discoveryThreads );
236
-
237
- StackTraceElement [] stacktrace = Thread .currentThread ().getStackTrace ();
238
- String methodName = stacktrace [3 ].getClassName () + ":" + stacktrace [3 ].getMethodName () + "->" + stacktrace [4 ].getClassName () + ":" + stacktrace [4 ].getMethodName ();
239
- Log .w (PLUGIN_ID , "startNetworkReceivers " + methodName );
240
-
241
- // Go through all ports and start a thread for it if none is running for it so far
242
- for (int port : ports ) {
243
- boolean already_running = false ;
244
- for (AnelReceiveUDP running_thread : discoveryThreads ) {
245
- if (running_thread .getPort () == port ) {
246
- already_running = true ;
247
- unusedThreads .remove (running_thread );
248
- break ;
249
- }
250
- }
251
-
252
- if (already_running ) {
253
- continue ;
254
- }
255
-
256
- new_threads_started = true ;
257
- AnelReceiveUDP thr = new AnelReceiveUDP (this , port );
258
- thr .start ();
259
- discoveryThreads .add (thr );
260
- }
261
-
262
- if (unusedThreads .size () > 0 ) {
263
- for (AnelReceiveUDP thr : unusedThreads ) {
264
- thr .interrupt ();
265
- discoveryThreads .remove (thr );
266
- }
267
- }
268
-
269
- if (new_threads_started ) {
270
- // give the threads a chance to start
271
- try {
272
- Thread .sleep (100 );
273
- } catch (InterruptedException ignored ) {
274
- }
275
- }
276
-
277
- HttpThreadPool .startHTTP ();
278
- }
279
-
280
227
private void stopNetwork () {
281
228
StackTraceElement [] stacktrace = Thread .currentThread ().getStackTrace ();
282
229
String methodName = stacktrace [3 ].getClassName () + ":" + stacktrace [3 ].getMethodName () + "->" + stacktrace [4 ].getClassName () + ":" + stacktrace [4 ].getMethodName ();
@@ -343,7 +290,7 @@ else if (command == Executable.TOGGLE)
343
290
}
344
291
return success ;
345
292
} else if (ioConnection instanceof IOConnectionUDP ) {
346
- final Credentials credentials = dataService .credentials . findByUID ( executable . deviceUID ) ;
293
+ final Credentials credentials = ioConnection .credentials ;
347
294
if (credentials == null ) {
348
295
Log .e (PLUGIN_ID , "execute. No credentials found!" );
349
296
if (callback != null ) callback .addFail ();
@@ -383,7 +330,56 @@ public void onDestroy() {
383
330
384
331
@ Override
385
332
public void onStart (Context context ) {
386
- startNetworkReceivers (true );
333
+ // Get all ports of configured devices and add the additional_port if != 0
334
+ Set <Integer > ports = dataService .connections .getAllUDPReceivePorts (this );
335
+ ports .add (SharedPrefs .getInstance ().getDefaultReceivePort ());
336
+
337
+ if (discoveryThreads .size () == ports .size ()) return ;
338
+
339
+ boolean new_threads_started = false ;
340
+ List <AnelReceiveUDP > unusedThreads = new ArrayList <>(discoveryThreads );
341
+
342
+ StackTraceElement [] stacktrace = Thread .currentThread ().getStackTrace ();
343
+ String methodName = stacktrace [3 ].getClassName () + ":" + stacktrace [3 ].getMethodName () + "->" + stacktrace [4 ].getClassName () + ":" + stacktrace [4 ].getMethodName ();
344
+ Log .w (PLUGIN_ID , "startNetworkReceivers " + methodName );
345
+
346
+ // Go through all ports and start a thread for it if none is running for it so far
347
+ for (int port : ports ) {
348
+ boolean already_running = false ;
349
+ for (AnelReceiveUDP running_thread : discoveryThreads ) {
350
+ if (running_thread .getPort () == port ) {
351
+ already_running = true ;
352
+ unusedThreads .remove (running_thread );
353
+ break ;
354
+ }
355
+ }
356
+
357
+ if (already_running ) {
358
+ continue ;
359
+ }
360
+
361
+ new_threads_started = true ;
362
+ AnelReceiveUDP thr = new AnelReceiveUDP (this , port );
363
+ thr .start ();
364
+ discoveryThreads .add (thr );
365
+ }
366
+
367
+ if (unusedThreads .size () > 0 ) {
368
+ for (AnelReceiveUDP thr : unusedThreads ) {
369
+ thr .interrupt ();
370
+ discoveryThreads .remove (thr );
371
+ }
372
+ }
373
+
374
+ if (new_threads_started ) {
375
+ // give the threads a chance to start
376
+ try {
377
+ Thread .sleep (100 );
378
+ } catch (InterruptedException ignored ) {
379
+ }
380
+ }
381
+
382
+ HttpThreadPool .startHTTP ();
387
383
}
388
384
389
385
@ Override
0 commit comments