biz.hammurapi.dataflow
Class DataPump

java.lang.Object
  extended by biz.hammurapi.dataflow.DataPump
All Implemented Interfaces:
biz.hammurapi.config.Component

public class DataPump
extends java.lang.Object
implements biz.hammurapi.config.Component

Performs multi-threaded data pumping between data sources and sinks. Converts data item types as necessary.

Author:
Pavel

Nested Class Summary
protected  class DataPump.DataSinkProxy
          Blocks sources when stopped.
 
Constructor Summary
DataPump()
           
 
Method Summary
 void addConnection(DataSource source, DataSink sink)
          Adds connection to be processed.
protected  void connect(DataSource source, DataPump.DataSinkProxy sink)
          Invoked in start() to establish connection between source and sink.
protected  java.lang.Object convert(java.lang.Object source, java.lang.Class targetType)
          Converts data item to expected target type.
protected  Data createData(java.util.Map newValues, Data chain)
          Creates new data with return values or error.
protected  void disconnect(DataSource source, DataPump.DataSinkProxy sink)
          Invoked in stop() to terminate connection between source and sink.
 void join()
          This method block until all pumping jobs finish execution.
protected  Data passData(Data data, DataItemInfo[] sinkInfo)
          Passes data from source to sink adjusting data types.
protected  void postJob(java.lang.Runnable job)
          Executes job either in the current thread or in a worker thread.
 void setOwner(java.lang.Object owner)
           
 void setWorker(biz.hammurapi.util.Worker worker)
          Worker to execute pumping jobs.
 void start()
          Starts data pumping.
 void stop()
          Stops/pauses data pumping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataPump

public DataPump()
Method Detail

setOwner

public void setOwner(java.lang.Object owner)
Specified by:
setOwner in interface biz.hammurapi.config.Component

setWorker

public void setWorker(biz.hammurapi.util.Worker worker)
Worker to execute pumping jobs. If worker is not set, all tasks are executed in the starting thread.

Parameters:
worker -

addConnection

public void addConnection(DataSource source,
                          DataSink sink)
Adds connection to be processed.

Parameters:
source -
sink -

connect

protected void connect(DataSource source,
                       DataPump.DataSinkProxy sink)
Invoked in start() to establish connection between source and sink.

Parameters:
source -
sink -

disconnect

protected void disconnect(DataSource source,
                          DataPump.DataSinkProxy sink)
Invoked in stop() to terminate connection between source and sink. This implementation invokes source.setSink(null);

Parameters:
source -
sink -

start

public void start()
Starts data pumping.

Specified by:
start in interface biz.hammurapi.config.Component

stop

public void stop()
Stops/pauses data pumping. Start method can be invoked again after stop to resume data pumping.

Specified by:
stop in interface biz.hammurapi.config.Component

passData

protected Data passData(Data data,
                        DataItemInfo[] sinkInfo)
Passes data from source to sink adjusting data types. If not conversion is required data is returned as-is. Override for logging, etc.

Parameters:
data -
sinkInfo -
Returns:

convert

protected java.lang.Object convert(java.lang.Object source,
                                   java.lang.Class targetType)
Converts data item to expected target type. This implementation uses ConvertingService. Override as needed.

Parameters:
source -
targetType -
Returns:

createData

protected Data createData(java.util.Map newValues,
                          Data chain)
Creates new data with return values or error. This implementation creates Map data.

Parameters:
newValues -
chain -
Returns:

join

public void join()
          throws java.lang.InterruptedException
This method block until all pumping jobs finish execution. If worker is not set, this method returns immediately.

Throws:
java.lang.InterruptedException

postJob

protected void postJob(java.lang.Runnable job)
Executes job either in the current thread or in a worker thread.

Parameters:
job -


Copyright © 2005 Hammurapi Group. All Rights Reserved.