[rules-users] How to inovke a Service...

Edson Tirelli tirelli at post.com
Thu Feb 8 16:31:21 EST 2007


   James,

   The consequence and function blocks in a DRL file are transformed 
into a plain java method. It means you can do whatever you want and java 
allows. So, if you are for instance inside an application server, you 
cat get your JNDI context from there and do your stuff. Although, it is 
usually better to have helper classes doing procedural code and keep the 
consequence code clean to make rules maintance easier.

   So, for exaple, you can have a helper class that has the actual code 
to call the service you want and set it as a global for your rulebase. 
Then in the consequence you call this class method with the given 
paramenters.
   Example:

package my.package;

global my.service.package.ServiceInvoker invoker;

rule "Cheese in stock"
when
     $p : Person( $likes : likes )
     $c : Cheese( type == $likes, quantity > 0 )
then
    invoker.sendMessageToPerson( $p, "Your prefered cheese 
("+$c.getType()+") is back in stock;" );
end

   Inside your ServiceInvoker class you create the code to actually send 
the message (procedural code).

   This is only one way of doing it, but it is usually what is done.

   Hope it helps.

   []s
   Edson

jdepaul wrote:

>I've done a little research since my first post and have been experimenting
>with the AgendaEventListener interface...   I can register a component in
>WorkingMemory that will 'listen' and be notified afterEventFired event -
>this could be a good place from which to invoke my serivce, however, the
>problem I'm having is that the event delivered doesn't seem to pass the
>original Fact that caused the Event to fire, only the rule that got
>activated is sent...  How could I get the Fact that caused this event to
>fire from that event object?
>
>James
>
>
>  
>


-- 
 Edson Tirelli
 Software Engineer - JBoss Rules Core Developer
 Office: +55 11 3124-6000
 Mobile: +55 11 9218-4151
 JBoss, a division of Red Hat @ www.jboss.com





More information about the rules-users mailing list