class CompositeLineConsumer implements LineConsumer {

  @Override
  public void writeLine(String line) {
    if (isOpen) {
      for (LineConsumer lineConsumer : lineConsumers) {
        try {
          lineConsumer.writeLine(line);
        } catch (ClosedByInterruptException interrupted) {
          Thread.currentThread().interrupt();
          isOpen = false;
          return;
        } catch (ConsumerAlreadyClosedException e) {
          lineConsumers.remove(
              lineConsumer); // consumer is already closed, so we cannot write into it any more
          if (lineConsumers.size() == 0) { // if all consumers are closed then we can close this one
            isOpen = false;
          }
        } catch (IOException e) {
          LOG.error(
              String.format(
                  "An error occurred while writing line to the line consumer %s", lineConsumer),
              e);
        }
      }
    }
  }

  public  CompositeLineConsumer(LineConsumer... lineConsumers);

}