Drools and serialize
by clement.pernot
Hi,
I want to serialize a StatefulKnowledgeSession in drools (which have rule
and fact)
Actually i know how to serialize a KnowledgeBase.
Here is my code for serialize a KnowledgeBase:
KnowledgeBuilder kBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add( ResourceFactory.newFileResource( "Sample.drl" ),
ResourceType.DRL );
if( kBuilder.hasErrors() ){
for( KnowledgeBuilderError err: kBuilder.getErrors() ){
System.err.println( err.toString() );
}
throw new IllegalStateException( "DRL errors" );
}
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );
OutputStream os = new FileOutputStream( "droolsCompiledFile" );
ObjectOutputStream oos = new ObjectOutputStream( os );
oos.writeObject( kBase );
oos.close();
This work fine, no problem here.
Here is my code for serialize a StatefulKnowledgeSession:
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add( ResourceFactory.newFileResource( "Sample.drl" ),
ResourceType.DRL );
if( kBuilder.hasErrors() ){
for( KnowledgeBuilderError err: kBuilder.getErrors() ){
System.err.println( err.toString() );
}
throw new IllegalStateException( "DRL errors" );
}
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );
try {
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
ksession.insert(message);
Marshaller marshaller = MarshallerFactory.newMarshaller(
ksession.getKnowledgeBase(), new ObjectMarshallingStrategy[]{
MarshallerFactory.newSerializeMarshallingStrategy() } );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectMarshallingStrategy oms =
MarshallerFactory.newIdentityMarshallingStrategy();
marshaller.marshall( baos, ksession );
ObjectOutputStream out = new ObjectOutputStream( baos );
out.writeObject( marshaller );
out.close();
baos.close();
ksession.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
But this didn't work.
I get always the same error:
"java.io.NotSerializableException"
I have try to not implement the "marshall" but this didn't work.
I don't know what I must do. Can someone help me?
Thank.
Best regards,
Clement Pernot
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-and-serialize-tp3161882p3161882....
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 8 months
BRMS on WebLogic
by Benson Fung
Hi,
Is there installation documentation how BRMS/Drools Guvnor is
installed on WebLogic server? Please help.
Thanks
Benson
14 years, 8 months
Temporal reasoning with external persistence not working
by Aman Teja
I am trying to use an external storage for loading and persisting objects.
But when I try a set a temporal reasoning rule it start to fail. The rule,
test code and exception are given below. Please help
// rules file
package foo.externalwm;
global foo.ExternalStorage session;
import foo.externalwm.YUser
import foo.externalwm.Test
declare User
@role(event)
end
declare Contest
@role(event)
end
rule "test"
dialect "java"
when
$c1:Contest() from session.getContestByName("Contest1")
User(this after[0,3m] $c1) from session.getUserByIndex(0)
then
System.out.println("rule fired");
end
// ************ code
public class Test {
public static void main(String[] args) throws Exception {
KnowledgeBaseConfiguration config =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption( EventProcessingOption.STREAM );
KnowledgeBase k = init(); // read and compile rules done here
final StatefulKnowledgeSession ksession =
k.newStatefulKnowledgeSession();
ExternalStorage session = new ExternalStorage();
ksession.setGlobal("session", session);
ksession.fireAllRules();
}
***********EXCEPTION
Exception in thread "main" org.drools.RuntimeDroolsException: Unexpected
exception executing action
org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction@669a4cb
at
org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:996)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:730)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:699)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
at foo.externalwm.Test.main(Test.java:55)
Caused by: java.lang.ClassCastException: org.drools.common.DefaultFactHandle
cannot be cast to org.drools.common.EventFactHandle
at
org.drools.base.evaluators.AfterEvaluatorDefinition$AfterEvaluator.evaluateCachedLeft(AfterEvaluatorDefinition.java:332)
at
org.drools.rule.VariableRestriction.isAllowedCachedLeft(VariableRestriction.java:110)
at
org.drools.rule.VariableConstraint.isAllowedCachedLeft(VariableConstraint.java:111)
at
org.drools.common.SingleBetaConstraints.isAllowedCachedLeft(SingleBetaConstraints.java:127)
at
org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:274)
at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:137)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:189)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:64)
at
org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:279)
at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:137)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:189)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.createAndPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:138)
at
org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:141)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
at
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:185)
at
org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:143)
at org.drools.reteoo.Rete.assertObject(Rete.java:107)
at
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:260)
at
org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:343)
at
org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:994)
... 4 more
--
View this message in context: http://drools.46999.n3.nabble.com/Temporal-reasoning-with-external-persis...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 8 months
accumulate Functions with self coded classes as result type
by Andre
i implemented an accumulate function which uses Datatypes, which i coded my
self , see example
the function return a list of ResourceMatch Objects, but when i try access
that objects i get an NullPointerrException (nothing more) (yes i imported
that class in the DRL)
so it seems that there has to be some kind of registration, so drools, can
handle these objectsm right ?
or what did i forget?
rule "Request counting analysed Resources By Id"
when
$list: List()
from accumulate($neu : RequestCtx() over
window:time(1m),countMatchingAnalysedResourcesInRequest($neu) )
ResourceMatch( $id: uri.toString(), count > 1 ) from $list
then
System.out.println( "Id " + $id + ": " );
System.out.println("Request counting Resources By Id Rule Workss");
channels["AuthZBlocking"].send(new ItemCacheEntry(new Item((String)$id),
new Date(System.currentTimeMillis()+ 8000)));
end
--
View this message in context: http://drools.46999.n3.nabble.com/accumulate-Functions-with-self-coded-cl...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 8 months
Any suggestions to implement exclusions and avoid update
by Wishing Carebear
Hi,
Below are 2 rules, rule1 has higher precedence than rule2. Rule2 should not
execute if Rule 1 executes.
1) One way to get this working is to check the null value.
2) If the update is not called, the Rule2 gets executed using the previous
null value of potentialTheftRating.
Is there any other way to implement this requirement.
rule "Rule 1 PotentialTheft0"
ruleflow-group "TheftRating0"
salience 10
no-loop
lock-on-active
when
$client : Client()
$policy : Service(productType == "Vehicle Insurance") from
$client.service
$car : Vehicle(potentialTheftRating == null, vehicleType ==
vehicleTypeType.CAR, convertible == Boolean.TRUE) from $policy.vehicle
then
modify ($car) {
setPotentialTheftRating( potentialTheftRatingType.HIGH )
}
update($client);
end
rule "Rule2 PotentialTheft0"
ruleflow-group "TheftRating0"
no-loop
lock-on-active
when
$client : Client()
$policy : Service(productType == "Vehicle Insurance") from
$client.service
$car : Vehicle(potentialTheftRating == null,vehicleType ==
vehicleTypeType.CAR, price >= 20000, price <= 45000, highTheftProbabilty ==
Boolean.FALSE ) from $policy.vehicle
then
modify ($car) {
setPotentialTheftRating( potentialTheftRatingType.MODERATE )
}
update($client);
end
14 years, 8 months
Writting a fusion query with specific time intervals
by Amila Suriarachchi
As I understood Drools fusion supports sliding windows which can either time
based on message length based. But can I write a query with specific time
intervals?
For an example Lets say my CEP engine recive events which has order value.
Now I want to fire an event if the orders within 8.00 am to 9.00 am have
less than $40000. In generally firing an event if there are less that $40000
total order value within any working hour (i.e 8.00 am 5.00 pm)
is it possible to do this?
--
View this message in context: http://drools.46999.n3.nabble.com/Writting-a-fusion-query-with-specific-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 8 months