if (networkRunning.compareAndSet(false, true)) {
try {
executor = Executors.newCachedThreadPool();
closeAllUnconnectedInputs();
final int componentsCount = components.size();
PacketCountInComponent packetCounter = new PacketCountInComponent(componentsCount);
addPacketListener(packetCounter);
for (AbstractRunnableComponent r : components) {
if (shouldRun(r)) {
startComponent(r);
}
}
componentStates.waitForComponentsStop();
if (alivePacketsCount.get() > 0) {
StringBuilder builder = new StringBuilder();
builder.append("There are " + alivePacketsCount.get() + " packets left and no components are running.\n");
builder.append("Components failed due error:\n");
for (int i = 0; i < componentsCount; i++) {
final AbstractRunnableComponent component = components.get(i);
if (component.getError() != null){
Throwable t = component.getError();
builder.append(" ");
builder.append(component.componentName() + ": ");
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintStream print = new PrintStream(bout);
t.printStackTrace(print);
builder.append(new String(bout.toByteArray()));
builder.append("\n");
}
}
builder.append("Components suspended or messages inside:\n");
for (int i = 0; i < componentsCount; i++) {
final AbstractRunnableComponent component = components.get(i);
if (component.state() == 0 && packetCounter.getCount(i) == 0) {
continue;
}
String state = component.getStateString();
final int count = packetCounter.getCount(i);
builder.append(" ");
builder.append(component.componentName() + " (" + state + ")" + ": " + count + " in component\n");
}
builder.append("\nPorts with messages:\n");
for (int i = 0; i < componentsCount; i++) {