See below.

On 22 March 2012 17:25, lhorton <LHorton@abclegal.com> wrote:
5.2.0.Final

consider this simplified example, which has RMI calls to a service to
getLocation()

rule "example"
when
  $p : Product( location != remoteService.getLocation("A") )
then
  $p.setLocation( remoteService.getLocation("A") );
end

the above rule calls the remote method twice, once in the LHS to compare to
a current value, and again in the RHS to set the value.  I would like to
capture the return value of the LHS call, to avoid making the call twice.  I
haven't been able to figure out the syntax to do this within the pattern.
Here's one example of what I have tried:

rule "example"
when
  $p : Product( location != $loc : remoteService.getLocation("A") )
then
  $p.setLocation( $loc );
end

Does anyone know the correct syntax to accomplish this?  Or am I trying to
do the impossible?

With a single rule: yes, I think. However:
  1. At the outset, you know that a comparison with Location A is required.
  2. If you have that firmly in your WM, you can compare and it's possible to use it on the RHS.
This is reflected by the following rules:

rule example1
when
     $p : Product( $mli: missingLocationId ) // that would be "A"
     not Location( id == $mli ) //  haven't RMI'd this yet
then
     Location loc = remoteService.getLocation( $mli );
     insert( loc );
end

rule example2
when
  $p : Product( $mli: missingLocationId )
  $loc: Location( id == $mli )
then
  $p.setLocation( $loc );
end

The idea here is to let a RHS execution intervene to do the RMI once.

-W

 


--
View this message in context: http://drools.46999.n3.nabble.com/Can-I-capture-the-result-of-an-RMI-call-within-a-pattern-tp3848873p3848873.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users