You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ext2 <xu...@tongtech.com> on 2010/03/30 13:13:33 UTC

exhausted usage of splitter-pattern

Hi:
	Previously , I have ask some question about splitter, and the
stream-based splitter pattern can resolve such situations: 
	Enumerate data from large external data source, and process each
data continuously until all data from external-data source is readed;

	But resolve such problem, Usage of Camel's splitter pattern is very
exhausted;  to illustrate it , let's have a example:
	read a condition from jms queue. According to the condition ,
enumerate a external file's content line by line; and we do same operations
on each line;

Although we could use streamed splitter pattern to resolve this problem, as
following :
	1: write my custom iterater to enumerate content from external file;
	2: using streamed-splitter to process each line from file;
	3: using a doTry-doFianlly to close the iterater;

But the real exhausted thing is how to close the iterator, while execute the
process concurrent-ly;
	1) I must using a bean to create the iterator; it seems like :
	2) I must close the iterator while split finished, it looks like
		<dotry>
			<splitter/>
			<doFinally>
				<bean ref="fileProcess"
method="closeLineIterator"/>
			</doFianlly>
		<dotry>
But configured as above cannot execute concurrently, because the bean itself
cannot ensure to close iterator thread-safely;
In order ensure concurrently execute safe, I must save iterator in the
Exchange's property and close it by property; 
it looks like as following and the following things look like too exhausted.
So does  camel provide a better choice to resolve such problems?

<setProperty name="iteratorId">
	<method bean="fileProcess" method="createLineIterator"/>
<setProperty>
<doTry>
<split streaming="true">
	<getProperty name="iteratorId">
	...
</split><doFinally>
   <process ref = "CloseIteratorByProperty"/> //here is too exhausted,
because I cannot get a bean from message and invoke it's method;
</doTry>

Class CloseIteratorByProperty implement Process
{
	Void process(Exchange ex)
	{
		Iterator iter = Ex.getProperty("iteratorId");
		((implementation class)iter).close();
	}
}