Class Data.Pipe<T>

java.lang.Object
org.praxislive.code.userapi.Data.Pipe<T>
Type Parameters:
T - data type of Pipe
Direct Known Subclasses:
Data.In, Data.Out
Enclosing class:
Data

public abstract static class Data.Pipe<T> extends Object
The base type of pipes that can be connected to form processing graphs. Generally use the various factory methods (eg. Data.with() ) or Data.In / Data.Out
  • Constructor Details

    • Pipe

      public Pipe()
      Base constructor for pipes.
  • Method Details

    • addSource

      public final void addSource(Data.Pipe<T> source)
      Add a source for this pipe. Will register this pipe as a sink on the source.
      Parameters:
      source - source pipe
    • removeSource

      public final void removeSource(Data.Pipe<T> source)
      Remove a source from this pipe.
      Parameters:
      source - source pipe
    • disconnectSources

      public final void disconnectSources()
      Remove all sources from this pipe.
    • disconnectSinks

      public final void disconnectSinks()
      Remove all sinks from this pipe.
    • sources

      public final List<Data.Pipe<T>> sources()
      Get an immutable snapshot of the currently attached sources.
      Returns:
      current sources
    • withSources

      @SafeVarargs public final Data.Pipe<T> withSources(Data.Pipe<T>... sources)
      Convenience method to add multiple sources in one call. See addSource(org.praxislive.code.userapi.Data.Pipe).
      Parameters:
      sources - sources to add
      Returns:
      this for chaining
    • linkTo

      @SafeVarargs public final Data.Pipe<T> linkTo(Data.Pipe<T>... pipes)
      Convenience method to link provided pipes. This pipe will be added as a source of the first provided pipe, with any additional pipes linked in order.
      Parameters:
      pipes - pipes to link to
      Returns:
      this for chaining
    • sinks

      public final List<Data.Pipe<T>> sinks()
      Get an immutable snapshot of the currently attached sinks.
      Returns:
      current sinks
    • clearCaches

      protected final void clearCaches()
      Clear any cached data.
    • process

      protected void process(Data.Pipe<T> sink, Data.Packet<T> packet, long pass)
      Process data through this pipe. This method is called by sink pipes to process data. It is generally not necessary to call or override this method.

      The pass parameter is checked against any previous call to check whether sources need to be called or cached data is invalid.

      Parameters:
      sink - sink calling process - must be registered
      packet - data packet to process
      pass - pass count
    • process

      protected abstract void process(List<Data.Packet<T>> data)
      Process the data.

      If there is only one sink, and zero or one sources, the packet will be the one provided by the sink. In other cases the data is cached, and written to the sink(s) in writeOutput(java.util.List, org.praxislive.code.userapi.Data.Packet, int).

      Parameters:
      data - data packets to process
    • writeOutput

      protected void writeOutput(List<Data.Packet<T>> data, Data.Packet<T> output, int sinkIndex)
      Write the data to the output. The default implementation calls Data.Packet.accumulate(java.util.List) to combine all the data from sources using the accumulation function provided by the pipeline.
      Parameters:
      data - list of processed data
      output - output data to write to
      sinkIndex - sink index of the output
    • isOutputRequired

      protected boolean isOutputRequired(Data.Pipe<T> source, long pass)
      Check whether this pipe requires output from the registered source. By default this method checks whether the output of this pipe is required by any registered sink.

      This method may be overridden to provide additional checks.

      Parameters:
      source - registered source
      pass - process pass
      Returns:
      true if source must provide output
    • isOutputRequired

      protected boolean isOutputRequired(long pass)
      Check whether at least one registered sink requires this pipe to produce output. This method handles cycles in the pipe graph.

      This method may be overridden to provide additional checks.

      Parameters:
      pass - process pass
      Returns:
      true if at least one sink requires output from this pipe
    • registerSource

      protected void registerSource(Data.Pipe<T> source)
      Register a source. This method is called by addSource(org.praxislive.code.userapi.Data.Pipe).

      May be overridden to validate source or throw an exception.

      Parameters:
      source - source to register
      Throws:
      IllegalArgumentException - if source is already registered
    • unregisterSource

      protected void unregisterSource(Data.Pipe<T> source)
      Unregister a source. This method is called by removeSource(org.praxislive.code.userapi.Data.Pipe).
      Parameters:
      source - source to unregister
    • registerSink

      protected void registerSink(Data.Pipe<T> sink)
      Register a sink. This method is called by addSource(org.praxislive.code.userapi.Data.Pipe) on the sink.

      May be overridden to validate sink or throw an exception.

      Parameters:
      sink - sink to register
    • unregisterSink

      protected void unregisterSink(Data.Pipe<T> sink)
      Unregister a sink. This method is called by removeSource(org.praxislive.code.userapi.Data.Pipe) on the sink.
      Parameters:
      sink - sink to unregister