MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / serviceAndCull

Method serviceAndCull

src/main/java/field/app/ThreadSync.java:352–441  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

350 }
351
352 public boolean serviceAndCull() throws InterruptedException {
353 threadingModel.set(this);
354
355 if (live.size() > 0)
356 System.err.println(" -- serviceAndCull, status of " + live.size() + " fibers");
357
358
359 Iterator<Fiber> i = live.iterator();
360 Set<Fiber> repost = new LinkedHashSet<>();
361 while (i.hasNext()) {
362 Fiber f = i.next();
363
364 System.err.println(" " + f + " runner done ? " + f.runner.isDone() + " / " + f.runner.isCancelled() + " paused ? " + f.paused);
365 if (f.runner.isDone()) {
366 f.wasPaused = false;
367 if (f.exception != null) {
368 i.remove();
369 if (f.handler != null)
370 f.handler.accept(f.exception);
371 else
372 throw new IllegalStateException(f.exception);
373 } else {
374
375 System.err.println(" done, polling one more time");
376 Object o = f.output.poll();
377 System.out.println(" got :" + o);
378 if (o != null) {
379 f.out.accept(o);
380 f.lastReturn = o;
381 }
382 System.out.println(" that's it for this fiber");
383 i.remove();
384 }
385 } else {
386 Object p = f.paused.get();
387 f.wasPaused = true;
388
389 if (p == null) continue;
390
391 if (p instanceof Collection) {
392 if (((Collection) p).size() == 0) {
393 repost.add(f);
394 continue;
395 }
396 Iterator q = ((Collection) p).iterator();
397 q.next();
398 q.remove();
399 }
400
401 if (p instanceof Boolean) {
402 if (((Boolean) p).booleanValue()) {
403 repost.add(f);
404 continue;
405 }
406 }
407
408 f.wasPaused = false;
409

Callers 2

shutdownMethod · 0.95
enterMainLoopMethod · 0.80

Calls 15

debugTakeMethod · 0.95
removeAllMethod · 0.80
setMethod · 0.65
hasNextMethod · 0.65
nextMethod · 0.65
acceptMethod · 0.65
getMethod · 0.65
sizeMethod · 0.45
printlnMethod · 0.45
iteratorMethod · 0.45
removeMethod · 0.45
pollMethod · 0.45

Tested by

no test coverage detected