+

Search Tips   |   Advanced Search

Using an accumulator

As noted previously, we can also pass in an accumulator object to an AssemblyLine with the TCB. An accumulator can be any one of the following classes or interfaces:

If the accumulator is not one of these classes or interfaces, an exception is returned. For example, to accumulate all work entries of an AssemblyLine into an XML file we can use the following script:
var parser = system.getParser ( "example_name.XML" ); // Get a Parser
// Set it up to write to file
parser.setOutputStream ( new java.io.FileOutputStream ( "d:/accum.xml" ));
parser.initParser();                                  // Initialize it.
tcb.setAccumulator ( parser );                        // Set Parser to tcb

var al = main.startAL ( "MyAssemblyLine", tcb );      // Start AL with tcb
al.join();                                            // Wait for AL to finish

parser.closeParser(); // Close the parser - this flushes and 
							     		// closes the output file   
As well, we can configure a Connector instead of programming the Parser manually as in the following script:
var connector = system.getConnector("myFileSysConnWithXMLParser"); 
tcb.setAccumulator ( connector ); 

var al = main.startAL( "MyAssemblyLine", tcb);
al.join();

connector.terminate();
Typically, you initialize the TCB and then the TCB is used by the AssemblyLine. If the AssemblyLine has an Operations specification, the TCB remaps input attributes to the Initial Work Entry as expected by the AssemblyLine, and likewise for setting the result object. This is done so that the external call interface to an AssemblyLine can remain the same even though the internal Work entry names change in the AssemblyLine. Once the TCB is passed to an AssemblyLine, you must not expect anything more from the TCB. Use the AssemblyLine's getResult() and getStats() to retrieve the result object and statistics.

The TCB result mapping is performed before the Epilog so we can still access the final result before the AssemblyLine caller gets to it.


Parent topic:

Task Call Block (TCB)