- public void addManager(Manager m) {
- var thread = newManagerRunner.apply(m);
- if (thread == null) {
- return;
- }
- synchronized (receiveThreads) {
- receiveThreads.add(new Pair<>(m, thread));
- }
- }
-
- public void run() {
- synchronized (stopTrigger) {
- try {
- stopTrigger.wait();
- } catch (InterruptedException ignored) {
- }
- }
-
- synchronized (receiveThreads) {
- for (var t : receiveThreads) {
- t.second().interrupt();
- }
- }
- while (true) {
- final Thread thread;
- synchronized (receiveThreads) {
- if (receiveThreads.size() == 0) {
- break;
- }
- var pair = receiveThreads.remove(0);
- thread = pair.second();
- }
- try {
- thread.join();
- } catch (InterruptedException ignored) {
- }
- }
- }
-