Remote Iterator Pattern
winterer Mar 31, 2005 4:40 AMHello!
I've searched through lots of webpages about J2EE design patterns, but I could not find any satisfying answer to my problem concerning "continuous loading". The only design pattern that almost fits is the value-list-handler (also called page-by-page pattern) - but I think it is not the best way to do what I want:
My client is a rich client (implemented with Eclipse RCP) accessing an EJB application on JBoss Application Server 4.x (using EJB 3.0).
Very often the clients shows lists (and trees) containing data (merely lists of Tranfer Objects) from the server. To enhance UI-responsiveness on the client, it would be nice, if I could fetch the data from the server in a continous stream and so populate the list asynchronous instead of waiting until all items are deserialized on the client (the list often contains more than 1000 elements).
So what I need is something like a "Remote Iterator Pattern". My suggestion:
A stateless session bean implements the query-methods, but does not return the result directly, but a reference to a stateful session bean that is able to iterate over the result.
// lookup stateless session bean QuerySession querySession = (QuerySession)ctx.lookup("querySession"); // Execute query. The result is a stateful session bean that acts as iterator RemoteIterator remoteResult = querySession.findItemsByName("*"); // Iterate over the remote(!) result: while (remoteResult.hasNext()) { // fetch another 10 items Item[] items = (Item[])remoteResult.fetchNext(10); // process items here (e.g. populate UI-list) } remoteResult.done(); // removes stateful session bean
I'm not sure if this approach works. How do I implement my QuerySession and RemoteIterator interfaces? Is it possible to have a generic RemoteIterator implementation that is initialized within the finder-method, or do I have to implement one class per finder-method (e.g. an FindItemsByNameRemoteIterator)?
Thanks in advance,
Tex
P.S.: Please have in mind I'm using EJB 3.0.