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

James Depaul jjdepaul at us.ibm.com
Thu Feb 8 17:29:20 EST 2007


Thanks Edson -

Two questions:

1)  Is using Globals (as you mention below) same as using
WorkingMemory.setApplicationData(myService)  - or is this yet another way
to do it.  Is there a difference in terms of efficiency?

2)  Is there a way to get to the Fact that fired the event from the Event
object passed in the AgendaEventListener.afterActivationFired(Event event)

>From an efficiency and performance standpoint, which way would you
recommend pursuing:  EventListener invoking a service or service invoked
from global Helper class in current WorkingMemory?  Any guidance there
would be appreciated.

Thanks,
James





                                                                           
             Edson Tirelli                                                 
             <tirelli at post.com                                             
             >                                                          To 
             Sent by:                  Rules Users List                    
             rules-users-bounc         <rules-users at lists.jboss.org>       
             es at lists.jboss.or                                          cc 
             g                                                             
                                                                   Subject 
                                       Re: [rules-users] How to inovke a   
             02/08/2007 02:31          Service...                          
             PM                                                            
                                                                           
                                                                           
             Please respond to                                             
             Rules Users List                                              
             <rules-users at list                                             
               s.jboss.org>                                                
                                                                           
                                                                           




   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


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070208/abb93825/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20070208/abb93825/attachment.gif 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pic25565.gif
Type: image/gif
Size: 1255 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20070208/abb93825/attachment-0001.gif 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ecblank.gif
Type: image/gif
Size: 45 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20070208/abb93825/attachment-0002.gif 


More information about the rules-users mailing list