com.rhi.architecture.parc.filter
Class AbstractFilter

java.lang.Object
  extended bycom.rhi.architecture.parc.filter.AbstractFilter
All Implemented Interfaces:
Filter, java.lang.Runnable
Direct Known Subclasses:
AbstractFilter, NotificationFilter, PollingFilter

public abstract class AbstractFilter
extends java.lang.Object
implements Filter

The AbstractFilter provides a partially implemented Filter allowing simpler concrete Filter objects. It deals w/ thread safe exit logic, and idle cycle detection as well as providing the required hooks for pre & post channel hookup. All concrete filter processing is deferred to a doWork() abstract method.

Note: a simple run() method is provided to support the Runnable Interface.

Since:
1.0
Author:
Pete McKinstry

Constructor Summary
protected AbstractFilter()
          constructor
protected AbstractFilter(int max)
          constructor
 
Method Summary
protected abstract  java.util.Collection doWork(java.util.Collection in)
          Template method to facilitate simple Filter implementations.
 Consumer getErrorChannel()
          return error channel
 ExceptionHandler getExceptionHandler()
          return exception handler
 Supplier getInbound()
          supplier configured on the inbound side of the filter.
 int getMaxRecords()
          Returns the maxRecords.
 java.lang.String getName()
          Easy implementation for sub-classes
 Consumer getOutbound()
          consumer configured on the outbound side of this filter.
 void init(java.util.Properties properties)
          Initialize common Filter settings.
protected  boolean isShutdown()
          Returns the shutdown flag
static Logger log()
          Returns the log.
 void markForDeath()
          Tell the filter to shutdown after detecting idle cycles.
 int numThreads()
          Return the suggested number of threads to launch for this Filter.
 void reset()
          Reset the filter to ensure that it's ready to process records again.
 void run()
          Thread execution method.
 void setErrorChannel(Consumer err)
          Set the error delivery mechanism.
 void setExceptionHandler(ExceptionHandler handler)
          Set the exception handler mechanism.
 void setInbound(Supplier s)
          Set the inbound delivery mechanism.
 void setMaxRecords(int val)
          Method setMaxRecords.
 void setNumThreads(int val)
          Method setNumThreads.
 void setOutbound(Consumer c)
          Set the outbound delivery mechanism.
protected static Logger stats()
          Returns the Logger instance used for statistics.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.rhi.architecture.parc.Filter
process
 

Constructor Detail

AbstractFilter

protected AbstractFilter()
constructor


AbstractFilter

protected AbstractFilter(int max)
constructor

Parameters:
max - - greatest number of records that this filter will accept from the channel in 1 batch. Used in conjunction w/ the thread count to performance tune the pipeline.
Since:
1.0
Method Detail

init

public void init(java.util.Properties properties)
          throws InitializationException
Initialize common Filter settings. Note: sub-classes may override this method, but they must call super.init() in addition to doing their own local initialization. If any of these values are already set, they will be over- written. If you don't want that to happen, do not provide a property setting for these attributes.

Sets the following common Filter attributes. 1) .max_records: the max number of records to be pulled from the channel during each work cycle. 2) .num_threads: the number of threads to run for this filter. If no setting is found, the default value will be used. - For threads, the default is 1. - For work sets, the default size is 20.

Specified by:
init in interface Filter
Parameters:
properties -
Throws:
InitializationException
Since:
1.0

run

public void run()
Thread execution method. Inherited from Runnable All this method does is call process(). & catch the ProcessingException.

Specified by:
run in interface java.lang.Runnable
Since:
1.0

doWork

protected abstract java.util.Collection doWork(java.util.Collection in)
                                        throws ProcessingException
Template method to facilitate simple Filter implementations.

This method, just like process(), is part of the main thread loop and therefore must be thread safe.

Parameters:
in -
Returns:
Throws:
ProcessingException

markForDeath

public void markForDeath()
Tell the filter to shutdown after detecting idle cycles. markForDeath sets an 'exit' flag on the Filter. The pipeline model assumes that a complete cycle leaves the pipeline empty, therefore, the markForDeath() is _lazy_ in the sense that it only takes effect after a thread finds no more work in the inbound channel.

Specified by:
markForDeath in interface Filter
Since:
1.0

reset

public void reset()
Reset the filter to ensure that it's ready to process records again. This method must be called after calling markForDeath() to reset the state of the Filter.

Note: Although it's thread safe due to the volatile keyword, the reset() method is intended to be used

Specified by:
reset in interface Filter
Since:
1.1

isShutdown

protected boolean isShutdown()
Returns the shutdown flag

Returns:
boolean

setInbound

public void setInbound(Supplier s)
Set the inbound delivery mechanism.

Specified by:
setInbound in interface Filter
Parameters:
s -
Since:
1.0

getInbound

public Supplier getInbound()
supplier configured on the inbound side of the filter.

Returns:
Supplier

setOutbound

public void setOutbound(Consumer c)
Set the outbound delivery mechanism.

Specified by:
setOutbound in interface Filter
Parameters:
c -
Since:
1.0

getOutbound

public Consumer getOutbound()
consumer configured on the outbound side of this filter.

Returns:
Consumer

setErrorChannel

public void setErrorChannel(Consumer err)
Set the error delivery mechanism.

Specified by:
setErrorChannel in interface Filter
Parameters:
err -
Since:
1.0

getErrorChannel

public Consumer getErrorChannel()
return error channel

Returns:
Consumer

setExceptionHandler

public void setExceptionHandler(ExceptionHandler handler)
Set the exception handler mechanism.

Specified by:
setExceptionHandler in interface Filter
Parameters:
handler -
Since:
1.0

getExceptionHandler

public ExceptionHandler getExceptionHandler()
return exception handler

Returns:
ExceptionHandler

getName

public java.lang.String getName()
Easy implementation for sub-classes

Specified by:
getName in interface Filter
Returns:
String
Since:
1.0

setNumThreads

public void setNumThreads(int val)
Method setNumThreads.

Parameters:
val -

numThreads

public int numThreads()
Return the suggested number of threads to launch for this Filter. Obviously this requires that the application uses a Pipeline that implements multi-threading. The number of threads is '1' by default, but can be altered by setting a configuration property = .num_threads to be whatever value you wish.

Specified by:
numThreads in interface Filter
Returns:
int the number of threads to launch for this Filter
Since:
1.1

setMaxRecords

public void setMaxRecords(int val)
Method setMaxRecords.

Parameters:
val -

getMaxRecords

public int getMaxRecords()
Returns the maxRecords.

Returns:
int

stats

protected static Logger stats()
Returns the Logger instance used for statistics.

Returns:
Logger

log

public static Logger log()
Returns the log.

Returns:
Logger


Copyright © 2002-2004 Robert Half International. All Rights Reserved.