xsmeral.pipe
Class Pipe

java.lang.Object
  extended by xsmeral.pipe.Pipe

public class Pipe
extends Object

A simple implementation of the Chain of Responsibility pattern. Works similar to a unix pipe, working over objects, with processors executed in separate threads.


Constructor Summary
Pipe(List<ObjectProcessor> processors)
          Initializes the pipe with supplied chain of processors and instantiates a context.
Pipe(List<ObjectProcessor> processors, Collection<AttachedProcessor> attached)
          In addition to Pipe(java.util.List) also sets attached processors.
Pipe(ObjectProcessor[] processors)
          Does the same as calling Pipe(Arrays.asList(processors))
 
Method Summary
 Collection<AttachedProcessor> getAttached()
          Returns list of attached processors.
 PipeContext getContext()
          Returns the context associated with this pipe and all processors.
 List<ObjectProcessor> getProcessors()
          Returns list of processors in this chain, order from input to output
 ObjectProcessor.Status getStatus()
          Returns the status of this pipe, determined by the status of the processors.
 void kill()
          Interrupts all threads sequentially, possibly leaving the processors in an indeterminate and erroneous state.
 void start(boolean blocking)
          Connects processors, checks input-output type match, assigns and initializes context.
 void stop(boolean blocking)
          Signals the first processor to stop, which should propagate to all following processors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pipe

public Pipe(List<ObjectProcessor> processors,
            Collection<AttachedProcessor> attached)
In addition to Pipe(java.util.List) also sets attached processors.

Parameters:
processors - List of processors, ordered from the first (source) to last (sink).
See Also:
AttachedProcessor

Pipe

public Pipe(List<ObjectProcessor> processors)
Initializes the pipe with supplied chain of processors and instantiates a context.

Parameters:
processors - List of processors, ordered from the first (source) to last (sink).

Pipe

public Pipe(ObjectProcessor[] processors)
Does the same as calling Pipe(Arrays.asList(processors))

Parameters:
processors - Array of processors
Method Detail

getProcessors

public List<ObjectProcessor> getProcessors()
Returns list of processors in this chain, order from input to output


getAttached

public Collection<AttachedProcessor> getAttached()
Returns list of attached processors.


getContext

public PipeContext getContext()
Returns the context associated with this pipe and all processors.


getStatus

public ObjectProcessor.Status getStatus()
Returns the status of this pipe, determined by the status of the processors.


start

public void start(boolean blocking)
           throws ObjectProcessorException
Connects processors, checks input-output type match, assigns and initializes context. More information about context initialization in description of AbstractObjectProcessor class, section "Context initialization".

Parameters:
blocking - If set to true, the method doesn't return until all processor threads stop
Throws:
ObjectProcessorException - If a condition for starting was not met (non-matching outputs/inputs, processor fails to start, invalid object is passed as processor, context parameter dependency conflict)

stop

public void stop(boolean blocking)
Signals the first processor to stop, which should propagate to all following processors. The processing stops as soon as all objects in buffers are processed.

Parameters:
blocking - If set to true, the method doesn't return until all threads stop

kill

public void kill()
Interrupts all threads sequentially, possibly leaving the processors in an indeterminate and erroneous state.
Whenever possible, stop() should be used instead.