com.rhi.architecture.parc.adapter
Class AbstractOutputAdapter

java.lang.Object
  extended bycom.rhi.architecture.parc.adapter.AbstractOutputAdapter
All Implemented Interfaces:
Adapter, OutputAdapter, java.lang.Runnable
Direct Known Subclasses:
FlatFileOutputAdapter, JDBCOutputAdapter, JDOOutputAdapter, XMLOutputAdapter

public abstract class AbstractOutputAdapter
extends java.lang.Object
implements OutputAdapter

The OutputAdapter is responsible for taking a completed work set and storing it. File or DB persistence mechanisms will be the only initially supported output adapter types.

Since:
1.0
Author:
Pete McKinstry

Field Summary
 
Fields inherited from interface com.rhi.architecture.parc.OutputAdapter
DEFAULT_THREAD_MODE, RUN_AS_THREAD, RUN_AS_THREAD_KEY
 
Constructor Summary
AbstractOutputAdapter()
          Default constructor.
 
Method Summary
 void cleanup()
          cleanup() is called by the BatchApplication during shutdown.
 void close()
          No op by default.
protected  void completeBatch(Transaction transaction)
          Do any non-record level processing required to finish this batch cycle.
 Transaction createTransaction()
          Create a transaction of the appropriate type.
 void flush()
          Do any required processing prior to completing the batch cycle.
 AuditAgent getAuditAgent()
          get audit agent
protected abstract  void handleErrorRecords(java.util.Collection c, Transaction t)
          Defer handling of valid records to sub-classes..
protected abstract  java.util.Collection handleValidRecords(java.util.Collection c, Transaction t)
          Defer handling of valid records to sub-classes..
 void init(java.util.Properties props)
          Load error logfile & create writer.
 Logger log()
          Returns the Logger
 void markComplete()
          Mark output adapter complete
 void run()
          Processing method for the output adapter.
 void setAuditAgent(AuditAgent agent)
          Set method to tell the OutputAdapter what audit agent to use.
 void setErrorChannel(Channel ch)
          Set error record channel
 void setExceptionHandler(ExceptionHandler h)
          Set the handler used for reporting fatal errors during Filter processing.
 void setValidChannel(Channel ch)
          Set valid record channel
 void write(Channel ch, Channel err)
          Persist valid and errored records to the appropriate data store.
 void writeErrorRecords(Channel err)
          To Improve Performance, a thread pool is created and used.
 void writeValidRecords(Channel ch)
          To Improve Performance, a thread pool is created and used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractOutputAdapter

public AbstractOutputAdapter()
Default constructor.

Since:
1.0
Method Detail

setAuditAgent

public final void setAuditAgent(AuditAgent agent)
Set method to tell the OutputAdapter what audit agent to use. The output Adapter is responsible for setting the audit counts when it persists the records.

Specified by:
setAuditAgent in interface Adapter
Parameters:
agent -
Since:
1.0

getAuditAgent

public final AuditAgent getAuditAgent()
get audit agent

Specified by:
getAuditAgent in interface Adapter
Returns:
AuditAgent
Since:
1.0

init

public void init(java.util.Properties props)
          throws InitializationException
Load error logfile & create writer.

Specified by:
init in interface OutputAdapter
Parameters:
props -
Throws:
InitializationException
Since:
1.0

cleanup

public void cleanup()
cleanup() is called by the BatchApplication during shutdown. It closes the errorLog writer and threadpool.

Specified by:
cleanup in interface OutputAdapter
Since:
1.0

flush

public void flush()
           throws ProcessingException
Do any required processing prior to completing the batch cycle. The flush() method is called by the strategy for each execution cycle. This differs from the cleanup method, which is called only once upon application shutdown.

flush() is called by the run() method during each cycle.

Throws:
ProcessingException - Signals a fatal error. The application will shutdown if this exception is thrown.
Since:
1.0

run

public void run()
Description copied from interface: OutputAdapter
Processing method for the output adapter. Opens the possibility of processing completed records asynchronously while the pipeline is running. It can also be run directly by the exec strategy from within the main thread. Both modes are supported and reasonable.

Specified by:
run in interface OutputAdapter
See Also:
Runnable.run()

write

public void write(Channel ch,
                  Channel err)
           throws ProcessingException
Persist valid and errored records to the appropriate data store. Depending on the concrete interface, the output channel may or may not have errored records in it. Output adapters should process the valid records first so that any errors can be added to the error collection.

Parameters:
ch - Channel holding bin for valid records waiting to be persisted.
err - Channel holding bin for errored records waiting to be persisted.
Throws:
ProcessingException - error occured during write. Signals a fatal error. The application will shutdown if this exception is thrown.
Since:
1.0

writeValidRecords

public void writeValidRecords(Channel ch)
                       throws ProcessingException
To Improve Performance, a thread pool is created and used. From valid channel, oa_max_rec_count number of records are retrieved and handed over to each thread. At any point of time at maximum oa_max_threads number of thread will be running. Once, all threads are handling work, main thread waits for all of them to finish and then only processes next set of records.

Parameters:
ch - Channel valid records.
Throws:
ProcessingException
Since:
1.0

writeErrorRecords

public void writeErrorRecords(Channel err)
                       throws ProcessingException
To Improve Performance, a thread pool is created and used. From error channel, oa_max_rec_count number of records are retrieved and handed over to each thread. At any point of time at maximin oa_max_threads number of thread will be running. Once, all threads are handling work, main thread waits for all of them to finish and then only processes next set of records.

Parameters:
err - Channel error records.
Throws:
ProcessingException
Since:
1.0

handleValidRecords

protected abstract java.util.Collection handleValidRecords(java.util.Collection c,
                                                           Transaction t)
                                                    throws ProcessingException
Defer handling of valid records to sub-classes..

Parameters:
c - Collection valid records.
t - Transaction transaction under which these records should be committed.
Returns:
Collection
Throws:
ProcessingException
Since:
1.0

handleErrorRecords

protected abstract void handleErrorRecords(java.util.Collection c,
                                           Transaction t)
                                    throws ProcessingException
Defer handling of valid records to sub-classes..

Parameters:
c - Collection valid records.
t - Transaction transaction under which these records should be committed.
Throws:
ProcessingException
Since:
1.0

completeBatch

protected void completeBatch(Transaction transaction)
                      throws ProcessingException
Do any non-record level processing required to finish this batch cycle. An example of this is incrementing the file sequence number after each batch (write()) is finished.

Since this type of processing doesn't depend on records, it should be called outside of the handle* methods.

Parameters:
transaction -
Throws:
ProcessingException
Since:
1.1

close

public void close()
           throws ProcessingException
No op by default.

Specified by:
close in interface OutputAdapter
Throws:
ProcessingException
Since:
1.1
See Also:
OutputAdapter.close()

setErrorChannel

public void setErrorChannel(Channel ch)
Description copied from interface: OutputAdapter
Set error record channel

Specified by:
setErrorChannel in interface OutputAdapter
Parameters:
ch -
See Also:
OutputAdapter.setErrorChannel(Channel)

setValidChannel

public void setValidChannel(Channel ch)
Description copied from interface: OutputAdapter
Set valid record channel

Specified by:
setValidChannel in interface OutputAdapter
Parameters:
ch -
See Also:
OutputAdapter.setValidChannel(Channel)

setExceptionHandler

public void setExceptionHandler(ExceptionHandler h)
Description copied from interface: OutputAdapter
Set the handler used for reporting fatal errors during Filter processing. Since each Filter is run w/in a thread, the call stack is not an appropriate mechanism for reporting critical processing errors. Therefore, a Handler object is provided for the Filter to use for logging unrecoverable processing errors. Note: This handler must assume that any error is fatal. Non-fatal errors should be handled by adding errors to the record(s) being processed.

Specified by:
setExceptionHandler in interface OutputAdapter
Parameters:
h -
See Also:
OutputAdapter.setExceptionHandler(ExceptionHandler)

markComplete

public void markComplete()
Description copied from interface: OutputAdapter
Mark output adapter complete

Specified by:
markComplete in interface OutputAdapter
See Also:
OutputAdapter.markComplete()

createTransaction

public Transaction createTransaction()
                              throws ProcessingException
Create a transaction of the appropriate type.

Returns:
Transaction
Throws:
ProcessingException
Since:
1.0

log

public Logger log()
Returns the Logger

Returns:
Logger


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