java.lang.Object
org.praxislive.code.userapi.Data.Pipe<T>
- Type Parameters:
T- data type of Pipe
- Enclosing class:
Data
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdd a source for this pipe.protected final voidClear any cached data.final voidRemove all sinks from this pipe.final voidRemove all sources from this pipe.protected booleanisOutputRequired(long pass) Check whether at least one registered sink requires this pipe to produce output.protected booleanisOutputRequired(Data.Pipe<T> source, long pass) Check whether this pipe requires output from the registered source.Convenience method to link provided pipes.protected abstract voidprocess(List<Data.Packet<T>> data) Process the data.protected voidprocess(Data.Pipe<T> sink, Data.Packet<T> packet, long pass) Process data through this pipe.protected voidregisterSink(Data.Pipe<T> sink) Register a sink.protected voidregisterSource(Data.Pipe<T> source) Register a source.final voidremoveSource(Data.Pipe<T> source) Remove a source from this pipe.sinks()Get an immutable snapshot of the currently attached sinks.sources()Get an immutable snapshot of the currently attached sources.protected voidunregisterSink(Data.Pipe<T> sink) Unregister a sink.protected voidunregisterSource(Data.Pipe<T> source) Unregister a source.withSources(Data.Pipe<T>... sources) Convenience method to add multiple sources in one call.protected voidwriteOutput(List<Data.Packet<T>> data, Data.Packet<T> output, int sinkIndex) Write the data to the output.
-
Constructor Details
-
Pipe
public Pipe()Base constructor for pipes.
-
-
Method Details
-
addSource
Add a source for this pipe. Will register this pipe as a sink on the source.- Parameters:
source- source pipe
-
removeSource
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
Get an immutable snapshot of the currently attached sources.- Returns:
- current sources
-
withSources
Convenience method to add multiple sources in one call. SeeaddSource(org.praxislive.code.userapi.Data.Pipe).- Parameters:
sources- sources to add- Returns:
- this for chaining
-
linkTo
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
Get an immutable snapshot of the currently attached sinks.- Returns:
- current sinks
-
clearCaches
protected final void clearCaches()Clear any cached data. -
process
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 registeredpacket- data packet to processpass- pass count
-
process
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
Write the data to the output. The default implementation callsData.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 dataoutput- output data to write tosinkIndex- sink index of the output
-
isOutputRequired
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 sourcepass- 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
Register a source. This method is called byaddSource(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
Unregister a source. This method is called byremoveSource(org.praxislive.code.userapi.Data.Pipe).- Parameters:
source- source to unregister
-
registerSink
Register a sink. This method is called byaddSource(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
Unregister a sink. This method is called byremoveSource(org.praxislive.code.userapi.Data.Pipe)on the sink.- Parameters:
sink- sink to unregister
-