DTRules as an embedded rules engine

234 views
Skip to first unread message

Michael O'Connor

unread,
Dec 24, 2013, 10:38:28 AM12/24/13
to dtr...@googlegroups.com
Hi,

I'm looking for a rules-engine that I can embed in a java application / service, and it looks like DTRules may be a good fit. However my use-case differs from the examples at dtrules.com in that I need to provide data to, and read data from, the rules-engine directly in java (and not via XML file). Specifically I need to:
  1. pass parameters from java to the rules-engine at start-up.
  2. allow the rules-engine to call-back into the java application to read or write data (the discussion at https://groups.google.com/forum/#!topic/dtrules/B-hclzqPcOU seems to cover this).
  3. pass results data from the rules-engine to java at completion.
In my application the rules-engine would be called thousands of times (or even hundreds of thousands of times) with different input parameters each time, and it would be expected to perform the same rules evaluation on each. So any performance tips around avoiding repeated rules-engine start-up and tear-down costs would be appreciated.

Can I confirm that this is a suitable use-case for DTRules, and if so are there any examples or documentation of how to achieve steps 1 - 3 above?

Thanks,

Michael


paul snow

unread,
Dec 24, 2013, 1:05:21 PM12/24/13
to dtr...@googlegroups.com
That is rather straight forward with DTRules.  You can map your data into a Session, execute the rules, and pull out what values you are interested in.  If your rule set is setup such that you want to alter one value, you can do so, and call the engine again.

I am pretty busy for the next few weeks, but I can work up an example to demonstrate this approach.  We actually use it in an application at SourcePulse.  The engine state is updated only with changes, and Rule sets are executed repeatedly to reflect the updates, all without start up and tear down costs.

Paul

Paul Snow
President
Texas Bitcoin Association



--
You received this message because you are subscribed to the Google Groups "DTRules" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dtrules+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

paul snow

unread,
Dec 24, 2013, 1:06:11 PM12/24/13
to dtr...@googlegroups.com
Oh, and I neglected to point out that inserting Java functions into the engine allowing you to execute Java from decision tables is also supported.

Paul

Paul Snow
President
Texas Bitcoin Association



Michael O'Connor

unread,
Dec 24, 2013, 1:51:15 PM12/24/13
to dtr...@googlegroups.com
Thanks for the quick response. If there's an example of mapping (java) data in to and out of a Session that I could look at that'd be great.

In my case I need to setup between 2 and 4 input parameters in each call to the rules-engine with a single result parameter as output - I guess the input parameters could be encapsulated in something like a single request entity (?).

Michael

paul snow

unread,
Dec 24, 2013, 2:37:30 PM12/24/13
to dtr...@googlegroups.com
Yes, you can do that.  You can populate the Entity via Java calls directly.  That would make the call very simple.

Also, the Rules Engine is thread safe.  So you can create multiple sessions and make calls to those sessions in different threads.  Don't know if you need that, but it does work.

Paul

Paul Snow
President
Texas Bitcoin Association



--

Michael O'Connor

unread,
Dec 24, 2013, 2:54:46 PM12/24/13
to dtr...@googlegroups.com
That sounds great (on both counts)!

Do any of the example projects available on github do something like this?

Michael

paul snow

unread,
Dec 24, 2013, 4:54:15 PM12/24/13
to dtr...@googlegroups.com
The Chip Application comes close.  It uses a Datamap to load data.  There are more direct API's to do this however.

I don't have time at the moment to generate an example, but if you look at the ChipApp example 


You can at least see how to put data into a Datamap object and map it into a session.  This can be done over and over without creating a new session.

If you give me an example Result Entity with the datatypes you want to push, I can write you some sample code.




--

Michael O'Connor

unread,
Dec 24, 2013, 6:19:31 PM12/24/13
to dtr...@googlegroups.com
Thanks for that.

The result entity in my case is merely a double value (actually a price like 10.99, with the rules-engine doing the job of a price calculator).

Michael

paul snow

unread,
Dec 25, 2013, 12:48:32 AM12/25/13
to dtr...@googlegroups.com
In the next day or two I'll write you a simple example rule set.  Sadly it is Christmas, and I am going to New Orleans for a few days afterwards.  But I will try and do it as soon as possible.

Paul

Paul Snow
President
Texas Bitcoin Association



--

paul snow

unread,
Dec 28, 2013, 8:16:13 PM12/28/13
to dtr...@googlegroups.com

Sorry about the delay... I don't think I'll get to this until the new year...

Michael O'Connor

unread,
Dec 30, 2013, 9:44:25 AM12/30/13
to dtr...@googlegroups.com
Hi Paul,

I've succeeded in creating a java service that uses DTRules as an embedded rules-engine and performs the 3 operations I mentioned at the start of this thread (it wasn't hard! - I based it on the CHIPApp example, and the StateForZipcode() discussion for my callback).

One thing I'm wondering: what would be involved in returning an entity containing multiple properties (instead of just a single value) from my callback - is this easy to do, is there an example in any of the available sample projects?

Thanks,

Michael

paul snow

unread,
Dec 30, 2013, 1:23:05 PM12/30/13
to dtr...@googlegroups.com
You can access all the data within the Rule Engine state.  So you can return arbitrarily complex data.  I am pretty sure some of the examples return multiple values. 

I am out of town, and I am buried under some other tasks.  I will get something done for you anyway.

Paul 



--

Michael O'Connor

unread,
Jan 3, 2014, 10:18:39 AM1/3/14
to dtr...@googlegroups.com
Hi Paul,

I've been unable to work out how to get my callback to return an entity (and I haven't been able to find an example). I'm trying to do something like "local entity myEntity = the entity value of GetEntityForId(123)", however the parser doesn't like the "entity value" bit here.

I'm also not sure how I push the entity object that I've created in my callback onto the data stack (- something like "state.datapush(REntity.entityValue(myEntity));" ?)

Any clues / suggestions would be appreciated, thanks,

Michael
Reply all
Reply to author
Forward
0 new messages