本文整理匯總了Java中org.kie.api.KieServices類的典型用法代碼示例。如果您正苦於以下問題:Java KieServices類的具體用法?Java KieServices怎麽用?Java KieServices使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
KieServices類屬於org.kie.api包,在下文中一共展示了KieServices類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initKie
import org.kie.api.KieServices; //導入依賴的package包/類
private void initKie() {
KieServices ks = KieServices.Factory.get();
kfs = ks.newKieFileSystem();
uploadDroolFiles();
KieBuilder kbuilder = ks.newKieBuilder(kfs);
kbuilder.buildAll();
if (kbuilder.getResults().hasMessages(Level.ERROR)) {
throw new IllegalArgumentException(kbuilder.getResults().toString());
}
KieContainer kcontainer = ks.newKieContainer(kbuilder.getKieModule().getReleaseId());
KieBaseConfiguration kbConfig = KieServices.Factory.get().newKieBaseConfiguration();
kbConfig.setOption(ConstraintJittingThresholdOption.get(-1));
kbase = kcontainer.newKieBase(kbConfig);
}
示例2: createKJar
import org.kie.api.KieServices; //導入依賴的package包/類
public static byte[] createKJar(ReleaseId releaseId, List<String> drls) {
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId);
drls.forEach(drl -> kfs.write("src/main/resources/" + drl.hashCode() + ".drl", drl));
KieBuilder kb = kieServices.newKieBuilder(kfs).buildAll();
if (kb.getResults().hasMessages(Message.Level.ERROR)) {
for (Message result : kb.getResults().getMessages()) {
System.out.println(result.getText());
}
return null;
}
InternalKieModule kieModule = (InternalKieModule) kieServices.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
return jar;
}
示例3: testDeleteProcess
import org.kie.api.KieServices; //導入依賴的package包/類
@Test
public void testDeleteProcess() {
RuntimeManager manager = createRuntimeManager("approval.bpmn");
RuntimeEngine engine = getRuntimeEngine(null);
KieSession ksession = engine.getKieSession();
KieRuntimeLogger log = KieServices.Factory.get().getLoggers().newThreadedFileLogger(ksession, "test", 1000);
ksession.getWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler());
TaskService taskService = engine.getTaskService();
long processInstanceId = startProcess(ksession, taskService);
callDelete(taskService);
assertProcessInstanceCompleted(processInstanceId);
System.out.println("Process instance completed");
log.close();
manager.disposeRuntimeEngine(engine);
manager.close();
}
示例4: loadDrools
import org.kie.api.KieServices; //導入依賴的package包/類
private void loadDrools() {
try {
logger.info("Initializing Drools rule engine");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
addDrls(kbuilder);
KieSessionConfiguration config = KieServices.Factory.get().newKieSessionConfiguration();
config.setOption(ClockTypeOption.get("pseudo"));
logger.debug("Compiling rules");
kSession = kbuilder.newKieBase().newKieSession(config, null);
homeioSessionClock = new HomeioSessionClock(kSession.getSessionClock());
initGlobals();
droolsInitialized = true;
logger.debug("Successfully initialized Drools rule engine");
} catch (Exception e) {
logger.error("Exiting because of an exception during the Drools initialization ", e);
new RuntimeException("Exiting because of an exception during the Drools initialization");
}
}
示例5: loadContainerFromString
import org.kie.api.KieServices; //導入依賴的package包/類
private KieContainer loadContainerFromString(List<Rule> rules) {
long startTime = System.currentTimeMillis();
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();
for (Rule rule:rules) {
String drl=rule.getContent();
kfs.write("src/main/resources/" + drl.hashCode() + ".drl", drl);
}
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
if (kb.getResults().hasMessages(Message.Level.ERROR)) {
throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
}
long endTime = System.currentTimeMillis();
System.out.println("Time to build rules : " + (endTime - startTime) + " ms" );
startTime = System.currentTimeMillis();
KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
endTime = System.currentTimeMillis();
System.out.println("Time to load container: " + (endTime - startTime) + " ms" );
return kContainer;
}
示例6: createKieFileSystemWithKProject
import org.kie.api.KieServices; //導入依賴的package包/類
/**
* 創建默認的kbase和stateful的kiesession
*
* @param ks
* @param isdefault
* @return
*/
public static KieFileSystem createKieFileSystemWithKProject(KieServices ks, boolean isdefault) {
KieModuleModel kproj = ks.newKieModuleModel();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("KBase").setDefault(isdefault)
.setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM);
// Configure the KieSession.
kieBaseModel1.newKieSessionModel("KSession").setDefault(isdefault)
.setType(KieSessionModel.KieSessionType.STATEFUL);
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML());
return kfs;
}
示例7: helloDroolsTest
import org.kie.api.KieServices; //導入依賴的package包/類
@Test
public void helloDroolsTest() {
System.out.println( "Bootstrapping the Rule Engine ..." );
// Bootstrapping a Rule Engine Session
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.newKieClasspathContainer();
KieBase kBase = kContainer.getKieBase( "confKBase" );
KieSession kSession = kBase.newKieSession();
ArrayList<String> errors = new ArrayList<String>();
kSession.setGlobal( "errors", errors );
House house = new House( "Maniac Mansion" );
kSession.insert( house );
int fired = kSession.fireAllRules();
assertEquals( 1, fired );
assertEquals( 1, errors.size() );
assertThat( errors, Matchers.contains( "Warn: Your House ( " + house.getName() + " ) has no Rooms" ) );
kSession.dispose();
}
示例8: buildRelease
import org.kie.api.KieServices; //導入依賴的package包/類
private static void buildRelease(ReleaseId releaseId, Resource pomResource, Resource kmodule, String... resources) {
if (releases.contains(releaseId)) {
ks.getRepository().removeKieModule(releaseId);
}
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();
kfs.write("pom.xml", pomResource);
kfs.write("src/main/resources/META-INF/kmodule.xml", kmodule);
for (String res : resources) {
Resource resource = new ClassPathResource(res);
kfs.write("src/main/resources/" + res, resource);
}
hasErrors(kieServices.newKieBuilder(kfs).buildAll().getResults());
releases.add(releaseId);
}
示例9: processRules
import org.kie.api.KieServices; //導入依賴的package包/類
public Measure processRules(@Body Measure measure) {
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(
kieHost, kieUser,
kiePassword);
Set<Class<?>> jaxBClasses = new HashSet<Class<?>>();
jaxBClasses.add(Measure.class);
config.addJaxbClasses(jaxBClasses);
config.setMarshallingFormat(MarshallingFormat.JAXB);
RuleServicesClient client = KieServicesFactory.newKieServicesClient(config)
.getServicesClient(RuleServicesClient.class);
List<Command<?>> cmds = new ArrayList<Command<?>>();
KieCommands commands = KieServices.Factory.get().getCommands();
cmds.add(commands.newInsert(measure));
GetObjectsCommand getObjectsCommand = new GetObjectsCommand();
getObjectsCommand.setOutIdentifier("objects");
cmds.add(commands.newFireAllRules());
cmds.add(getObjectsCommand);
BatchExecutionCommand myCommands = CommandFactory.newBatchExecution(cmds,
"DecisionTableKS");
ServiceResponse<ExecutionResults> response = client.executeCommandsWithResults("iot-ocp-businessrules-service", myCommands);
List responseList = (List) response.getResult().getValue("objects");
Measure responseMeasure = (Measure) responseList.get(0);
return responseMeasure;
}
示例10: setup
import org.kie.api.KieServices; //導入依賴的package包/類
@Before
public void setup() {
KieServices kieServices = KieServices.Factory.get();
KieContainer kContainer = kieServices.getKieClasspathContainer();
Results verifyResults = kContainer.verify();
for (Message m : verifyResults.getMessages()) {
LOG.debug("Kie container message: {}", m);
}
KieBase kieBase = kContainer.getKieBase();
LOG.debug("Created kieBase");
for ( KiePackage kp : kieBase.getKiePackages() ) {
for (Rule rule : kp.getRules()) {
LOG.debug("kp " + kp + " rule " + rule.getName());
}
}
session = kieBase.newKieSession();
LOG.info(session.getGlobals().toString());
Logger kieLogger = LoggerFactory.getLogger(this.getClass());
// session.setGlobal("logger",kieLogger);
}
示例11: buildSession
import org.kie.api.KieServices; //導入依賴的package包/類
/**
* Load all .drl files
*
* if a rule does not compile an exception will be thrown indicating the problem
*
* @param path
* @return - session containing all loaded rules
* @throws Exception
*/
public KieSession buildSession() throws Exception {
kieServices = KieServices.Factory.get();
KieRepository kr = kieServices.getRepository();
kfs = kieServices.newKieFileSystem();
if(rules != null){
loadFromList();
}
else{
loadFromFiles();
}
kieBuilder = kieServices.newKieBuilder( kfs ).buildAll();
Results results = kieBuilder.getResults();
if( results.hasMessages( Message.Level.ERROR ) ){
System.out.println( results.getMessages() );
throw new IllegalStateException( results.getMessages() + "" );
}
kieContainer =
kieServices.newKieContainer( kr.getDefaultReleaseId() );
ksession = kieContainer.newKieSession();
ksession.addEventListener(new RuleTracker());
return ksession;
}
示例12: DroolsRulesEngineImpl
import org.kie.api.KieServices; //導入依賴的package包/類
public DroolsRulesEngineImpl() {
log.debug("Creating instance.");
ks = KieServices.Factory.get();
kc = ks.getKieClasspathContainer();
kSession = kc.newKieSession(SESSION_NAME);
if (log.isTraceEnabled()) {
kSession.addEventListener(new DebugAgendaEventListener());
kSession.addEventListener(new DebugRuleRuntimeEventListener());
}
minReportingIntervalData = new Integer(
HawkularProperties.getProperty(MIN_REPORTING_INTERVAL_DATA,
MIN_REPORTING_INTERVAL_DATA_ENV,
MIN_REPORTING_INTERVAL_DATA_DEFAULT));
minReportingIntervalEvents = new Integer(
HawkularProperties.getProperty(MIN_REPORTING_INTERVAL_EVENTS,
MIN_REPORTING_INTERVAL_EVENTS_ENV,
MIN_REPORTING_INTERVAL_EVENTS_DEFAULT));
}
示例13: doTest
import org.kie.api.KieServices; //導入依賴的package包/類
@Test
public void doTest() throws InterruptedException {
new UrlResource();
KieServices kieServices = KieServices.Factory.get();
ReleaseIdImpl releaseId = new ReleaseIdImpl(G, A, V);
KieContainer kContainer = KieServices.Factory.get().newKieContainer(
releaseId);
KieScanner kScanner = kieServices.newKieScanner(kContainer);
KieSession kSession = kContainer.newKieSession();
kScanner.start(3000);
// KieScanner will continue scanning the server looking for artifact
// update
while (true) {
Thread.sleep(3000);
kSession.fireAllRules();
}
}
示例14: doTest
import org.kie.api.KieServices; //導入依賴的package包/類
@Test
public void doTest() {
logger.info("Running test using persistence");
// start our mock DB
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
// setting persistence
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("org.jbpm.persistence.jpa");
Environment env = KnowledgeBaseFactory.newEnvironment();
// to load our kbase
KieContainer kc = KieServices.Factory.get().getKieClasspathContainer();
KieBase kb = kc.getKieBase("TestProcessKB");
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
StatefulKnowledgeSession kSession = JPAKnowledgeService
.newStatefulKnowledgeSession(kb, null, env);
kSession.startProcess("HelloWorldProcess");
}
示例15: doTest
import org.kie.api.KieServices; //導入依賴的package包/類
@Test
public void doTest() throws IOException {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
UrlResource urlResource = (UrlResource) ks.getResources().newUrlResource(URL);
urlResource.setUsername(USER);
urlResource.setPassword(PASSWORD);
urlResource.setBasicAuthentication("enabled");
InputStream is = urlResource.getInputStream();
KieModule kModule = kr.addKieModule(ks.getResources().newInputStreamResource(is));
KieContainer kc = ks.newKieContainer(kModule.getReleaseId());
// This fact was created using Data Modeller in business central
// Product p = new Product();
// p.setName("Table");
// p.setPrice(500f);
KieSession kSession = kc.newKieSession();
// kSession.insert(p);
kSession.fireAllRules();
}