java.lang.NullPointerException in simple example
by ahgiovanini
Hi guys!
I'm new in the world of jboss and drools and I'm making some simple examples
that existing on
https://github.com/droolsjbpm/drools/tree/master/drools-examples-api
Now, I'm studing the CashFlow example and in my project when I run it, I
receive a error message saying:
Exception in thread "main" java.lang.NullPointerException
at com.sample.CashFlowMain.main(CashFlowMain.java:30)"
I don't know the why this message, because I set the acp at lines 20 and 21.
Someone would help me please?
Thanks
package com.sample;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;
import java.text.SimpleDateFormat;
import java.util.Date;
public class CashFlowMain {
public static void main(String[] args) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
KieContainer kc =
KieServices.Factory.get().getKieClasspathContainer();
KieSession ksession = kc.newKieSession("CashFlowKS");
AccountPeriod acp = new AccountPeriod();
acp.setStart(date("2013-01-01")); // set acp - line 20
acp.setEnd(date("2013-03-31")); // set acp - line 21
Account ac = new Account(1, 0);
CashFlow cf1 = new CashFlow(date( "2013-01-12"), 100,
CashFlowType.CREDIT, 1 );
CashFlow cf2 = new CashFlow(date( "2013-02-2"), 200,
CashFlowType.DEBIT, 1 );
CashFlow cf3 = new CashFlow(date( "2013-05-18"), 50,
CashFlowType.CREDIT, 1 );
CashFlow cf4 = new CashFlow(date( "2013-03-07"), 75,
CashFlowType.CREDIT, 1 );
FactHandle fh = ksession.insert(acp);
ksession.insert( ac );
ksession.insert( cf1 );
ksession.insert( cf2 );
ksession.insert( cf3 );
ksession.insert( cf4 );
ksession.fireAllRules();
acp.setStart(date( "2013-04-01"));
acp.setEnd(date( "2013-06-31"));
ksession.update(fh, acp);
ksession.fireAllRules();
}
public static Date date(String str) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.parse( str );
}
}
--
View this message in context: http://drools.46999.n3.nabble.com/java-lang-NullPointerException-in-simpl...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 8 months
Cannot find KieModule: org.default:artifact:1.0.0-SNAPSHOT
by waynemetcalfe
I've seen this problem a few places while searching for a solution. Is it
possible to overcome this issue?
Drools version:6.0.0.Final
Java version: 1.7.0_45
Code snippet:
...
final KieServices ks = KieServices.Factory.get();
final KieRepository kr = ks.getRepository();
final KieFileSystem kfs = ks.newKieFileSystem();
//ruleScript is simply a string containing the rules
kfs.write("src/main/resources/com/company/test/rules/rules.drl",
ruleScript);
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
if (kb.getResults().hasMessages(Level.ERROR)){
configuration.getLog().error("\nSomething wrong here!\n\n");
}
final KieContainer kContainer =
ks.newKieContainer(kr.getDefaultReleaseId());
session = kContainer.newKieSession();
Exception:
java.lang.RuntimeException: Cannot find KieModule:
org.default:artifact:1.0.0-SNAPSHOT
at
org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:86)
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/Cannot-find-KieModule-org-default-artif...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 8 months
How to feed camel-server with kmodules using kie-ci?
by wogo
Hi,
I am trying to integrate drools-camel-server-example and kie-ci (6.0.1)
plugin.
My goal is to load modules from maven (built/deployed from kie-wb).
Maven configuration looks fine, as MavenSettings are initialized while
debugging (I see my repos).
I do everything locally to make things simpler.
Standalone code (from Eclipse) works fine with kie-cie - I execute
"Underage" rule from mortgages example.
I have built server with all kie-cie dependencies, however none of kmodules
deployed in Maven is loaded.
What am I missing? Is there anything special required in
knowledge-services.xml (I have used a default one provided originally in
.war)?
Do you have an example of mortgages obtained via camel-server?
Regards,
Wojciech
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-feed-camel-server-with-kmodules-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 8 months
Drools Fusion inconsistencies at increasing event throughputs
by Vieri
Dear Drools Experts,
*Short version*
1. Cron-based rules triggers (more than once) for a full second, rather
than once every defined period;
2. After some time, event creation from the drl seems to hang. The "time
to hang" decreases as we increase the throughput of incoming events;
3. The two issues seem to be somehow related (well, maybe).
*Full version*
We are testing Drools Fusion to implement CEP functionalities in our
platform. We are performing these tests using Drools 6.0.1.Final.
As a basic test case, we set up a synthetic stream of events, and defined a
couple of rules to implement a simple throughput metric. Here's the
complete drl:
*package* it.intext.unity.test
*import* it.intext.unity.test.SynthEvent;
*import* java.util.Date;
*global* org.slf4j.Logger logger;
*declare* SynthEvent
@role( event )
@timestamp( timestamp )
*end*
*declare* EventCounter
@role( event )
@timestamp( timestamp )
id : *long*
key : String
timestamp : Date
*end*
// Business rules
*rule* "Create counter"
*when*
$e : SynthEvent() *from* entry-point "synth"
*then*
entryPoints["counters"].*insert*(*new* EventCounter( $e.getId(), "event",
$e.getTimestamp() ) );
*end*
// Metrics
*rule* "Count epm"
// Emit count every 10s, accumulate over 1m
timer ( cron: 0/10 * * * * ? )
*when*
Number( $count : intValue ) *from* *accumulate*(
EventCounter( key == "event" ) over window:time( 60s
)*from*entry-point
"counters", count(1) )
*then*
logger.debug("epm = {}", $count );
*end*
The SynthEvent class is very basic:
*public* *class* SynthEvent {
*long* id;
Date timestamp;
List<String> meta;
... // Getters/Setters and constructors omitted
}
Now, the test is performed running the session in one thread (code below)
*private* *void* process(*final* KieSession session) {
*new* Thread(){
*public* *void* run() {
session.fireUntilHalt();
};
}.start();
}
while feeding the events on a second thread (code below)
*private* *void* feed(*final* KieSession session) {
*new* Thread(){
@SuppressWarnings("unchecked")
*public* *void* run() {
*try* {
*int* counter = 0;
*while*(*true*) {
counter++;
session.execute(CommandFactory.
*newInsert*(createEvent(), *null*, *false*, "synth"));
Thread.*sleep*(getSleepRate());
*if* ((counter % 1000) == 0) {
*logger*.debug("Total events: {}",
counter);
}
}
} *catch* (InterruptedException e) {
*logger*.warn("{}", e);
}
};
}.start();
}
I expected the cron rule "count epm" to trigger once every 10 seconds. But
here's an extract from the log (running at 5 events per second +/- 20%):
[DEBUG] 2014-03-25 04:56:10.008
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 1
[DEBUG] 2014-03-25 04:56:10.075
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 2
[DEBUG] 2014-03-25 04:56:10.262
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 3
[DEBUG] 2014-03-25 04:56:10.507
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 4
[DEBUG] 2014-03-25 04:56:10.678
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 5
[DEBUG] 2014-03-25 04:56:10.871
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 6
[DEBUG] 2014-03-25 04:56:20.001
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 50
[DEBUG] 2014-03-25 04:56:20.042
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 51
[DEBUG] 2014-03-25 04:56:20.231
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 52
[DEBUG] 2014-03-25 04:56:20.405
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 53
[DEBUG] 2014-03-25 04:56:20.647
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 54
[DEBUG] 2014-03-25 04:56:20.823
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 55
[DEBUG] 2014-03-25 04:56:20.992
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 56
As you can see, the "count epm" rules fires once per incoming event for a
full second (e.g. for the second cycle we see the first activation at
04:56:20.001 and the last one at 04:56:20.992).
This is not a major issue, since it can be solved with a sort-of
publish/subscribe pattern which, BTW, increases the system stability (if
anyone is interested I can post more details on the list).
Anyhow, the test ran for more than 20' consistently until we decided it was
enough.
Now, the problem is that as we increase the throughput (e.g. 50 events per
second), the test runs for a few minutes before it becomes inconsistent.
The evidence is that the first rule stops to trigger, and EventCounter
aren't created anymore. Here's a log extract:
[DEBUG] 2014-03-25 07:37:40.008
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 199
[DEBUG] 2014-03-25 07:37:40.017
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 200
[DEBUG] 2014-03-25 07:37:40.034
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 201
[DEBUG] 2014-03-25 07:37:40.058
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 202
[DEBUG] 2014-03-25 07:37:40.076
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 203
*... here the system is stable as we get about 3K events per minute as
expected*
[DEBUG] 2014-03-25 07:38:36.022 (StreamTester.java:run:70) Total events:
3000
[DEBUG] 2014-03-25 07:38:40.001
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 2999
[DEBUG] 2014-03-25 07:38:40.016
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 2998
[DEBUG] 2014-03-25 07:38:40.024
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 2999
[DEBUG] 2014-03-25 07:38:40.034
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 2998
[DEBUG] 2014-03-25 07:38:40.047
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 2999
[DEBUG] 2014-03-25 07:38:40.057
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 2998
...
[DEBUG] 2014-03-25 07:39:50.974
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 3008
[DEBUG] 2014-03-25 07:39:50.988
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 3007
[DEBUG] 2014-03-25 07:39:50.996
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 3008
[DEBUG] 2014-03-25 07:39:55.842 (StreamTester.java:run:70) Total events:
7000
*... Somewhere in between the system becomes inconsistent and the number of
events decreases to 0*
[DEBUG] 2014-03-25 07:40:00.001
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 2734
[DEBUG] 2014-03-25 07:40:00.017
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 2733
[DEBUG] 2014-03-25 07:40:00.037
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 2732
...
[DEBUG] 2014-03-25 07:40:50.937
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 181
[DEBUG] 2014-03-25 07:40:50.953
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 180
[DEBUG] 2014-03-25 07:40:50.975
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 179
[DEBUG] 2014-03-25 07:40:50.997
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 178
[DEBUG] 2014-03-25 07:40:55.438 (StreamTester.java:run:70) Total events:
10000
[DEBUG] 2014-03-25 07:41:00.001
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 0
[DEBUG] 2014-03-25 07:41:10.001
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 0
We added a quick rule to count "live EventCounter"
*rule* "Count live counters"
timer ( cron: 0/60 * * * * ? )
*when*
Number( $count : intValue ) *from* *accumulate*(
EventCounter( key == "event" ) *from* entry-point "counters",
count(1) )
*then*
logger.debug("Live counters = {}", $count );
*end*
and, again, the evidence is that when things go wrong the EventCounter
events aren't created anymore.
[DEBUG] 2014-03-25 07:40:55.438 (StreamTester.java:run:70) Total events:
10000
[DEBUG] 2014-03-25 07:41:00.001
(Rule_Count_live_counters1625367465.java:defaultConsequence:14) Live
counters = 0
[DEBUG] 2014-03-25 07:41:00.001
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 0
[DEBUG] 2014-03-25 07:41:10.001
(Rule_Count_epm442808096.java:defaultConsequence:14) epm = 0
Adding a debug line in the "Create counter" rule confirm this hypotesis
(after a while the rule won't trigger anymore). Modified rule is:
*rule* "Create counter"
*when*
$e : SynthEvent() *from* entry-point "synth"
*then*
entryPoints["counters"].*insert*( *new* EventCounter( $e.getId(),
"event", $e.getTimestamp() ) );
*if* (Math.random() < 0.01) logger.debug("New event: {}", $e.getId());
*end*
When the system becomes inconsistent, we stop seeing "New event" log lines.
What are we missing? Any suggestion? Anyone experienced the same problems
we have?
Your help will be greatly appreciated.
Thanks in advance,
Vieri
10 years, 8 months
Drools 6 and OSGi
by Florian Pirchner
Hi,
today i started to setup Drools 6 in my OSGi container. But it seems
there are some issues that do not allow to run drools 6 (and jbpm) under
OSGi properly.
For instance:
JPAKnowledgeService
.newStatefulKnowledgeSession(kieBase, null, env);
will never find "org.drools.persistence.jpa.KnowledgeStoreServiceImpl"
since it is not in the scope of the current ClassLoader.
Tried to tie things up, but then there would be a cyclic dependency
between kie-internal and jbpm-persistence-jpa.
I also could see, that a ProjectClassLoader was added. I found a way to
put my current BundleClassLoader as its parent into play. This solves a
lot of class loading issues.
For me it seems, that Drools 6 was not designed to run in an OSGi
container. Is there ongoing work to integrate Drools and JBPM Version
6.x into OSGi environments properly?
--
Thanks for your answer
Florian Pirchner
10 years, 8 months
Loading external KieModule fails with NullPointerException
by Jean-Philippe Steinmetz
Hello,
I am trying to set up a simple Drools (6.0.1.Final) application that pulls
a kmodule from an external jar that is installed in the local Maven
repository. Unfortunately when my code executes the newKieContainer method
it crashes with a NullPointerException.
Here is my code...
KieServices kieServices = KieServices.Factory.get();
ReleaseId releaseId = kieServices.newReleaseId("com.mycompany",
"mymodule", "1.0-SNAPSHOT");
KieContainer kContainer = kieServices.newKieContainer(releaseId);
And here is the output I get...
[pool-1-thread-1] INFO
com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of
application's worked threads is 16
[pool-3-thread-1] INFO
com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of
application's worked threads is 16
[pool-5-thread-1] INFO
com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of
application's worked threads is 16
[pool-7-thread-1] INFO
com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of
application's worked threads is 16
[pool-9-thread-1] INFO
com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of
application's worked threads is 16
[pool-11-thread-1] INFO
com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of
application's worked threads is 16
[pool-13-thread-1] INFO
com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of
application's worked threads is 16
[pool-15-thread-1] INFO
com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of
application's worked threads is 16
[pool-17-thread-1] INFO
com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of
application's worked threads is 16
Disconnected from the target VM, address: '127.0.0.1:51890', transport:
'socket'
Exception in thread "main" java.lang.NullPointerException
at
org.kie.scanner.KieRepositoryScannerImpl.addDependencies(KieRepositoryScannerImpl.java:128)
at
org.kie.scanner.KieRepositoryScannerImpl.buildArtifact(KieRepositoryScannerImpl.java:119)
at
org.kie.scanner.KieRepositoryScannerImpl.loadArtifact(KieRepositoryScannerImpl.java:90)
at
org.kie.scanner.KieRepositoryScannerImpl.loadArtifact(KieRepositoryScannerImpl.java:83)
at
org.drools.compiler.kie.builder.impl.KieRepositoryImpl.loadKieModuleFromMavenRepo(KieRepositoryImpl.java:113)
at
org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:99)
at
org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:76)
at
org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:84)
The module has the following dependencies listed in the pom.xml.
<dependencies>
<!-- Drools -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>${drools.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${drools.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>${drools.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-persistence-jpa</artifactId>
<version>${drools.version}</version>
<scope>compile</scope>
</dependency>
<!-- Misc -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
I have tried searching for help on this but am unable to find anything
related. Any help here is appreciated.
Thanks!
Jean-Philippe Steinmetz
10 years, 9 months
Resource scanning happens mpre than configured interval
by san_hegde
Hi,
I have configured Resource Scanner to scan at the interval of 3600 seconds(1 hr). But it actually scans 3 times in the duration of one hour.
My configuration is as below.
<drools:resource-change-scanner id="s1" interval="3600" />
When I checked the log file it actually scans 4 times in a hour.
Log is as below.
[2014-03-23 17:30:09,338:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 17:30:09,434:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
[2014-03-23 17:30:09,435:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 17:30:09,442:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
[2014-03-23 17:52:37,647:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 17:52:37,694:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
[2014-03-23 17:52:37,694:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 17:52:37,713:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
[2014-03-23 18:30:09,872:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 18:30:09,988:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
[2014-03-23 18:30:09,989:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 18:30:10,011:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
[2014-03-23 18:52:38,132:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 18:52:38,240:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
[2014-03-23 18:52:38,240:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 18:52:38,247:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
[2014-03-23 19:30:10,425:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 19:30:10,454:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
[2014-03-23 19:30:10,454:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 19:30:10,464:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
[2014-03-23 19:52:38,676:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 19:52:38,771:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
[2014-03-23 19:52:38,771:debug] ResourceChangeScanner attempt to scan 1 resources
[2014-03-23 19:52:38,796:debug] ResourceChangeScanner thread is waiting for 3600 seconds.
Any idea on why its not scanning only once in a hour..
Thank you
Santosh Hegde A
--
View this message in context: http://drools.46999.n3.nabble.com/Resource-scanning-happens-mpre-than-con...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 9 months