Compare commits
2 Commits
d33b3036a0
...
661ab292ad
| Author | SHA256 | Date | |
|---|---|---|---|
| 661ab292ad | |||
| a9411f1d37 |
16
src/main/java/com/r35157/nenjim/kicker/impl/ref/Dummy.java
Normal file
16
src/main/java/com/r35157/nenjim/kicker/impl/ref/Dummy.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.r35157.nenjim.kicker.impl.ref;
|
||||
|
||||
import com.r35157.nenjim.kicker.NenjimProcess;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Dummy implements NenjimProcess {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Hello! This is '" + getName() + "'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return "Just A Dummy";
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,19 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class KickerImpl implements Kicker {
|
||||
|
||||
static void main() throws Exception {
|
||||
new KickerImpl();
|
||||
}
|
||||
|
||||
public KickerImpl() throws InterruptedException {
|
||||
startProcess("com.r35157.nenjim.kicker.impl.ref.Dummy");
|
||||
|
||||
System.out.println("Waiting for all processes to finish!");
|
||||
awaitAllProcessesFinished();
|
||||
log.info("Kicker successfully shutdown!");
|
||||
System.out.println("Kicker successfully shutdown!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startProcess(@NotNull String fqInterfaceName) {
|
||||
ClassLoader loader = ClassLoader.getSystemClassLoader();
|
||||
@@ -41,6 +54,10 @@ public class KickerImpl implements Kicker {
|
||||
proc.setContext(context);
|
||||
proc.setHub(null); log.warn("TODO: Set the HUB here when we have one!");
|
||||
|
||||
synchronized (lock) {
|
||||
running++;
|
||||
}
|
||||
|
||||
Thread t = Thread.ofVirtual()
|
||||
.name(procName)
|
||||
.start(() -> {
|
||||
@@ -52,6 +69,10 @@ public class KickerImpl implements Kicker {
|
||||
} finally {
|
||||
processThreads.remove(processId);
|
||||
processes.remove(processId);
|
||||
synchronized (lock) {
|
||||
running--;
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -67,8 +88,18 @@ public class KickerImpl implements Kicker {
|
||||
public void noop() {
|
||||
}
|
||||
|
||||
public void awaitAllProcessesFinished() throws InterruptedException {
|
||||
synchronized (lock) {
|
||||
while (running > 0) {
|
||||
lock.wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Logger log = LogManager.getLogger(KickerImpl.class);
|
||||
|
||||
private final Object lock = new Object();
|
||||
private int running = 0;
|
||||
private final ConcurrentHashMap<Integer, NenjimProcess> processes = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<Integer, Thread> processThreads = new ConcurrentHashMap<>();
|
||||
private final AtomicInteger nextProcessId = new AtomicInteger(1);
|
||||
|
||||
Reference in New Issue
Block a user