class QueuingConnection implements Connection<I> {

  synchronized void setDelegate(Connection<I> delegate) {
    if (this.delegate != null) {
      throw new IllegalStateException("Attempt at setting delegate twice");
    }

    this.delegate = checkNotNull(delegate);

    if (disposed) {
      return;
    }

    for (I item : queue) {
      delegate.accept(item);
    }

    queue.clear();
  }

}