Skip to content

Commit

Permalink
synchronized
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolovison committed Jan 6, 2025
1 parent be8f0a6 commit 15d5285
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/main/java/io/hyperfoil/tools/qdup/shell/AbstractShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -600,22 +600,28 @@ public void addShObserver(String name, Consumer<String> consumer) {
addShObserver(name,(output,promptName)->consumer.accept(output));
}
public void addShObserver(String name, BiConsumer<String,String> consumer) {
shObservers.put(name, consumer);
synchronized (AbstractShell.class) {
shObservers.put(name, consumer);
}
}
public void removeShObserver(String name) {
shObservers.remove(name);
synchronized (AbstractShell.class) {
shObservers.remove(name);
}
}

private void shObservers(String output,String promptName) {
shObservers.forEach((name,consumer)->{
int v = c.getAndIncrement();
logger.info("in: consumer.accept: {}x", v);
if (v == 15) {
logger.info("{}={}", name, output);
}
consumer.accept(output,promptName);
logger.info("out: consumer.accept: {}x", v);
});
synchronized (AbstractShell.class) {
shObservers.forEach((name, consumer) -> {
int v = c.getAndIncrement();
logger.info("in: consumer.accept: {}x", v);
if (v == 15) {
logger.info("{}={}", name, output);
}
consumer.accept(output, promptName);
logger.info("out: consumer.accept: {}x", v);
});
}
}
public int permits() {
return shellLock.availablePermits();
Expand Down

0 comments on commit 15d5285

Please sign in to comment.