How to Access Rule RHS (THEN Part) from JAVA?
by Ravikiran
Hi Drools Gurus,
One more newbie here for Drools Guvnor. I have chosen
"guvnor-distribution-5.3.0.Final" (I could see version as SNAPSHOT 5.4.0
within Guvnor-->Administration-->About) to start with. After reading through
the complete user manual, I was able to setup and deploy Drools Guvnor war
in JBoss AS 7.
My intension is to access all the rules that i have created using Guvnor
web. I have written a java test case to access my Rules which are resided in
a drools Package using REST API. I was successful to access them using
standard Authentication mechanism with charset*.xml. Even though i was able
to call fireAllRules with specific rule using "AgendaFilter" provided. But i
was not able to access the values at RHS after a specific rule got fired.
For Example, i want to access "percent value as 2.5" after the below sample
rule is successfully executed,
I have uploaded my model jar to Guvnor containing Person & LoanFormula
classes.
---Rule 1 (please do not see the syntax errors)
WHEN
Person age > 25
----
THEN
LoanFormula percent = 2.5
....
....
JAVA Code follows
---------------------
KnowledgeBase kbase = ...
FactType personType = kbase.getFactType( "org.drools.examples","Person" );
Object bob = personType.newInstance();
personType.set( bob, "name","Bob" );
personType.set( bob,"age",42 );
StatefulKnowledgeSession ksession = ...
ksession.insert( bob );
AgendaFilter filter = new ......("Rule1");
int count = ksession.fireAllRules(filter);
String name = personType.get( bob, "name" );
int age = personType.get( bob, "age" );
It would be great help if some one can show me the sample code for accessing
RHS part of the Rule. Please let me know if you need more details.
thanks
Kiru
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-Access-Rule-RHS-THEN-Part-from-J...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Drools Guvnor - question on "mortgages" package in "guvnor-distribution-5.4.0.Final"
by Ravikiran
Hi,
I have deployed drools-guvnor.war version 5.4.0 in Jboss AS 7. When i launch
the guvnor for the first time, it also loads the defalult packages, one
package is called "mortgages" is also loaded. Mortgages package contans
totally 7 diff. rules, but when i go see the model of the mortgages i do not
see any classes displayed over there. But, i was able to build & create
deployment SNAPSHOT successfully. Even the rule DSL source contains all
classes like LoanApplication etc.,.
How is it possible? Do you mean, some kind of related drl file is uploaded
as a Model? please clarify?
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Guvnor-question-on-mortgages-pac...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Planner - Initialized solution & local search
by Garf
I'm using v5.4. I've built a prototype which uses the constructionHeuristic,
and localSearch, as the example does, and am able to run the solver (though
it still doesn't do a good job of solving at this point).
I've now added customSolverPhase, and set it to use an initializer class
which implements CustomSolverPhaseCommand.
In my changeWorkingSolution, I call scoreDirector.beforeEntityAdded(), and
then set the planning entity's planning variable, and then call
afterEntityAdded().
If I leave any entities unadded -- and let the constructionHeuristic
(BEST_FIT, etc) do the fitting (which I can verify from the logs)-- I then
get this exception:
/java.lang.IllegalStateException: Phase localSearch started with an
uninitialized Solution. First initialize the Solution. For example, run a
phase constructionHeuristic first./
For now, I can update my code to ensure that all of the entities are fitted
and bypass the constructionHeuristic, but I'm curious why this error is
getting thrown. I did hunt through the source code to look at all the
isInitialized() methods, but I haven't yet stepped through to see which one
returns false any why.
As for turning on TRACE mode, see my
http://drools.46999.n3.nabble.com/drools-planner-5-4-0-Final-java-lang-Il...
recent post .
Jon
--
View this message in context: http://drools.46999.n3.nabble.com/Planner-Initialized-solution-local-sear...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Serialization issue with StateKnowledgeSession
by chrisLi
Hi, all
I have a requirement to serialzie a stateful session as a snapshot.
private void serialize(OutputStream out) throws IOException{
System.out.println("writing");
DroolsObjectOutputStream droolsOut = new DroolsObjectOutputStream(
(OutputStream) out);
droolsOut.writeLong(counter);
droolsOut.writeLong(clock.getCurrentTime());
droolsOut.writeObject(this.knowledgeBase);
Marshaller marshaller = createSerializableMarshaller(this.knowledgeBase);
marshaller.marshall(droolsOut, this.session);
droolsOut.close();
System.out.println("written");
}
I used the above code to serialize the knowledgebase and session into a file
simultaneously and it works well. Then I used the following code to attempt
to deserialize them, but I failed.
private void deserialize(InputStream in) throws IOException,
ClassNotFoundException {
System.out.println("reading");
DroolsObjectInputStream droolsIn = new DroolsObjectInputStream(
(InputStream) in);
this.counter = droolsIn.readLong();
long clockTime = droolsIn.readLong();
this.knowledgeBase = (KnowledgeBase) droolsIn.readObject();
Marshaller marshaller = createSerializableMarshaller(this.knowledgeBase);
this.session = marshaller.unmarshall(droolsIn);
this.session.getSessionConfiguration().setOption(ClockTypeOption.get("pseudo"));
this.clock = (PseudoClockScheduler) session.getSessionClock();
this.clock.setStartupTime(clockTime);
droolsIn.close();
System.out.println("read");
}
In my other codes, I set the clock type of session to "pseudo" with a
KnowledgeSessionConfiguration
instance. However, when I serialized it, it's clock type was "realtime". It
seems that the some of session's
fields were not serialized.
So, I wonder are there any other ways to serialize a session? I heard about
XStream, is it appropriate to
serialize a session. And how?
Or, are there methods allowing me to set the clock type of a session to
"pseudo" after deserializing it?
Thank you very much!
--
View this message in context: http://drools.46999.n3.nabble.com/Serialization-issue-with-StateKnowledge...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
FireUntilHalt
by crajor
I have a fairly complicated drools program and I want to introduce temporal
reasoning to it. I spent a bit of time writing some proof-of-concept
programs to get the feel of fusion and then tried to slowly introduce things
into my original drools program. When I changed my program from using
fireAllRules() to using fireUntilHalt() on a separate thread, I suddenly get
failures in my unit tests. (My first thought was that there was a race
condition between my unit tests and the thread calling fireUntilHalt() so I
introduced a delay before my unit tests but no luck)
Here are some of the behaviors I am seeing.
1) I occasionally get nullpointerexception from the thread running
fireUntilHalt()
2) My lock-on-active rules aren't firing
I have banged my head on this a while with no success. (I even tried
putting fireAllRules() in a loop because of suggestions I saw but no luck
and same behavior). My questions are, Is there a secret to using
fireUntilHalt() that I am not aware of? Can anybody point me to where I can
educate myself on its proper use?
BTW no persistence and no spring in the code at this point.
Thanks, in advance, for any help you can provide.
Craig
--
View this message in context: http://drools.46999.n3.nabble.com/FireUntilHalt-tp4018610.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months