[rules-users] Stateless session commands and ExecutionResults (5.5.0.Final)

Stephen Masters stephen.masters at me.com
Wed Dec 4 06:59:39 EST 2013


Hi folks,

Can anyone explain how stateless session execution results should work? Working through the docs and tracing the code, it’s getting a bit confusing.

Firstly, according to the user manual, one should be able to insert a list of facts as a Command, and get an instance of ExecutionResults back, which can then be queried. Here’s the example code:
StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();

Command cmd = CommandFactory.newInsertElements( Arrays.asList( Object[] { 

                  new Cheese( "stilton" ),

                  new Cheese( "brie" ),

                  new Cheese( "cheddar" ),

              });

ExecutionResults bresults = ksession.execute( cmd );

That doesn’t compile, so I fixed it as follows:

        Command cmd = CommandFactory.newInsertElements( Arrays.asList( 
                new Cheese( "stilton" ),
                new Cheese( "brie" ),
                new Cheese( "cheddar" )
         ));
        ExecutionResults bresults = ksession.execute( cmd );

This does now compile, but running it throws a ClassCastException:
	java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.drools.runtime.ExecutionResults

Taking a look through the Drools code, it would appear that Command has a generic type, which in the case of an InsertElementsCommand is: 
GenericCommand<Collection<FactHandle>>

In turn, the execute command in StatelessKnowledgeSessionImpl casts its result to that generic type:
	public <T> T execute(Command<T> command) {
		Object o = ((GenericCommand) command).execute( context );
		...
		return (T) o;

So the ClassCastException is because the execute method returns an ArrayList of FactHandle instead of an ExecutionResults.

I’m assuming that I must have got the wrong end of the stick somewhere, so what should I be doing to get an ExecutionResults from a stateless session, which I can then query?

Cheers,

Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20131204/6c2b30f2/attachment.html 


More information about the rules-users mailing list