use of suite.primitive.BooMutable in project suite by stupidsing.
the class LoadBalancer method run.
public void run() throws IOException {
BooMutable running = BooMutable.true_();
Thread probe = new Thread(() -> {
while (running.isTrue()) try {
List<String> alives1 = new ArrayList<>();
for (String server : servers) try (Socket socket = new Socket(server, port)) {
alives1.add(server);
} catch (SocketException ex) {
}
alives = alives1;
Thread.sleep(500l);
} catch (Exception ex) {
LogUtil.error(ex);
}
});
Io io = (is, os) -> {
int count = counter.getAndIncrement();
List<String> alives0 = alives;
String server = alives0.get(count % alives0.size());
try (Socket socket = new Socket(server, port)) {
InputStream sis = socket.getInputStream();
OutputStream sos = socket.getOutputStream();
List<Thread> threads = List.of(Copy.streamByThread(is, sos), Copy.streamByThread(sis, os));
Thread_.startJoin(threads);
}
};
try {
probe.start();
new SocketUtil().listenIo(port, io);
} finally {
running.setFalse();
}
}
use of suite.primitive.BooMutable in project suite by stupidsing.
the class MutexTest method isDeadlock.
private boolean isDeadlock(MutexTestRunnable... mtrs) throws InterruptedException {
BooMutable result = BooMutable.false_();
List<Thread> threads = //
Read.from(//
mtrs).map(mtr -> Thread_.newThread(() -> {
try {
mtr.run();
} catch (DeadlockException ex1) {
result.setTrue();
}
})).toList();
Thread_.startJoin(threads);
return result.isTrue();
}
Aggregations