package com.test;
import ilog.rules.archive.IlrJarArchiveLoader;
import ilog.rules.engine.IlrContext;
import ilog.rules.engine.IlrParameterMap;
import ilog.rules.engine.IlrRuleset;
import ilog.rules.engine.IlrRulesetArchiveParser;
import ilog.rules.teamserver.brm.IlrBaseline;
import ilog.rules.teamserver.brm.IlrRuleProject;
import ilog.rules.teamserver.client.IlrRemoteSessionFactory;
import ilog.rules.teamserver.model.IlrArchiveOutput;
import ilog.rules.teamserver.model.IlrDefaultSearchCriteria;
import ilog.rules.teamserver.model.IlrSession;
import ilog.rules.teamserver.model.IlrSessionFactory;
import ilog.rules.teamserver.model.IlrSessionHelper;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.util.jar.JarInputStream;
import com.demo.dto.Driver;
import com.demo.dto.Result;
public class InvokeRuleSet {
//A remote implementation of a session factory.
private static IlrSessionFactory factory = new IlrRemoteSessionFactory();
private static String userName = "rtsAdmin";
private static String passWord = "rtsAdmin";
private static String url = "http://localhost:8080/teamserver";
private static String dataSource = "jdbc/ilogDataSource";
private static String projectName = "RuleDemo2";
private static ThreadLocal<IlrContext> localEngine = new ThreadLocal<IlrContext>();
public static void invokeIlrJar() throws Exception{
// This class is a parser of ruleset archives. The archive is given as a stream. The parsing provides:
// a ruleset.
// a business reflect used in the case of a business ruleset archive.
// an execution reflect, used to create the provided ruleset.
IlrRulesetArchiveParser parser = new IlrRulesetArchiveParser();
//Creates an archive loader which relies on a jar stream.
IlrJarArchiveLoader ruleArchvieLoader = new IlrJarArchiveLoader(
new JarInputStream(new FileInputStream("/demo2.jar")));
//Parses the ruleset archive.
parser.parseArchive(ruleArchvieLoader);
//Get a ruleset issued from a ruleset archive parsing.
IlrRuleset rtsRuleSet = parser.getRuleset();
//IlrContext is the base class of all the execution contexts. Rules can be executed only within an execution context.
//In ILOG JRules, the rule engine is an instance of IlrContext, the rule engine is simply a Java object.
//An IlrContext instance is always attached to an IlrRuleset. If the context is created without a ruleset passed as an argument, it creates its own ruleset.
//An IlrContext instance contains all the methods required to control the rule engine. IlrRuleset is responsible for rule management, IlrContext is responsible for rule execution.
IlrContext context = new IlrContext();
context.setRuleset(rtsRuleSet);
//Implements a structure for storing parameter values to set or get from ruleset variables. Each parameter is stored with its name and its value.
IlrParameterMap paramMap = new IlrParameterMap();
Driver vhl = new Driver();
vhl.setAge(6);
vhl.setSex('1');
//vhl.setNme("zs");
//Store for the parameter "name" and its value "value".
paramMap.setParameter("drv", vhl);
//Sets the values of the declared ruleset variables contained in the passed IlrParameterMap (defined either with the "in" or "inout" modifier).
context.setParameters(paramMap);
//Executes the ruleflow defined in the context's ruleset.
//Executes the task passed as the argument.
//context.execute(taskName);
context.execute();
//Gets the value of the ruleset parameter.
//Returns the values of the "out" ruleset variables (those defined either with the "inout" or "out" modifier).
//IlrParameterMap rpm = context.getReturnValues();
Result r = (Result) context.getParameterValue("res");
System.err.println(r.getResult());
//Disconnects all connected IlrTool.
context.disconnectTools();
//Called by Rule Studio to prepare a context for another execution.
context.reset();
}
public static void ilrRemote() throws Exception {
//Connects the given user to Rule Team Server.
factory.connect(userName, passWord, url, dataSource);
IlrSession session = factory.getSession();
// get the project by name
IlrRuleProject ruleProject = (IlrRuleProject) IlrSessionHelper
.getProjectNamed(session, projectName);
// open current baseline
IlrBaseline currentBaseline = IlrSessionHelper.getCurrentBaseline(
session, ruleProject);
session.setWorkingBaseline(currentBaseline);
//IlrDefaultSearchCriteria is the default implementation of IlrSearchCriteria. It is used to specify the search criteria passed to the findElements search methods of an IlrSession object.
IlrSearchCriteria criteria = new IlrDefaultSearchCriteria("查找 所有 规则");
//Generates a ruleset archive for the given query and extractor validator symbol.
//If the preference ilog.rules.teamserver.buildCheckArchive is set to true, then the archive is checked just after being generated.
//When errors are found during the archive generation or the check:
//If the severity of the error is greater than or equal to the preference ilog.rules.teamserver.rulesetGenerationAbortLevel, an exception is thrown and the returned IlrArchiveOutput is null.
//Otherwise, the error is put in the error list of the archive output.
IlrArchiveOutput jarOutArray = session.generateRulesetArchive(criteria,null,projectName);
session.close();
IlrRulesetArchiveParser parser = new IlrRulesetArchiveParser();
IlrJarArchiveLoader ruleArchvieLoader = new IlrJarArchiveLoader(
new JarInputStream(new ByteArrayInputStream(jarOutArray.getBytes())));
parser.parseArchive(ruleArchvieLoader);
IlrRuleset rtsRuleSet = parser.getRuleset();
IlrContext context = localEngine.get();
if (context == null) {
context = new IlrContext();
context.setRuleset(rtsRuleSet);
localEngine.set(context);
}
IlrParameterMap paramMap = new IlrParameterMap();
Driver vhl = new Driver();
vhl.setAge(6);
vhl.setSex('1');
paramMap.setParameter("drv", vhl);
context.setParameters(paramMap);
context.execute();
Result r = (Result) context.getParameterValue("res");
System.err.println(r.getResult());
context.disconnectTools();
context.reset();
}
public static void main(String[] args) throws Exception {
ilrRemote();
}
}
jrules-engine.jar
jrules-language.jar
jrules-res-execution.jar
jrules-res-session-ejb3-WAS7_stub.jar
jrules-res-session-ejb3-WASCE21.jar
jrules-ruleartifacts.jar
jrules-teamserver.jar
分享到:
相关推荐
总结来说,Java调用ILOG规则集有两种主要方式:一是通过ExecutionServer和ExecutionSession进行规则的生命周期管理,二是直接操作ReteOO引擎进行规则匹配和执行。这两种方法各有优缺点,适用于不同的场景和需求。在...
Java API是CPLEX提供的一种编程接口,使得开发者能够用Java语言方便地调用CPLEX的功能。在这个压缩包文件中,包含的是ILOG CPLEX Java API的官方文档,格式为HTML,适合离线查阅。 首先,让我们深入了解一下ILOG ...
在 C# 中调用 ILOG CPLEX,需要引用 `ILOG.CONCERT.DLL` 和 `ILOG.CPLEX.DLL` 库,并导入 `ILOG.CONCERT` 和 `ILOG.CPLEX` 命名空间。初始化 `Cplex` 对象后,可以按以下步骤构建和求解模型: 1. 创建决策变量数组 ...
这部分主要在将ILOG OPL的入门知识,以及一些简单的示例,可以帮助你快速入门。
首先,为了在Java中调用Cplex,你需要安装IBM ILOG CPLEX Optimization Studio,其中包含了Java接口。安装完成后,确保JAR文件(如cplex.jar)已被添加到Java项目的类路径中。这些JAR文件提供了必要的API,使Java...
Java调用Cplex主要通过ILOG CPLEX Optimization Studio提供的Java API来实现。这个API提供了丰富的类和方法,使得开发者可以方便地构建模型,设置参数,并执行求解过程。 1. **Java调用Cplex步骤**: - **导入库**...
2. **使用示例**:提供使用 ILOG CPLEX 或 JRules 解决具体问题的代码示例,展示如何定义模型、编写规则和调用 API。 3. **性能优化**:分享如何优化 ILOG 工具的性能,如调整参数、使用并发和内存管理等。 4. **...
总之,ILOG是一款强大的业务规则管理工具,通过百度云盘分享的安装包提供了一种便捷的获取途径。用户在下载安装过程中,需遵循正确的步骤,确保安装顺利完成,并充分利用其功能来优化企业的业务决策流程。
规则语言主要包括两种:业务操作语言(BAL)和ILOG规则语言(IRL)。BAL是一种结构化的if-then语法,专为描述业务规则设计;而IRL则更接近于Java语法,用于定义技术规则。 在ILOG JRules中,规则执行模型分为两个...
它支持多种规则类型,如普通规则、决策表、决策树,以及使用Business Operation Language (BAL) 和ILOG Rule Language (IRL)定义的技术规则。BAL是一种简洁的if-then语法,用于构建业务规则,而IRL则更接近Java的...
- **许可使用**:根据ILOG的规定,用户只能在获得正式许可的情况下使用该产品及其文档。未获得许可擅自使用将构成侵权行为。 - **版权信息**:JRules 5.0及相关的文档都受ILOG版权保护,未经官方授权不得进行复制、...
IBM ILOG Help文档是该产品的重要组成部分,它为用户提供详尽的操作指南、API参考、示例代码以及故障排查信息,旨在帮助用户更好地理解和使用IBM ILOG的各种功能。 IBM ILOG的核心组件包括: 1. **ILOG CPLEX**:...
它提供了MXML和AS3两种编程语言,使得开发者能以声明式和面向对象的方式构建用户界面。ILOG Charts 3D充分利用了Flex的图形渲染能力和事件处理机制,提供了流畅的用户体验。 五、ILOG Elixir与Charts 3D的结合 ...
5. 集成能力:IBM ilog Elixir 可与多种开发环境无缝集成,如Java、.NET和Web应用服务器,便于将规则引擎融入现有的IT架构。 关于导入`.swc`文件进行开发,`.swc`是Adobe Flex的库包格式,包含类库和其他资源。在...
2. "ilog flex" 暗示可能使用了ILOG的Flex技术,Flex是一种用于构建富互联网应用程序(RIA)的Adobe框架,可能被IBM ILOG Elixir用来创建用户界面。 3. "ibm_ilog_flex" 强调了IBM ILOG与Flex的结合使用。 4. "ilog-...
总结来说,ilog jRules提供了一个强大的平台,让企业能够以声明式的方式管理业务规则,从而简化复杂决策过程。通过学习提供的"ilog jrules例子(规则)",我们可以深入理解规则引擎的工作原理,掌握如何构建和应用规则...
总结以上知识点,规则引擎Ilog Jrules是一种企业级业务规则管理系统,它通过提供丰富的工具组件和强大的规则定义能力,帮助开发者实现业务规则的模块化管理与快速变更。安装和使用Ilog Jrules时,需要关注安装顺序、...
IBM ilog的详细介绍 ILOG 业务规则管理系统在Java的应用与实践