mehrandvd
mehrandvd

Reputation: 9116

How the Policy Execution works using FactRetriever?

I'm checking the document for FactRetriever class using following link:

http://msdn.microsoft.com/en-us/library/ee253709%28v=bts.10%29.aspx

It says:

A fact retriever is a component that is used to assert instances of long-term facts into a policy during its execution. You can implement the IFactRetriever interface and configure a policy version to use this implementation at run time to bring in the long-term fact instances. The policy version invokes the UpdateFacts method of the fact retriever implementation on every execution cycle, if a fact retriever is configured for that particular version.

I'm trying to use Business Rule Composer independently (Not using orchestrations).

Question 1: When does an execution cycle happen? How does it get triggered?

Question 2: What does an execution cycle do exactly? What's the algorithm?

Upvotes: 0

Views: 76

Answers (1)

DTRT
DTRT

Reputation: 11040

A1: You can read that literally. Every time the Policy is executed, the UpdateFacts method of your implementation if IFactRetriever is called prior to any other actual Rule processing. There is no timer and there is nothing else really to configure. Every time means every time.

There is no way, and no reason either, to update a Long Term Fact outside of a Policy execution. Sure, a Fact may change, but if the Policy is not executed, that update was a waste. It's your job, as implementer of IFactRetriever, to keep track of changes to your Facts and provide the most current Facts via UpdateFacts. There's no way for the engine or Policy to just 'know' when to update a Fact. Technically, the Policy doesn't care that a Fact has changed. It will always evaluate the Rules based on the Facts it has.

A2: An execution cycle is just that, a single invocation of a Policy, such as by Policy.Execute(), by any caller. You can see an example here: http://msdn.microsoft.com/en-us/library/aa995566.aspx

The algorithm is as simple as possible. For our purposes, assume that UpdateFacts is the first thing the Rules Engine does after you call Execute, if a Fact Retriever is configured of course. That happens every time. Update Facts is never called at any other point other than immediately after Execute. This is per Execute.

However, it's also worth pointing out that the engine can create multiple instances of the Policy in memory so that it can service multiple callers in the same Process (technically, it might be the AppDomain, never bothered to check). So, UpdateFacts is called for every Execute on any given Instance of the Policy.

Upvotes: 1

Related Questions