xsmeral.pipe
Class LocalObjectFilter<I,O>

java.lang.Object
  extended by xsmeral.pipe.AbstractObjectProcessor
      extended by xsmeral.pipe.LocalObjectFilter<I,O>
Type Parameters:
I - Input object type
O - Output object type
All Implemented Interfaces:
Runnable, ContextAware, ObjectProcessor, ObjectSink<I>, ObjectSource<O>

@ObjectProcessorInterface(in=java.lang.Object.class,
                          out=java.lang.Object.class)
public class LocalObjectFilter<I,O>
extends AbstractObjectProcessor
implements ObjectSink<I>, ObjectSource<O>

An object processor that serves the role of a filter. Receives objects, processes them and writes to the output buffer. Provides default ObjectProcessorInterface set to Objects.
This implementation delegates all calls to an instance of LocalObjectSink and LocalObjectSource.


Nested Class Summary
 
Nested classes/interfaces inherited from interface xsmeral.pipe.interfaces.ObjectProcessor
ObjectProcessor.Status
 
Field Summary
 
Fields inherited from class xsmeral.pipe.AbstractObjectProcessor
canStart, context, status
 
Constructor Summary
LocalObjectFilter()
          Instantiates the sink and the source
LocalObjectFilter(BlockingQueue<O> outBuffer)
          Instantiates a new sink and a source, setting the source to the supplied output buffer.
 
Method Summary
 ObjectSink<O> getNext()
          Returns the next processor in chain.
 BlockingQueue<O> getOutBuffer()
          Returns the output buffer of this processor.
 ObjectSource<I> getPrev()
          Returns the previous processor in chain.
protected  void handleStoppedSink()
          Called in case the next processor is stopped during a write operation.
protected  void handleStoppedSource()
          Called in case the previous processor is stopped during a read operation.
 void next(ObjectSink<O> sink)
          Sets the next processor in the chain and sets this as its previous.
 void prev(ObjectSource<I> src)
          Sets this processor as the next in the chain, after the given processor.
protected  void process()
          Called by the processor itself from run().
protected  I read()
          Reads one object from the top of the buffer of the previous processor.
 void requestStop()
          Requests the processor to stop and sets its status to STOPPING.
 void setNext(ObjectSink<O> sink)
          Sets the next processor, without calling prev() on the sink.
 void setOutBuffer(BlockingQueue<O> buffer)
          Sets the output buffer, used for object flow redirection.
protected  void write(O o)
          Puts one object to the output buffer
 
Methods inherited from class xsmeral.pipe.AbstractObjectProcessor
canStart, failStart, failStart, failStart, getContext, getInType, getOutType, getParams, getStatus, initContext, initContextSet, initialize, initializeInternal, initPostContext, initWithContext, postRun, preRun, run, setContext, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface xsmeral.pipe.interfaces.ObjectSink
getInType
 
Methods inherited from interface xsmeral.pipe.interfaces.ObjectSource
getOutType
 

Constructor Detail

LocalObjectFilter

public LocalObjectFilter()
Instantiates the sink and the source


LocalObjectFilter

public LocalObjectFilter(BlockingQueue<O> outBuffer)
Instantiates a new sink and a source, setting the source to the supplied output buffer.

Method Detail

prev

public final void prev(ObjectSource<I> src)
Description copied from interface: ObjectSink
Sets this processor as the next in the chain, after the given processor.

Specified by:
prev in interface ObjectSink<I>
Parameters:
src - The previous processor

next

public final void next(ObjectSink<O> sink)
Description copied from interface: ObjectSource
Sets the next processor in the chain and sets this as its previous.

Specified by:
next in interface ObjectSource<O>
Parameters:
sink - The next processor

getPrev

public final ObjectSource<I> getPrev()
Description copied from interface: ObjectSink
Returns the previous processor in chain.

Specified by:
getPrev in interface ObjectSink<I>

getNext

public final ObjectSink<O> getNext()
Description copied from interface: ObjectSource
Returns the next processor in chain.

Specified by:
getNext in interface ObjectSource<O>

getOutBuffer

public final BlockingQueue<O> getOutBuffer()
Description copied from interface: ObjectSource
Returns the output buffer of this processor.

Specified by:
getOutBuffer in interface ObjectSource<O>

setOutBuffer

public void setOutBuffer(BlockingQueue<O> buffer)
Sets the output buffer, used for object flow redirection. Shouldn't be called when running.


setNext

public final void setNext(ObjectSink<O> sink)
Sets the next processor, without calling prev() on the sink.


write

protected final void write(O o)
                    throws ProcessorStoppedException
Puts one object to the output buffer

Parameters:
o - The object to write
Throws:
SinkStoppedException - If the sink is in STOPPED state and thus no longer reads the buffer
Calls handleStoppedSink() immediately before throwing.
ProcessorStoppedException

read

protected final I read()
                throws ProcessorStoppedException
Reads one object from the top of the buffer of the previous processor.

Returns:
The read object
Throws:
SourceStoppedException - If the previous processor is in STOPPED state. Calls handleStoppedSource() immediately before throwing.
ProcessorStoppedException

handleStoppedSink

protected void handleStoppedSink()
Called in case the next processor is stopped during a write operation. Can be used, for example, to persist objects left in the buffer.


handleStoppedSource

protected void handleStoppedSource()
Called in case the previous processor is stopped during a read operation.


requestStop

public final void requestStop()
Description copied from interface: ObjectProcessor
Requests the processor to stop and sets its status to STOPPING. There is no limit to the time it takes the processor to stop, it should however stop as soon as possible.
Only the first processor in chain should be requested to stop.

Specified by:
requestStop in interface ObjectProcessor
Overrides:
requestStop in class AbstractObjectProcessor

process

protected void process()
                throws ProcessorStoppedException
Called by the processor itself from run(). Should process one object and return. More information in description of AbstractObjectProcessor class, section "Running". This implementation is empty and should be overridden.

Specified by:
process in class AbstractObjectProcessor
Throws:
ProcessorStoppedException - If a neighboring processor has stopped.