CEP sliding window in the past
by cfuser
Can you offset the sliding window functionality to look for a window in the
past? What I'm trying to do is offset the window from 'now'. E.g.
Assuming it is 12:05 and I have been receiving objects for 5 minutes, I'm
trying to get this to sum received objects between 2 and 3 minutes ago.
rule "Accumulate attempts over 1 minute (window over time)"
when
$measure : Number()
from accumulate( MyData( $m:measures["attempts"],
objectType=="climber" )
over window:time( 2m, 3m ) from entry-point "My Stream",
sum($m))
then
#
end
Looking at the SlidingTimeWindow source code, it looks as though you can't
offset the window by a delay? Is that accurate? If you can't do that
directly via a sliding window, is there a way to work around this?
TIA.
--
View this message in context: http://drools.46999.n3.nabble.com/CEP-sliding-window-in-the-past-tp331463...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 5 months
Help with URL resource caching
by benji2212
I'm using KnowledgeAgent to poll regularly for three DRL files hosted on a
web server. If the web server goes down for any reason or one of the DRL
files becomes unavailable, the change scanner and knowledge agent
unsubscribe from the resource(s) that were unavailable.
After reading some topics on the forum, I found that setting the
drools.resource.urlcache system property should correct this. However, I've
been unable to get this to work properly. The code I'm using is below. Any
insight into what I'm doing wrong would be appreciated. I'm using drools
5.1.1.
System.setProperty("drools.dateformat",
"MM/dd/yyyy");
System.setProperty("drools.resource.urlcache",
"C:\\Users\\0000000\\Documents\\rule-cache");
//start the scanner service and resource change notifier service
changeNotifier = ResourceFactory.getResourceChangeNotifierService();
changeScanner = ResourceFactory.getResourceChangeScannerService();
changeNotifier.start();
changeScanner.start();
kagent = KnowledgeAgentFactory.newKnowledgeAgent("My Knowledge Agent");
URL url = RulesRuntimeImpl.class.getResource(CHANGE_SET_PATH);
Resource drl = ResourceFactory.newUrlResource(url);
kagent.applyChangeSet(drl);
My change set file looks like this:
<change-set xmlns="http://drools.org/drools-5.0/change-set"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/change-set
drools-change-set-5.0.xsd" >
<add>
<resource source="http://mysite.com/test/FirstDecisionTable.drl"
type="DRL" />
<resource source="http://mysite.com/test/SecondDecisionTable.drl"
type="DRL" />
<resource source="http://mysite.com/test/ThirdDecisionTable.drl"
type="DRL" />
</add>
</change-set>
and the output I get when a resource in the change set becomes unavailable:
[9/21/11 10:49:28:015 EDT] 0000004e SystemOut O [2011:09:264
10:09:15:debug] ResourceChangeScanner attempt to scan 3 resources
[9/21/11 10:49:28:046 EDT] 0000004e SystemOut O [2011:09:264
10:09:46:debug] ResourceChangeScanner thread is waiting for 60 seconds.
[9/21/11 10:50:28:055 EDT] 0000004e SystemOut O [2011:09:264
10:09:55:debug] ResourceChangeScanner attempt to scan 3 resources
[9/21/11 10:50:28:259 EDT] 0000004e SystemOut O [2011:09:264
10:09:259:debug] ResourceChangeScanner removed resource=[UrlResource
path='http://mysite.com/test/FirstDecisionTable.drl']
[9/21/11 10:50:28:309 EDT] 0000004e SystemOut O [2011:09:264
10:09:309:debug] ResourceChangeNotification received ChangeSet notification
[9/21/11 10:50:28:345 EDT] 0000004e SystemOut O [2011:09:264
10:09:345:debug] ResourceChangeScanner thread is waiting for 60 seconds.
[9/21/11 10:50:28:426 EDT] 0000004f SystemOut O [2011:09:264
10:09:417:debug] ResourceChangeNotification processing ChangeSet
[9/21/11 10:50:28:535 EDT] 0000004f SystemOut O [2011:09:264
10:09:535:debug] ResourceChangeNotification ChangeSet removed
resource=[UrlResource path='http://mysite.com/test/FirstDecisionTable.drl']
for listener=org.drools.agent.impl.KnowledgeAgentImpl@6e5a6e5a
[9/21/11 10:50:28:560 EDT] 0000004f SystemOut O [2011:09:264
10:09:560:debug] KnowledgeAgent received ChangeSet changed notification
[9/21/11 10:50:28:611 EDT] 0000004f SystemOut O [2011:09:264
10:09:611:debug] ResourceChangeNotification thread is waiting for queue
update
[9/21/11 10:50:28:626 EDT] 00000050 SystemOut O [2011:09:264
10:09:625:info] KnowledgeAgent applying ChangeSet
[9/21/11 10:50:28:663 EDT] 00000050 SystemOut O [2011:09:264
10:09:663:debug] KnowledgeAgent removing mappings for resource=[UrlResource
path='http://mysite.com/test/FirstDecisionTable.drl'] with unsubscribe=true
[9/21/11 10:50:28:684 EDT] 00000050 SystemOut O [2011:09:264
10:09:684:debug] KnowledgeAgent notifier unsubscribing to
resource=[UrlResource path='http://mysite.com/test/FirstDecisionTable.drl']
[9/21/11 10:50:28:689 EDT] 00000050 SystemOut O [2011:09:264
10:09:689:debug] ResourceChangeNotification unsubscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@6e5a6e5a to
resource=[UrlResource path='http://mysite.com/test/FirstDecisionTable.drl']
[9/21/11 10:50:28:689 EDT] 00000050 SystemOut O [2011:09:264
10:09:689:debug] KnowledgeAgent rebuilding KnowledgeBase using ChangeSet
...
--
View this message in context: http://drools.46999.n3.nabble.com/Help-with-URL-resource-caching-tp336204...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 5 months
Issue using global 'variable' with Drools 5.2 in DRL
by Slorg1
Good evening,
I am porting our project from Drools 5.1 to Drools 5.2 and I am running into
a couple of issues. Most I solved except:
It seems that our global variable is being completely ignored.
I have declared the following after package & imports :
global java.util.Date now;
When calling it in a rule:
rule "MyRule"
when
EXPRESSION >= now.time
then
// things to do
end
Then I get the following error at 'compile' time :
Not possible to directly access the property 'time' of declaration 'now'
since it is not a pattern
I do not know what to make of it.
I have tried to change it to now.getTime() without success.
Thank you in advance for your help.
--
View this message in context: http://drools.46999.n3.nabble.com/Issue-using-global-variable-with-Drools...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 5 months
Ant Build of PKG with Declared Types
by TroyL
I am attempting to build a PKG utilizing an Ant Script. My DRL includes two
declared types. When the declared types have only one field the PKG will
compile but when the declared types have more than one field I get an error
stating that a class of that name was already found on the class path :
specifically the error states:
[compiler] Duplicate type definition. A class with the name XXXXXXX was
found in the classpath while trying to redefine the fields in the declare
statement. Fields can only be defined for non-existing classes.
My ant script:
<?xml version="1.0" encoding="UTF-8" ?>
<project default="rules">
<property name="projectPath" value="" />
<property name="droolsPath"
value="C:/Users/266571/Documents/drools-distribution-5.2.0.Final/binaries"
/>
<property name="eclipsePath"
value="C:/Users/266571/Documents/eclipse/plugins" />
<path id="drools.classpath">
<pathelement location="${droolsPath}/drools-ant-5.2.0.FINAL.jar" />
<pathelement location="${droolsPath}/drools-api-5.2.0.jar" />
<pathelement location="${droolsPath}/drools-core-5.2.0.FINAL.jar" />
<pathelement location="${droolsPath}/drools-compiler-5.2.0.FINAL.jar" />
<pathelement location="${droolsPath}/antlr-runtime-3.3.jar" />
<pathelement location="${droolsPath}/mvel2-2.0.19.jar" />
<pathelement location="${droolsPath}/knowledge-api-5.2.0.Final.jar" />
<pathelement
location="${eclipsePath}/org.eclipse.jdt.core_3.6.2.v_A76_R36x.jar" />
</path>
<path id="model.classpath">
<pathelement location="bin" />
</path>
<taskdef name="compiler" classpathref="drools.classpath"
classname="org.drools.contrib.DroolsCompilerAntTask" />
<target name="rules" >
<compiler
srcdir="${projectPath}src/rules"
tofile="${projectPath}src/rules/rules.pkg"
binformat="package"
classpathref="model.classpath" >
<include name="supportObjects.drl" />
</compiler>
</target>
</project>
My DRL:
package gov.ssa.codedObjects
import gov.ssa.codedObjects.SupportObjectsCollection;
declare SecondaryBrain
name : String
id : int
end
declare ICDCode
code : String
name : String
end
global SupportObjectsCollection supportObjectsList;
rule "Evaluate Coded Object"
when
$codedObject : CodedObject(code == 191.0)
then
SecondaryBrain brain = new SecondaryBrain();
brain.setName("Brain Tumor, Cerebrum");
insert (brain);
end
rule "Evaluate Coded Object Malignent"
when
$codedObject : CodedObject(code == "239.6" || code == "C71.9", $code :
code)
then
ICDCode code = new ICDCode();
code.setCode($code);
code.setName("Neoplasm of uspecified nature of the Brain");
insert(code);
end
rule "Add Brain Neoplasm to List"
when
$code : ICDCode(code == "239.6" || code == "C71.9")
then
supportObjectsList.addToSupportObjects($code);
end
rule "Megaduodenum"
when
$codedObject : CodedObject(code == "537.3" || code == "K59.3", $code :
code)
then
ICDCode code = new ICDCode();
code.setCode($code);
code.setName("Megaduodenum");
insert(code);
end
rule "Add Megaduodenum to List"
when
$code : ICDCode(code == "537.3" || code == "K59.3")
then
supportObjectsList.addToSupportObjects($code);
end
Any suggestions would be helpful.
--
View this message in context: http://drools.46999.n3.nabble.com/Ant-Build-of-PKG-with-Declared-Types-tp...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 5 months
Facing an inconsistent error executing rules during runtime
by S_Kumar_P@DELLTEAM.com
Hi,
I am getting an error at inconsistent intervals while executing one scheduled task, which uses rules, in Websphere AS. Below is the error trace,
[9/22/11 8:57:59:316 CDT] 0000004d SystemErr R Caused by: java.lang.ClassNotFoundException: autoclassification.Rule_10___10_Auto_Classification_0DefaultConsequenceInvoker
at java.lang.Class.forNameImpl(Native Method)
at java.lang.Class.forName(Class.java:163)
at org.drools.rule.DroolsCompositeClassLoader.loadClass(DroolsCompositeClassLoader.java:91)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at org.drools.rule.JavaDialectRuntimeData.wire(JavaDialectRuntimeData.java:312)
at org.drools.rule.JavaDialectRuntimeData.reload(JavaDialectRuntimeData.java:379)
at org.drools.rule.JavaDialectRuntimeData.onBeforeExecute(JavaDialectRuntimeData.java:139)
at org.drools.rule.DialectRuntimeRegistry.onBeforeExecute(DialectRuntimeRegistry.java:132)
at org.drools.compiler.PackageBuilder.reloadAll(PackageBuilder.java:683)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:641)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:266)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:458)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
at com.dell.compliance.middleware.ruleengine.RuleEngine.fire(RuleEngine.java:43)
The rules are:
package autoclassification;
import com.dell.compliance.middleware.business.Part;
import java.util.Map;
function boolean like(String masterData, String transData) {
boolean result = false;
if (masterData == null) {
return result;
}
if (transData != null && transData.trim().length() > 0) {
if (transData.trim().startsWith('%')
&& !transData.trim().endsWith('%')) {
result = masterData.endsWith(removeChar(transData));
}
else if (!transData.trim().startsWith('%')
&& transData.trim().endsWith('%')) {
result = masterData.startsWith(removeChar(transData));
}
else if (transData.trim().startsWith('%')
&& transData.trim().endsWith('%')) {
result = masterData.contains(removeChar(transData));
} else {
result = masterData.equals(transData);
}
}
return result;
}
function String removeChar(String transData) {
String str = transData.replaceAll('%', '');
return str;
}
function boolean validateTechAttribute(Map taMap, String attrNames, String attrVals) {
boolean result = false;
if (attrNames == null || attrVals == null) {
return true;
}
if(taMap == null){
return false;
}
String[] attrs = attrNames.split('[|]');
String[] values = attrVals.split('[|]');
String attr = null;
String value = null;
String attrVal = null;
for (int i = 0; i < attrs.length; i++) {
attr = attrs[i] != null ? attrs[i].trim().toUpperCase() : '';
value = values[i] != null ? values[i].trim().toUpperCase() : '';
if (taMap.containsKey(attr)) {
attrVal = (String) taMap.get(attr);
result = like(attrVal, value);
if(result==false){
return result;
}
} else {
return false;
}
}
return result;
}
rule '2 - 2_Auto Classification'
when
part : Part(eval (like(partType,'Hard Drive (NBK)')) , eval (like(partClass,'Drive,Hard')) , eval (validateTechAttribute(techAttrList,'Placement|Encrypted Drive','Internal|No')))
then
part.setPartDesc('HARD DRIVE-INTERNAL');
update(part);
drools.getWorkingMemory().clearAgenda();
end
rule '3 - 3_Auto Classification'
when
part : Part(eval (like(partType,'Hard Drive (NBK)')) , eval (like(partClass,'Drive,Hard')) , eval (validateTechAttribute(techAttrList,'Placement|Encrypted Drive','Internal|Yes')))
then
part.setPartDesc('HARD DRIVE-INTERNAL-ENCRYPTED');
update(part);
drools.getWorkingMemory().clearAgenda();
end
--
--
--
rule '9 - 9_Auto Classification'
when
part : Part(eval (like(partType,'Card,Network')) , eval (like(partClass,'CARD,NETWORK')) , eval (validateTechAttribute(techAttrList,'Wireless |SWIncludesEncryption','no|Yes')))
then
part.setPartDesc('POPULATED PCB-NETWORK-ADAPTER-ENCRYPTED');
update(part);
drools.getWorkingMemory().clearAgenda();
end
rule '10 - 10_Auto Classification'
when
part : Part(eval (like(partType,'Card,Wireless')) , eval (like(partClass,'CARD,NETWORK')) , eval (validateTechAttribute(techAttrList,'Wireless |SWIncludesEncryption','yes|Yes')))
then
part.setPartDesc('POPULATED PCB-NETWORK WIRELESS WLAN');
update(part);
drools.getWorkingMemory().clearAgenda();
end
And the Code loading rules is in RuleEngine.java as:
public void fire(byte[] rules, Object obj) {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
// this will parse and compile in one step
kbuilder.add(ResourceFactory.newByteArrayResource(rules),ResourceType.DRL);
// Check the builder for errors
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString());
throw new RuntimeException("Unable to compile drl.");
}
// get the compiled packages (which are serializable)
final Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
// add the packages to a knowledgebase (deploy the knowledge packages).
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(pkgs);
final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugWorkingMemoryEventListener());
// setup the audit logging
//KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "log/drools.log");
ksession.insert(obj);
ksession.fireAllRules();
//logger.close();
ksession.dispose();
}
We used Drools 5.1,
Please help me resolve as soon as possible.
Thanks & Regards
Santhosh
14 years, 5 months
Exception in Banking Tutorial in Drools expert guide...
by Manohar Kokkula
Hi,
I am trying to execute Banking Tutorial Example given in Drools expert(
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-expert/ht...
),but im getting following error,
Exception in thread "main" java.lang.ClassCastException:
java.util.ArrayList cannot be cast to org.hibernate.mapping.Collection
at com.sample.RuleRunner.runRules(RuleRunner.java:32)
at com.sample.Example1.main(Example1.java:5)
And when i try to resolve this i am getting another error:
java.lang.ArrayIndexOutOfBoundsException: 0
at com.code.RuleRunner.runRules(RuleRunner.java:45)
at com.code.Example1.main(Example1.java:5)
Code snippet :
for (int i=0; i <=facts.length;i++)
{
System.out.println("222");
Object fact = facts[i]; //The error is for this line of
code
System.out.println( "Inserting fact: " + fact );
ksession.insert(fact);
System.out.println("333");
}
could any body help me on this.
Manohar Kokkula
Mailto: manohar.kokkula(a)tcs.com
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
14 years, 5 months
persisted stateful sessions and knowledge base changes
by Jordi Alvarez
Hello, I am working for an organization for which we have adopted
Drools flow as the BPM solution. We are making use also of Drools
Expert, which results in a nice combination.
We have stateful sessions persisted in a database in order to record
the state of long-time running processes (which are the goal of our
BPM).
In order to make changes to the knowledge-base associated to the
stateful sessions that we have, we always redeploy the whole system
(ear application + rules + process definitions).
This is where we have the problem. Depending on the changes performed
to the database, the system is not able to reload the persisted
sessions (the change could be for example a change in the condition of
a rule). This results in problems and stack traces similar to the
following one:
[...]
Caused by: java.lang.RuntimeException: Unable to load session snapshot
at org.drools.persistence.session.JPASessionMarshallingHelper.loadSnapshot(JPASessionMarshallingHelper.java:96)
at org.drools.persistence.session.SingleSessionCommandService.initKsession(SingleSessionCommandService.java:196)
at org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:159)
... 95 more
Caused by: java.lang.ClassCastException: org.drools.reteoo.ObjectTypeNode
at org.drools.marshalling.impl.InputMarshaller.readRightTuple(InputMarshaller.java:401)
at org.drools.marshalling.impl.InputMarshaller.readRightTuples(InputMarshaller.java:391)
at org.drools.marshalling.impl.InputMarshaller.readFactHandles(InputMarshaller.java:326)
at org.drools.marshalling.impl.InputMarshaller.readSession(InputMarshaller.java:205)
at org.drools.marshalling.impl.DefaultMarshaller.unmarshall(DefaultMarshaller.java:91)
at org.drools.persistence.session.JPASessionMarshallingHelper.loadSnapshot(JPASessionMarshallingHelper.java:91)
... 97 more
According to some posts, if we were using the knowledge agent we could
update the already loaded sessions, which would allow to migrate
in-memory sessions from the old database to the new database:
http://drools.46999.n3.nabble.com/Dynamic-updates-of-stateful-sessions-td...
http://stackoverflow.com/questions/4368148/is-it-possible-to-add-a-new-ru...
Nevertheless, we absolutely need a way to migrate persisted sessions
from the old database to the new one. Even in the situation in which
we would allow hot modification of the knowledge base, we cannot have
all the stateful sessions loaded in memory when this would happen.
Is there any facility provided by Drools Expert/Flow that allows to
perform this operations easily? Is there a way/configuration to
load/save sessions without the need to store/retrieve the rete-tree
(and instead recomputing it), which seems to be the problem for these
situations.
Many thanks in advance,
Jordi Alvarez
14 years, 5 months
Persistence of events
by Maciej Prochniak
Hello,
Is it possible to persist events (from drools fusion) with default jpa
mechanism? When I try to do this 'just like that' I get exception
like
org.drools.common.DefaultFactHandle incompatible with
org.drools.common.EventFactHandle
It seems that session marshaller is not really aware of certain objects
being events, not facts.
The code I try is more or less like:
UserTransaction ut = ...
StatefulKnowledgeSession session = JPAKnowledgeService
.newStatefulKnowledgeSession(kbase, null, env);
ut.begin()
session.insert(e1);
ut.commit();
StatefulKnowledgeSession sessionPersisted =
JPAKnowledgeService.loadStatefulKnowledgeSession( session.getId(),
kbase, null, env );
ut.begin()
sessionPersisted.insert(e2); (*) <- fails
ut.commit();
When I use session instead of sessionPersisted - it works fine, when
e2 is a fact, not an event - it also works
I know that it may be awkward to persist events which have time
limitations, but I want to use time limits in rules which are like few
days - so I want to have some persistence in case of server shutdown.
I would be grateful for any comment,
br,
maciek prochniak
14 years, 5 months