[rules-users] getting details of facts triggering rules

Wolfgang Laun wolfgang.laun at gmail.com
Wed Feb 23 02:04:01 EST 2011


2011/2/22 Archie Russell <archier at gmail.com>:
>
> Thanks Wolfgang,   I'll give this a shot.
> Is there any way to avoid the "things may have passed away" issue?     Would
> event listeners handle that?

No, it's the same issue anywhere. It depends on whether you have
retracts in the consequence and when you execute the value-sniffing
code. Just slap it into a try/catch
and ignore NPEs

       try {
          Object declVal = activation.getDeclarationValue( declId );
          if( declVal != null ){
            pStream.print( " " + declId + ": " + declVal.toString() );
          } else {
            pStream.print( " " + declId + ": null" );
          }
        } catch( NullPointerException npe ){
          // Silently ignore. This is a bug in getDeclarationIDs, which
          // should not return "evil" IDs referencing retracted facts.
        }

>
> On Thu, Feb 17, 2011 at 1:26 AM, Wolfgang Laun <wolfgang.laun at gmail.com>
> wrote:
>>
>> This may be more conveniently done from an event listener but
>> drools.getActivation() should give you the Activation. Then you get
>> the Collection<FactHandle>.
>>
>> For each of them,
>> org.drools.runtime.KnowledgeRuntime.getObject(
>> org.drools.runtime.rule.FactHandle )
>> gives you the fact objects that participates.
>>
>> You can also access bindings:
>>  List<String> declIds = activation.getDeclarationIDs();
>>  Object declVal = activation.getDeclarationValue( declId );
>> Be careful, things may have passed away, i.e., you can get nulls.
>>
>> -W
>>
>> 2011/2/16 Archie Russell <archier at gmail.com>:
>> >
>> > Hi,
>> > I've tried to figure this out but haven't been able to.
>> > How can I, from the RHS, figure out the details of what triggered a
>> > rule.
>> > I can access the facts individually by name,  but how do I do it in a
>> > generic fashion that would work in the RHS of any rule?
>> > I am using decisiontables and want to be able to have a function that is
>> > something like printTriggeringDetails()
>> > I came across drools.getTuple but am not sure if that's the correct path
>> > to go on.   From there I get InternalFactHandles but don't know how to
>> > turn
>> > those into human-readable facts.
>> > Thanks for any help,
>> > Archie
>> >
>> > _______________________________________________
>> > rules-users mailing list
>> > rules-users at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/rules-users
>> >
>> >
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>




More information about the rules-users mailing list