Пример #1
0
    /**
     * Sets the Listener that will be triggered for completed write operations on the matching
     * {@link Sink} and upon close and exhaustion.
     *
     * <p>Note that this Listener MAY NOT under any circumstances throw an exception. If it does so,
     * it will NOT be propagated outside of the Pipe, since the concurrent nature of this interface
     * makes it unreasonable to try to choose a relevant stack to propagate such an exception up
     * through.
     */
    public void setListener(Listener<ReadHead<$T>> $el) {
      DataPipe.this.$el = $el;

      // it's possible that there wasn't a listener before this, and we need to make sure we fire an
      // event now in case there aren't any more writes forthcoming for a while (if indeed ever).
      // this can be "spurious", since it doesn't actually come as news of a write, but it's
      // terribly important not to ignore this.
      boolean $mustSpur = false;
      lockWrite();
      if (SRC.hasNext()) $mustSpur = true;
      unlockWrite(); /* we prefer to release locks before we let the listener go on a tear, just as a matter of best/simplest practice. */
      if ($mustSpur) invokeListener(DataPipe.this.$el);
    }