I
- type of the input valuesO
- type of the output valuespublic class SignalPipeline<I,O> extends Object implements SignalProcessor<I,O>
A signal pipeline is a straight chain (that is every chain element has exactly one child)
of multiple SignalProcessor
s.
It has a head and a tail and is created using these two processors. Building pipelines is useful for creating blackbox building blocks that in turn can be used for building more complex processing graphs.
The structure of a pipeline is meant to be immutable, however, since you hand the processor chain to it when constructing the pipeline, this is not enforced programmatically.
Constructor and Description |
---|
SignalPipeline(SignalProcessor<?,?>... processors)
Creates a signal processor pipeline from the given processors (in that same order).
|
SignalPipeline(SignalProcessor<I,?> first,
SignalProcessor<?,O> last,
boolean verifyStraightChain)
Creates a pipeline with the given head and tail.
|
Modifier and Type | Method and Description |
---|---|
<O2> SignalProcessor<O,O2> |
connectTo(SignalProcessor<O,O2> oSignalProcessor)
Connects this processor to another processor to forward processed data to.
|
<O2> SignalProcessor<O,O2> |
disconnectFrom(SignalProcessor<O,O2> oSignalProcessor)
Disconnects a child processor.
|
boolean |
equals(Object o) |
void |
flush()
Asks to complete all pending operations.
|
SignalProcessor<O,?>[] |
getConnectedProcessors()
Lists all connected processors.
|
SignalProcessor<I,?> |
getFirstProcessor()
First processor of this pipeline.
|
Object |
getId()
Arbitrary object to identify a processor.
|
O |
getOutput()
First calls
SignalProcessor.flush() , then returns the pending output, should there be any. |
<T extends SignalProcessor> |
getProcessorWithClass(Class<T> klass)
Returns the first processor that is an instance of the given
Class . |
SignalProcessor<?,?> |
getProcessorWithId(Object id)
Returns the first processor with the given id.
|
int |
hashCode() |
<O2> SignalPipeline<I,O2> |
joinWith(SignalProcessor<O,O2> processor)
Creates a new pipeline from this pipeline's head to the given processor by connecting
this pipeline's tail to the given processor and using the current head and the newly
added processor as tail.
|
void |
process(I i)
Asks this processor to work on the provided data and pipe the
output to the connected processors' own
SignalProcessor.process(Object) method.Implementing methods must not modify or hold on to the provided data. |
String |
toString() |
public SignalPipeline(SignalProcessor<I,?> first, SignalProcessor<?,O> last, boolean verifyStraightChain) throws IllegalArgumentException
first
- first/head processorlast
- last/tail processorverifyStraightChain
- indicates whether you want to make sure that every chain element has exactly one child and that there is a connection between head and tailIllegalArgumentException
- if their is no straight connection between head and tail, i.e. one processor along the way has more than old child (only thrown when verifyStraightChain == true)SignalPipeline(com.tagtraum.jipes.SignalProcessor[])
public SignalPipeline(SignalProcessor<?,?>... processors)
SignalProcessor.connectTo(com.tagtraum.jipes.SignalProcessor)
methods.
Note that this way of creating a processing chain works around type checking mechanisms. I.e. if
one processor's output type does not match the next processor's input type, most likely a
ClassCastException
will be thrown at runtime.
If you want to wrap a series of processors that are already connected, use
SignalPipeline(SignalProcessor, SignalProcessor, boolean)
.processors
- array of processors that are supposed to make a pipeline (starting with the head, ending with the tail)SignalProcessor.connectTo(com.tagtraum.jipes.SignalProcessor)
public SignalProcessor<I,?> getFirstProcessor()
public SignalProcessor<?,?> getProcessorWithId(Object id) throws IllegalStateException
id
- id must not be null
null
IllegalStateException
- if this pipeline is not a line, but a tree or graphpublic <T extends SignalProcessor> T getProcessorWithClass(Class<T> klass) throws IllegalStateException
Class
.klass
- klass must not be null
null
IllegalStateException
- if this pipeline is not a line, but a tree or graphpublic <O2> SignalPipeline<I,O2> joinWith(SignalProcessor<O,O2> processor)
O2
- new output typeprocessor
- processor to appendpublic void process(I i) throws IOException
SignalProcessor
SignalProcessor.process(Object)
method.Object.clone()
method.
It is the responsibility of implementing classes to call the SignalProcessor.process(Object)
method of any connected processors. To manage connected processors classes may want
to use a SignalProcessorSupport
instance.process
in interface SignalProcessor<I,O>
i
- data to processIOException
- if a processing error occursSignalProcessor.getConnectedProcessors()
public void flush() throws IOException
SignalProcessor
SignalProcessor.flush()
method.flush
in interface SignalProcessor<I,O>
IOException
- if a processing error occurspublic O getOutput() throws IOException
SignalProcessor
SignalProcessor.flush()
, then returns the pending output, should there be any.
Note that this call may only succeed once to preserve memory.getOutput
in interface SignalProcessor<I,O>
null
is returnedIOException
- if a processing error occurspublic Object getId()
SignalProcessor
SignalProcessor.getOutput()
.getId
in interface SignalProcessor<I,O>
SignalPump.pump()
public <O2> SignalProcessor<O,O2> connectTo(SignalProcessor<O,O2> oSignalProcessor)
SignalProcessor
connectTo
in interface SignalProcessor<I,O>
O2
- output type of the processor we want to connect tooSignalProcessor
- processorSignalProcessor.disconnectFrom(SignalProcessor)
,
SignalProcessor.getConnectedProcessors()
,
SignalPipeline
public <O2> SignalProcessor<O,O2> disconnectFrom(SignalProcessor<O,O2> oSignalProcessor)
SignalProcessor
disconnectFrom
in interface SignalProcessor<I,O>
O2
- output type of the processor we want to disconnect fromoSignalProcessor
- processorSignalProcessor.connectTo(SignalProcessor)
,
SignalProcessor.getConnectedProcessors()
public SignalProcessor<O,?>[] getConnectedProcessors()
SignalProcessor
getConnectedProcessors
in interface SignalProcessor<I,O>
null
SignalProcessor.disconnectFrom(SignalProcessor)
,
SignalProcessor.connectTo(SignalProcessor)
Copyright © 2011–2020 tagtraum industries incorporated. All rights reserved.