class QueueingEventSubject implements EventSource<E>, Consumer<E> {

  @Override
  public void accept(E value) {
    Consumer<E> consumerToInvoke = null;

    // avoid calling the consumer from the synchronized section
    synchronized (this) {
      switch (state) {
        case NO_SUBSCRIBER:
          queue.add(value);
          break;
        case SUBSCRIBED:
          consumerToInvoke = subscriber;
          break;
      }
    }

    if (consumerToInvoke != null) {
      consumerToInvoke.accept(value);
    }
  }

  public  QueueingEventSubject(int capacity);

}