DROOLS通过URL访问changset
package droolsRule; import java.net.Authenticator;
import java.net.PasswordAuthentication; import kafka.producer2.KafkaProducerTest; import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentConfiguration;
import org.drools.agent.KnowledgeAgentFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.Resource;
import org.drools.io.ResourceChangeScannerConfiguration;
import org.drools.io.ResourceFactory;
import org.drools.io.impl.UrlResource;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession; import bean.DroolsResult;
import bean.Reg; public class RuleFilter {
public StatefulKnowledgeSession ksession = null;
public KnowledgeRuntimeLogger logger = null;
public KnowledgeAgent kagent = null;
public RuleFilter()
{
} public void getKsessionObj() throws Exception
{ } public void dispose()
{
ksession.dispose();
logger.close();
ksession = null;
logger = null;
} public StatefulKnowledgeSession readKnowledgeBase(String path) throws Exception {
if(kagent == null)
{
ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
sconf.setProperty("drools.resource.scanner.interval", "10");
ResourceFactory.getResourceChangeScannerService().configure(sconf);
ResourceFactory.getResourceChangeScannerService().start();
ResourceFactory.getResourceChangeNotifierService().start(); // KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
// aconf.setProperty("drools.agent.scanDirectories", "true");
// aconf.setProperty("drools.agent.newInstance", "true"); // UrlResource urlResource2 = (UrlResource)ResourceFactory.newUrlResource("http://localhost:8080/guvnor-5.6.0.Final-tomcat-6.0/org.drools.guvnor.Guvnor/package/heatbeat/LATEST/ChangeSet.xml");
// urlResource2.setBasicAuthentication("enabled");
// urlResource2.setUsername("admin");
// urlResource2.setPassword("admin");
// urlResource2.setResourceType(ResourceType.PKG); } //String path = "http://192.168.61.104:8080/guvnor-5.6.0.Final-tomcat-6.0/org.drools.guvnor.Guvnor/package/stormETL/LATEST";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
UrlResource urlResource = ((UrlResource) ResourceFactory.newUrlResource(path));
urlResource.setBasicAuthentication("enabled");
urlResource.setUsername("admin");
urlResource.setPassword("admin");
kbuilder.add(urlResource, ResourceType.PKG);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
} KnowledgeAgentConfiguration conf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration(); Authenticator.setDefault(new Authenticator() { // Check https://issues.jboss.org/browse/JBRULES-3465 for any future changes. @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( "admin", "admin".toCharArray()); } }); kagent = KnowledgeAgentFactory.newKnowledgeAgent("kagent2",conf);
kagent.applyChangeSet(ResourceFactory.newUrlResource("http://localhost:8080/guvnor-5.6.0.Final-tomcat-6.0/org.drools.guvnor.Guvnor/package/heatbeat/LATEST/ChangeSet.xml"));
kagent.addEventListener(new MYEventListener());
// KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeBase kbase = kagent.getKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
ksession = kbase.newStatefulKnowledgeSession();
logger = KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
return ksession;
}
public void runRroolsRule(KafkaProducerTest kafkaProducter,Object fact,String value,StatefulKnowledgeSession ksession) throws Exception
{ long startTime = System.currentTimeMillis(); DroolsResult dMessage = new DroolsResult();
// ksession.setGlobal("kafkaProducerObj", kafkaProducter);
ksession.setGlobal("dMessage", dMessage);
ksession.setGlobal("value", value);
ksession.insert(fact);
ksession.fireAllRules();
dMessage = (DroolsResult)ksession.getGlobal("dMessage");
System.out.print("~~~~~~~~" + dMessage.getFilterResult());
System.out.println("||||||||||||" + ksession.getFactCount());
dMessage = null;
if(ksession.getFactCount() > 10000)
{
dispose();
ksession = null;
logger = null;
//initDrools(); } long endTime = System.currentTimeMillis();
System.out.println("filter use time:" + (endTime - startTime));
}
//http://192.168.61.104:8080/guvnor-5.6.0.Final-tomcat-6.0/org.drools.guvnor.Guvnor/package/heatbeat/LATEST/SCENARIOS
public static void main(String[] args) throws Exception{
KafkaProducerTest kafkaProducerObj = new KafkaProducerTest();
RuleFilter rf = new RuleFilter();
StatefulKnowledgeSession ksession = rf.readKnowledgeBase("http://192.168.61.104:8080/guvnor-5.6.0.Final-tomcat-6.0/org.drools.guvnor.Guvnor/package/stormETL/LATEST");
kafkaProducerObj.init(); long startTime = System.currentTimeMillis();
for(int i = 0;i<10;i++)
{
Reg reg = new Reg();
String str = "123";
reg.setImei1("1111111111111111");
reg.setMeid("111");
//System.out.println(i);
rf.runRroolsRule(kafkaProducerObj, reg, str,ksession);
// reg = null;
System.out.println("!!!!!!!!!!!!!!!!!!" + i);
}
long endTime = System.currentTimeMillis();
System.out.println("all use time is:" + (endTime - startTime)); }
}
今天做DROOLS 通过网络访问changset(大多是通过文件方式访问,但是感觉既然用上了guvnor代码再做文件实在没意思)搞了几个小时,总算可以访问了。到此记录下
DROOLS通过URL访问changset的更多相关文章
- ThinkPHP的URL访问
url访问 http://www.kancloud.cn/manual/thinkphp5/118012 ThinkPHP5.0在没有启用路由的情况下典型的URL访问规则是: http://serve ...
- 关于搭建webservice以及无法通过URL访问的简易解决办法
之前工作天天在用webservice,但是从没有自己独立的搭建一个全新的项目,今天好不容易自己搭了一个webservice,报错不少,记录下来免得以后又忘了. 一.搭建webservice需要做的几点 ...
- 针对功能权限(url访问)如何避免越权访问
你可以用request获得之前的页面路径:Request.getHeader("Referer");然后你可以判断一下,这个是字符串类型的. 如果是需要登录的,你可以从sessio ...
- VS2012 easyui datagrid url访问之坑
VS2012 easyui datagrid url访问之坑 url属性放的是地址的话 返回的json格式必须有 total 和 rows,如下: {"total":2," ...
- phpcms V9 MVC模式 与 URL访问解析
[1]URL访问解析 观察访问网页时的网址,可以得出模块访问方法,如下示例: http://www.abcd.com.cn/phpcms/index.php?m=content&c=index ...
- 怎么通过URL访问到服务器上的物理文件
目的 :搞清楚在jsp页面中如何引用static目录结构中的静态资源 一.URL URL的全称是统一资源定位符,俗称网页地址(网址),如同在网络上的门牌,是因特网上标准的资源的地址(Address). ...
- thinkphp四种url访问方式详解
本文实例分析了thinkphp的四种url访问方式.分享给大家供大家参考.具体分析如下: 一.什么是MVC thinkphp的MVC模式非常灵活,即使只有三个中和一个也可以运行. M -Model 编 ...
- [ThinkPHP]MVC模块和URL访问
## ThinkPHP 3 MVC模式和URL访问#讲师:赵桐正微博:http://weibo.com/zhaotongzheng 本节课大纲: 一.什么是MVC // ...
- phpcms(1)phpcms V9 MVC模式 与 URL访问解析(转)
[1]URL访问解析 观察访问网页时的网址,可以得出模块访问方法,如下示例: http://www.abcd.com.cn/phpcms/index.php?m=content&c=index ...
随机推荐
- 神经网络 (2)- Alexnet Training on MNIST
文章目录 Win10 Anaconda下配置tensorflow+jupyter notebook环境 AlexNet 识别MNIST Win10 Anaconda下配置tensorflow+jupy ...
- 【笔记篇】斜率优化dp(三) APIO2010特别行动队
旁听了一波给舒老师和学弟的pkuwc面试讲座... 这里有一段隐身的吐槽, 想看的请自己想办法观看. 不想看的跳过这一段看似空白的东西就好了... 刚开始ATP学姐给我们讲了自己面试的时候的事情..描 ...
- PHP算法之寻找两个有序数组的中位数
给定两个大小为 m 和 n 的有序数组 nums1 和 nums2. 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n)). 你可以假设 nums1 和 nums2 ...
- centos7 RPM命令安装操作
RPM 安装操作 命令: rpm -i 需要安装的包文件名 举例如下: rpm -i example.rpm 安装 example.rpm 包: rpm -iv example.rpm 安装 exam ...
- animation,transition,transform小练习
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- (上线时清缓存)laravel 5.1 的程序性能优化(配置文件) - 简书
代码上到正式环境后执行这六步 php artisan config:clear php artisan config:cache php artisan route:clear php artisan ...
- css----7渐变
linear-gradient(90deg,red 10%,yellow 20%,green 30%) <!DOCTYPE html> <html> <head> ...
- [JZOJ4330] 【清华集训模拟】几何题
题目 题目大意 也懒得解释题目大意了-- 正解 正解居然是\(FFT\)? 不要看题目的那个式子这么长,也不要在那个式子上下手. 其实我们会发现,不同的\((x_i-x_j,y_i-y_j,z_i-z ...
- XML、JSON、ProtocolBuffer特点比较
XML JSON PB Lua 数据结构支持 复杂结构 简单结构 较复杂结构 复杂结构 数据保存方式 文本 文本 二进制 文本 数据保存大小 大 一般 小 一般 解析效率 慢 一般 快 稍快 语言支持 ...
- 快速搭建Bootstrap
粘贴下面代码,快速开启Bootstrap的搭建: <!DOCTYPE html> <html lang="en"> <head> <met ...