Asynchronous Digester

Since version 3.1 the Digester component offers asynchronous parse() methods.

Users can take advantage from that feature when need to process large XML streams without mapping to intermediary POJOs. Take in consideration applications that need to import data from XML documents - maybe obtained by a REST invocation - and transfer to a DataBase.
Putting the data processor in a non-blocking executor would help clients on:

  • increasing the number of parse operations at the same time;

Note keep always in mind the every single Digester instance is NOT thread-safety, so please use the asynchronous feature carefully!!!

Using Digester Loader

First of all, setup the DigesterLoader with java.util.concurrent.ExecutorService:

final DigesterLoader digesterLoader = newLoader( new AbstractRulesModule()
    {

        @Override
        protected void configure()
        {
            forPattern( "employee" ).createObject().ofType( Employee.class );
            ...
        }

    } ).setExecutorService( java.util.concurrent.Executors.newFixedThreadPool( 10 ) );

Then create the Digester and run the parse method asynchronously:

Digester digester = digesterLoader.newDigester();
...
Future<Employee> future = digester.asyncParse( new URL( "http://my.rest.server/employees/10" ) );

Using directly with the Digester

First of all, setup the Digester with java.util.concurrent.ExecutorService:

Digester digester = new Digester();
digester.addObjectCreate( "employee", Employee.class);
...
digester.setExecutorService( java.util.concurrent.Executors.newFixedThreadPool( 10 ) );

Then run the parse method asynchronously:

Future<Employee> future = digester.asyncParse( new URL( "http://my.rest.server/employees/10" ) );