high memory usage for rules with more than 6 facts as condition
by murphy
Hello,
I did some tests to get an opinion about the performance of drools (5.0.1).
At one test I have a rule with 10 objects (same object-type) declared as
condition and got an OutOfMemoryException. I noticed that the memory usage
increases when I insert the last facts into my
StatefulKnowledgeSession. On fact 7 it increases with 10MB, on fact 8 with
46MB and on fact 9 with 170MB.
I debuged a little bit in the drools-source and noticed that the
LeftTupleMemory increased exponential with the number of facts I inserted.
My question about this behaviour:
Is a condition limited to a handful of facts or do I have to change the
syntax to get it working? I know that I could insert the same object-types
as a list, but assume that I have 10 facts with different object-types.
Thanks in reply,
Christian
--
View this message in context: http://n3.nabble.com/high-memory-usage-for-rules-with-more-than-6-facts-a...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 9 months
Grid analyzing with drools
by Vendetta
Hi folks,
I'm pretty new to Drools and try to figure out how to get the best
out of this technology.
The issue at hand is a two-layered grid analysis of a given area regarding
its threat-level, which is calculated by certain rules.
So let's get started by explaining the problem:
I have a rectangular area, which is sliced into a grid:
=> int[][] threatLvl = int[maxX][maxY], where threatLvl[myX][myY]
represents the threat-level of the certain block
I also do have information about the following:
the position of a ball (x/y)
the position of 5 friendly units (x/y)
the position of 5 enemy units (x/y)
the (constant) position of a goal (x0, y1 to y2)
the information about which team is in control of the ball
In case you were wondering: yes, it's about some kind of soccer ;)
My aim is to calculate a basic threat-level for each block based on the
following rules:
#1 a block is more dangerous, when there is a direct line between the block
and the goal (any point of the goal), which is not blocked by a
defensive/offensive unit ( => additional threat of T / 0.5*T )
#2 a block is more dangerous, when there is a direct line between the block
and the ball, which is not blocked by a defensive/offensive unit (+ threat T
/ 0.5*T)
#3 a block receives a higher threat-level for any offensive unit within a
certain range, the closer the unit, the higher the threat (something like
already calculated Threat-Amount times a factor, which is influenced by the
range)
#4 a block receives a lower threat-level for any defensive unit within a
certain range, the closer the unit, the lower the threat (something like
already calculated Threat-Amount divided by a factor, which is influenced by
the range)
Note additionally: the x/y of all units are their midpoints, the actual unit
has a (constant) radius of R, which has to be translated into an area,
effecting rules #1 and #2.
Secondly, I will divide my calculation into 2 layers in order to optimize.
At first, i will calculate the level for the midpoint of a (let's say)
5x5-block, if this block reaches a certain threat-level, i consider it
worthy being analyzed in depth, going through the rules again for every 1x1
block inside the 5x5 block.
My thoughts on solving this:
- Is this a problem i should solve with Drools (being more of a rhetorical
question ;D )
- Given it is: Should i declare one large rule (which crosses my
comprehension of drools) or can i split this up into multiple rules
- i know i can create rule-groups and control, that rules #3 and #4 are
fired after #1 and #2, in order to ensure i multiply the correct numbers
- i feel the extremely powerful accumulate functions are just what i need,
yet i can't figure how to use them efficiently in this case
Lastly, i want to state that i do of course _not_ seek some kind of complete
implementation, but rather draw on your experience and learn how to approach
this issue.
Thanks to anyone, who is willing to spend his time to think about this issue
with me :)
Vendetta
--
View this message in context: http://n3.nabble.com/Grid-analyzing-with-drools-tp718061p718061.html
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 9 months
Drools Planner: Exception on createSolver method
by dweppenaar
Hi,
I am new to Drools in general so please excuse my noobness with some of the
concepts. I am in the process of creating a maintenance scheduling system.
As Geoffrey suggested, I have based my application heavily on the curriculum
course example included in the solver (planner) examples. I have created
most of the classes used by the example and will be implementing my gui.
I use an XmlSolverConfigurer to read the configuration from xml. The solver
config xml path is correct as I get another exception due to the file not
being found when I change the path. When the solver tries to load the xml
configuration the following exception occurs:
Exception in thread "AWT-EventQueue-0"
com.thoughtworks.xstream.converters.ConversionException: environmentMode :
environmentMode : environmentMode : environmentMode
---- Debugging information ----
message : environmentMode : environmentMode
cause-exception :
com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : environmentMode : environmentMode
class :
org.drools.solver.config.localsearch.LocalSearchSolverConfig
required-type :
org.drools.solver.config.localsearch.LocalSearchSolverConfig
line number : 12
-------------------------------
at
com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:89)
at
com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:63)
at
com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:76)
at
com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:60)
at
com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:137)
at
com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:33)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:923)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:909)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:853)
at
org.drools.solver.config.XmlSolverConfigurer.configure(XmlSolverConfigurer.java:68)
at
org.drools.solver.config.XmlSolverConfigurer.configure(XmlSolverConfigurer.java:59)
at
org.drools.solver.config.XmlSolverConfigurer.configure(XmlSolverConfigurer.java:52)
at
za.co.rgems.projects.imms.swing.gui.ImmsGui.createSolver(ImmsGui.java:95)
at
za.co.rgems.projects.imms.swing.gui.ImmsGui.createSolutionBusiness(ImmsGui.java:103)
at
za.co.rgems.projects.imms.swing.gui.ImmsGui.btnSolveActionPerformed(ImmsGui.java:76)
at
za.co.rgems.projects.imms.swing.gui.ImmsGui.access$000(ImmsGui.java:23)
at
za.co.rgems.projects.imms.swing.gui.ImmsGui$1.actionPerformed(ImmsGui.java:50)
at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException:
environmentMode : environmentMode
at
com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:68)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:71)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:88)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:86)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:96)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at
com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:52)
at
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.determineType(AbstractReflectionConverter.java:347)
at
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:208)
at
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:162)
at
com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:82)
... 41 more
Here is the contents of my XML configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<localSearchSolver>
<environmentMode>REPRODUCIBLE</environmentMode>
<scoreDrl>/za/co/rgems/projects/imms/drl/immsRules.drl</scoreDrl>
<scoreDefinition>
<scoreDefinitionType>HARD_AND_SOFT</scoreDefinitionType>
</scoreDefinition>
<termination>
<scoreAttained>0hard/-5000soft</scoreAttained>
</termination>
<startingSolutionInitializerClass>za.co.rgems.projects.imms.solution.initialiser.ImmsStartingSolutionInitialiser</startingSolutionInitializerClass>
<finish>
<maximumSecondsSpend>300</maximumSecondsSpend>
</finish>
<selector>
<selector>
<topSize>10</topSize>
</selector>
<selector>
<moveFactoryClass>za.co.rgems.projects.imms.move.factory.MaintenanceSlotMoveFactory</moveFactoryClass>
<relativeSelection>0.002</relativeSelection>
</selector>
<selector>
<moveFactoryClass>za.co.rgems.projects.imms.move.factory.MaintenanceTaskSwitchFactory</moveFactoryClass>
<relativeSelection>0.002</relativeSelection>
</selector>
<selector>
<moveFactoryClass>za.co.rgems.projects.imms.move.factory.MaintenanceTechnicianChangeMoveFactory</moveFactoryClass>
<relativeSelection>0.002</relativeSelection>
</selector>
<selector>
<moveFactoryClass>za.co.rgems.projects.imms.move.factory.MotorChangeMoveFactory</moveFactoryClass>
<relativeSelection>0.002</relativeSelection>
</selector>
</selector>
<accepter>
<completePropertyTabuSize>10</completePropertyTabuSize>
<completeSolutionTabuSize>1500</completeSolutionTabuSize>
</accepter>
<forager>
<foragerType>MAX_SCORE_OF_ALL</foragerType>
</forager>
</localSearchSolver>
I am not sure why this occurs and I have also searched the forums/mailing
list to no avail. I have been through the documentation on the configuration
file as well as several of the example applications' config files, but fail
to see what is the cause.
Thank you in advance!
Regards,
De Ville Weppenaar
--
View this message in context: http://n3.nabble.com/Drools-Planner-Exception-on-createSolver-method-tp71...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 9 months
Newbie Trap
by Kurt Guenther
I followed the 5.0 install docs:
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-introduct...
And used the "Create a new Drools 5 runtime....", but I ran into an issue:
org.drools.RuntimeDroolsException: Unable to load dialect
'org.drools.rule.builder.dialect.java.JavaDialectConfiguration:java:org.drools.rule.builder.dialect.java.JavaDialectConfiguration'
at
org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:274)
at
org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuilderConfiguration.java:259)
at
org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:176)
at
org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:153)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:242)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:142)
at
org.drools.builder.impl.KnowledgeBuilderProviderImpl.newKnowledgeBuilder(KnowledgeBuilderProviderImpl.java:29)
at
org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:29)
at com.sample.DroolsTest.readKnowledgeBase(DroolsTest.java:39)
at com.sample.DroolsTest.main(DroolsTest.java:23)
Caused by: java.lang.RuntimeException: The Eclipse JDT Core jar is not in
the classpath
at
org.drools.rule.builder.dialect.java.JavaDialectConfiguration.setCompiler(JavaDialectConfiguration.java:94)
at
org.drools.rule.builder.dialect.java.JavaDialectConfiguration.init(JavaDialectConfiguration.java:55)
at
org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:270)
... 9 more
It works fine when I downloaded the 5.0 binaries and just pointed it at
this.
Plz, let me know if there is a better place to report these issues. Also,
I found a bunch of documentation nits that I'd like to eventually report.
--Kurt
14 years, 9 months
Undeploy problem with Tomcat
by Thomas Carolan
I'm deploying a web application with drools 5.0 on Tomcat 6. Several jars remain "locked" on the file system after I undeploy the application. The jars are "drools-compiler.jar" and "drools-core.jar". I am also using a RuleFlow and that file remains locked on the filesystem when undeploying the application as well. I'm assuming that this is a ClassLoader issue or some other unreleased resource by Drools.
My question is, has anybody experienced this issue before and how can it be resolved? I'm use dispose() on the KnowledgeSession each time but I never perform any cleanup of the KnowledgeBase. Is that necessary?
I also have tried each method of adding rules/rule flows to the KnowledgeBase (File, URL, ClassPathResource) and each type has the same locking issue.
Thomas Carolan
14 years, 9 months
junit tests for drools rules
by Radhakrishnan Meiappan
I'm trying to test some rules from a junit test. Inside the rule the
fact is modified.
The fact is setup so that it matches the then condition in the rule, but
still my asserts are failing in my test.
How do I get the fact back from the session, after the rules are fired.
Can someone point me to a link that has samples for testing a rule from
a junit test. Its hard to find.
Thanks
RK.
14 years, 9 months
Issue with drools-flow/persistence
by Daniel Ilkovich
I'm stumped. I'm trying to implement persistence with Drools-flow, and I'd
like to grab the value of a property on a workitem / processinstance, but
everytime I try to get the workitem or process instance I end up with the
stack trace below.
I'm walking through the source and from what I can tell, this happens
anytime I try and grab a property that is annotated with @Lob in an entity
class.
My environment is hibernate/mysql/JPA persistence using BTM as a transaction
manager.
These are the relevant lines of code:
ksession =
JPAKnowledgeService.loadStatefulKnowledgeSession(ksession.getId(), m_kbase ,
null, m_environment);
m_pi = ksession.getProcessInstance(m_pi.getId());
What am I doing wrong?
<pre>
<code>
java.lang.NullPointerException
at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:89)
at
org.drools.persistence.processinstance.ProcessInstanceInfo.getProcessInstance(ProcessInstanceInfo.java:135)
at
org.drools.persistence.processinstance.JPAProcessInstanceManager.getProcessInstance(JPAProcessInstanceManager.java:62)
at
org.drools.common.AbstractWorkingMemory.getProcessInstance(AbstractWorkingMemory.java:1793)
at
org.drools.impl.StatefulKnowledgeSessionImpl.getProcessInstance(StatefulKnowledgeSessionImpl.java:261)Hibernate:
select at
org.drools.command.runtime.process.GetProcessInstanceCommand.execute(GetProcessInstanceCommand.java:29)
at
org.drools.command.runtime.process.GetProcessInstanceCommand.execute(GetProcessInstanceCommand.java:12)
at
org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:254)
at
org.drools.command.impl.CommandBasedStatefulKnowledgeSession.getProcessInstance(CommandBasedStatefulKnowledgeSession.java:95)
at
com.thoughtvine.tracks.workflow.TracksFlow.getParameterFromWorkItem(TracksFlow.java:182)
at
com.thoughtvine.tracks.workflow.test.TestTracksFlow.testGetWorkItem(TestTracksFlow.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
</code>
</pre>
14 years, 9 months
Performance comparasion of D3.0 and D5.0
by Agrawal, Swapnil
Hi
Do we have a performance comparison chart between Drools 3.0 and Drools 5.0?
I see we have one between 4.0 amd 5.0 and one between 2.5 and 3.0.
But missing the 3.0 and 5.0 comparison.
We recently moved to 5.0 from 3.0 and see significant drop in performance.
Need to check if the drop is related to our application structure or it is due to the upgrade of drools.
Thanks
Swapnil Agrawal
cell: 201 616 1189
desk: 212 816 7024
14 years, 9 months
drools-fusion: rule firing erroneously for the first time in a sliding window
by Badrinath, Shyam
Hi
I am using Drools 5.1.0 M1 within Eclipse. I am trying out a sample
rule, which fires if the minimum cpu is over 80 for 5s using sliding
windows. I see that it works well over a running window of 5s, but for
the first time, it fires even before reaching 5s.
It seems to ignore the fact that 5s hasn't elapsed yet. I am using the
engine in STREAM mode and using a pseudo clock to advance the time
manually.
Is this the expected behavior? Thanks!
sb
Here is the rule:
package org.drools.examples
import org.drools.examples.CpuMetric.Cpu;
import org.drools.examples.CpuMetric.Alarm;
global org.apache.log4j.Logger logger
declare Cpu
@role(event)
@expires(5s)
end
rule "Above Cpu threshold of 80 for 5s"
dialect "java"
when
not Alarm()
$cpuMin : Number(intValue >= 80) from accumulate(
$cpu : Cpu($v : value) over window:time(5s), min($v)
)
then
logger.info("Cpu above 80 for 5 s, raising alarm. min cpu:
"+$cpuMin);
Alarm a = new Alarm();
a.setReason("raised alarm as we hit cpu threshold");
a.setTime(System.currentTimeMillis());
insert(a);
end
Here is the snippet of the class that declares the Cpu and Alarm class
as well inserts events into the rule engine. The other thing I noticed
is the accumulate function seems to ignore the regex in the <src
pattern>. For example, in the rule above, if I give
$cpuMin : Number(intValue >= 80) from accumulate(
$cpu : Cpu($v : value, srcIp =='<val1>' && destIp == '<val2>') over
window:time(5s), min($v)
And insert cpu events, with no matching srcIp and destIp, I shouldn't
see any alarm raised, but I do and right at the beginning.
. . ... (code before this..)
//to use sliding windows, have to run the engine in stream mode
//default is cloud mode..where there are no concept of time and
//event ordering
KnowledgeBaseConfiguration kbaseconfig =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbaseconfig.setOption(EventProcessingOption.STREAM);
// add the packages to a knowledgebase (deploy the knowledge
packages).
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase(kbaseconfig);
kbase.addKnowledgePackages(pkgs);
KnowledgeSessionConfiguration conf =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ClockTypeOption.get("pseudo"));
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession(conf, null);
//get clock to manually advance and test firing..
SessionPseudoClock clock = ksession.getSessionClock();
logger.info("Pseudo clock current time: "+clock.getCurrentTime());
ksession.setGlobal("logger", logger);
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugWorkingMemoryEventListener());
// setup the audit logging
KnowledgeRuntimeLogger krlogger = KnowledgeRuntimeLoggerFactory
.newFileLogger(ksession, "log/cpu");
BufferedReader bf = new BufferedReader(new
FileReader("/opt/cpumetricdata.txt"));
String s;
long time=0;
int count=0;
long lastime=0;
int delta=0;
//logger.info("Advancing 5s right at the start");
//clock.advanceTime(5000, TimeUnit.MILLISECONDS);
while((s = bf.readLine()) != null)
{
String[] vals = s.split(",");
Cpu cpumetric = new Cpu();
cpumetric.setValue(Integer.parseInt(vals[1]));
//set in ms
//for the first time, initialize time and lastime
//to the value read in from the first line.
time = Long.parseLong(vals[0]);
if(count ==0)
{
lastime = time;
logger.info("Initialized lastime to "+lastime);
}
cpumetric.setTime(time);
cpumetric.setSrcIp("10.155.21.86");
cpumetric.setDestIp("10.6.35.120");
logger.info("Inserted cpu metric "+cpumetric);
logger.info("Count: "+count+" Pseudo clock current time:
"+clock.getCurrentTime());
ksession.insert(cpumetric);
ksession.fireAllRules();
//advance based on the read in time in ms
//do it only from the second insert onwards
delta=(int) (time-lastime);
if(count >=1)
{
clock.advanceTime(delta, TimeUnit.MILLISECONDS);
logger.info("Pseudo clock advanced "+delta+ "ms");
}
count++;
lastime=time;
}
System.out.println("Inserted facts, current time is "+new Date());
krlogger.close();
ksession.dispose();
bf.close();
}
public static class Alarm
{
private String reason;
private long time;
private String type;
/**
* @return the reason
*/
public String getReason()
{
return reason;
}
/**
* @param reason the reason to set
*/
public void setReason(String reason)
{
this.reason = reason;
}
/**
* @return the time
*/
public long getTime()
{
return time;
}
/**
* @return the type
*/
public String getType()
{
return type;
}
/**
* @param type the type to set
*/
public void setType(String type)
{
this.type = type;
}
/**
* @param time the time to set
*/
public void setTime(long time)
{
this.time = time;
}
}
public static class Cpu implements Serializable
{
private long time;
private int value;
private String srcIp;
private String destIp;
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return "Cpu [time=" + time + ", value=" + value + "]";
}
/**
* @return the time
*/
public long getTime()
{
return time;
}
/**
* @param time the time to set
*/
public void setTime(long time)
{
this.time = time;
}
/**
* @return the srcIp
*/
public String getSrcIp()
{
return srcIp;
}
/**
* @param srcIp the srcIp to set
*/
public void setSrcIp(String srcIp)
{
this.srcIp = srcIp;
}
/**
* @return the destIp
*/
public String getDestIp()
{
return destIp;
}
/**
* @param destIp the destIp to set
*/
public void setDestIp(String destIp)
{
this.destIp = destIp;
}
/**
* @return the value
*/
public int getValue()
{
return value;
}
/**
* @param value the value to set
*/
public void setValue(int value)
{
this.value = value;
}
}
}
Data that drives the insertion:
1358,81
2359,86
3360,88
4361,80
5362,84
6363,80
7364,83
8365,99
9366,97
10367,99
14 years, 9 months
Re: [rules-users] questions on guvnor and drools 5.0
by Libor Nenadál
Hi Jean!
Dne 13. dubna 2010 19:41 Jean-Denis Maroie [via Drools - Java Rules Engine]
<ml-node+716101-1775405691-43605(a)n3.nabble.com<ml-node%2B716101-1775405691-43605(a)n3.nabble.com>
> napsal(a):
>
> In the test scenario I want to create a list of objects and apply some
> rules on it. But Im unable to create my list in the test scenario. When I
> have to enter the value of the method "add" of my list I only can type
> integers. I want to enter a variable's name containing an object created
> before.
>
> Did you try the method with equal sign I wrote about in the previous post?
I.e. if your object is named myObject, fill to the edit box =myObject. I
just want to be sure.
BR,
Libor
--
View this message in context: http://n3.nabble.com/questions-on-guvnor-and-drools-5-0-tp58616p716193.html
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 9 months