本文整理匯總了Java中org.kie.api.KieServices.newKieContainer方法的典型用法代碼示例。如果您正苦於以下問題:Java KieServices.newKieContainer方法的具體用法?Java KieServices.newKieContainer怎麽用?Java KieServices.newKieContainer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.kie.api.KieServices
的用法示例。
在下文中一共展示了KieServices.newKieContainer方法的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: 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;
}
示例3: 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();
}
示例4: createKieContainer
import org.kie.api.KieServices; //導入方法依賴的package包/類
private KieContainer createKieContainer(String... ruleFiles) {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
for (String ruleFile : ruleFiles) {
InputStream ruleFileIs = DroolsTestSupport.class.getResourceAsStream("/" + ruleFile);
Assert.assertNotNull("Can't open stream for rule file. Does it exist?", ruleFileIs);
kfs.write(ks.getResources().newInputStreamResource(ruleFileIs).setSourcePath(ruleFile));
try {
ruleFileIs.close();
} catch (IOException e) {
throw new RuntimeException("InputStream of rule file could not be closed.");
}
}
kieBuilder.buildAll();
StringBuilder message = new StringBuilder();
List<Message> messages = kieBuilder.getResults().getMessages();
for (Message m : messages) {
message.append(m.toString()).append("\n");
}
Assert.assertEquals(message.toString(), 0, messages.size());
return ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
}
示例5: init
import org.kie.api.KieServices; //導入方法依賴的package包/類
public void init () {
LOG.info("[init]preparing stateful session...");
KieServices ks = KieServices.Factory.get();
String path = "";
try {
//OSGi support
BundleContext bc = Activator.getBundleContext();
if ( bc != null ) {
Preconditions.checkNotNull(bc, "bundle not activated");
URL url = bc.getBundle().getEntry(settingPath);
path = FileLocator.toFileURL(url).getPath();
} else {
path = settingPath;
}
} catch (Exception e) {
LOG.error("Failed to locate file:");
LOG.error(Throwables.getStackTraceAsString(e));
}
System.setProperty("kie.maven.settings.custom", path);
ReleaseId releaseId = ks.newReleaseId(groupId, artifactId, version);
LOG.info(String.format("[init]initializing kie container with releaseId %s", releaseId));
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieScanner kieScanner = ks.newKieScanner(kieContainer);
kieScanner.scanNow();
ksession = kieContainer.newKieSession(session);
ksession.setGlobal("LOG", LOG);
LOG.info("[init]stateful rule engine prepared");
}
示例6: init
import org.kie.api.KieServices; //導入方法依賴的package包/類
public void init () {
LOG.info("[init]preparing stateless session...");
KieServices ks = KieServices.Factory.get();
String path = "";
try {
//OSGi support
BundleContext bc = Activator.getBundleContext();
if ( bc != null ) {
Preconditions.checkNotNull(bc, "bundle not activated");
URL url = bc.getBundle().getEntry(settingPath);
path = FileLocator.toFileURL(url).getPath();
} else {
path = settingPath;
}
} catch (Exception e) {
LOG.error("Failed to locate file:");
LOG.error(Throwables.getStackTraceAsString(e));
}
System.setProperty("kie.maven.settings.custom", path);
ReleaseId releaseId = ks.newReleaseId(groupId, artifactId, version);
LOG.info(String.format("[init]initializing kie container with releaseId %s", releaseId));
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieScanner kieScanner = ks.newKieScanner(kieContainer);
kieScanner.scanNow();
ksession = kieContainer.newStatelessKieSession(session);
ksession.setGlobal("LOG", LOG);
LOG.info("[init]stateless rule engine prepared");
}
示例7: DecisionTableKieBaseProvider
import org.kie.api.KieServices; //導入方法依賴的package包/類
public DecisionTableKieBaseProvider() {
KieServices kieServices = KieServices.Factory.get();
KieRepository kieRepository = kieServices.getRepository();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
//addResource(kieFileSystem, "com.redhatbank.brms.tracktrace.model.SLACriteria.gdst");
addResource(kieFileSystem, "org.acme.insurance.TestDS.xls");
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
for (Message message : kieBuilder.getResults().getMessages()) {
System.out.println(message);
}
kieContainer = kieServices.newKieContainer(kieRepository.getDefaultReleaseId());
}
示例8: getKieBase
import org.kie.api.KieServices; //導入方法依賴的package包/類
private KieBase getKieBase(String url, String usr, String password) 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());
return kc.getKieBase();
}
示例9: 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());
KieSession kSession = kc.newKieSession();
kSession.startProcess("project1.hello");
}
示例10: initKieSession
import org.kie.api.KieServices; //導入方法依賴的package包/類
private void initKieSession(String... resourceNames) {
final KieServices kieServices = KieServices.Factory.get();
final KieModuleModel kieModuleModel = kieServices.newKieModuleModel();
final KieBaseModel kieBaseModel = kieModuleModel.newKieBaseModel("defaultKieBase")
.setDefault(true)
.setEqualsBehavior(EqualityBehaviorOption.EQUALITY)
.setEventProcessingMode(EventProcessingOption.STREAM);
kieBaseModel.newKieSessionModel("defaultKieSession")
.setDefault(true)
.setType(KieSessionModel.KieSessionType.STATEFUL)
.setClockType(ClockTypeOption.get("pseudo"))
.newWorkItemHandlerModel("Rest", "org.drools.workbench.screens.testscenario.backend.server.GithubContributorsWIH");
final KieFileSystem kfs = kieServices.newKieFileSystem();
kfs.writeKModuleXML(kieModuleModel.toXML());
for (String resource : resourceNames) {
kfs.write(ResourceFactory.newUrlResource(this.getClass()
.getResource(resource)
.toString()));
}
kieServices.newKieBuilder(kfs).buildAll();
kieContainer = kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId());
kieSession = kieContainer.newKieSession();
doReturn(kieSession).when(sessionService).newDefaultKieSessionWithPseudoClock(any(KieModule.class));
}
示例11: getKieContainer
import org.kie.api.KieServices; //導入方法依賴的package包/類
/**
* Creating a KieBase from the workflow GAV specified in the config.
*
* @return KieBase for package SRAMPPackage
*
* @throws SrampClientException
* @throws SrampAtomException
*/
public KieContainer getKieContainer(ReleaseId releaseId) throws SrampClientException, SrampAtomException {
KieServices ks = KieServices.Factory.get();
KieRepository repo = ks.getRepository();
SrampAtomApiClient client = SrampAtomApiClientFactory.createAtomApiClient();
Governance governance = new Governance();
String workflowGroupId = releaseId.getGroupId();
String workflowArtifactId = releaseId.getArtifactId();
String workflowVersion = releaseId.getVersion();
if (StringUtils.isBlank(workflowVersion)) {
throw new RuntimeException(Messages.i18n.format("maven.version.not.found", workflowGroupId, workflowArtifactId, workflowVersion)); //$NON-NLS-1$
}
QueryResultSet results = null;
ArtifactSummary artifactSummary = null;
results = client.buildQuery(SRAMP_KIE_JAR_QUERY).parameter(workflowGroupId).parameter(workflowArtifactId).parameter(workflowVersion).count(1)
.query();
if (results.size() > 0) {
artifactSummary = results.get(0);
InputStream is = client.getArtifactContent(artifactSummary);
KieModule kModule = repo.addKieModule(ks.getResources().newInputStreamResource(is));
logger.info(Messages.i18n.format("KieSrampUtil.CreatingKieContainer", artifactSummary.getName())); //$NON-NLS-1$
KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());
//Creating the KieBase for the SRAMPPackage
logger.info(Messages.i18n.format("KieSrampUtil.FindKieBase", governance.getGovernanceWorkflowPackage())); //$NON-NLS-1$
return kContainer;
} else {
return null;
}
}
示例12: loadKieContainer
import org.kie.api.KieServices; //導入方法依賴的package包/類
private static KieContainer loadKieContainer(ReleaseId releaseId) {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieContainer kieContainer = ks.newKieContainer(releaseId);
return kieContainer;
}
示例13: BRMSUtil
import org.kie.api.KieServices; //導入方法依賴的package包/類
public BRMSUtil() {
KieServices kServices = KieServices.Factory.get();
ReleaseId releaseId = kServices.newReleaseId( "com.redhat.poc.banking", "SLAMgmtRules", "LATEST" );
kContainer = kServices.newKieContainer( releaseId );
/*KieScanner kScanner = kServices.newKieScanner( kContainer );
// Start the KieScanner polling the maven repository every 10 seconds
System.out.println("Starting KieScanner...");
System.out.println();
kScanner.start( 10000L );
System.out.println("Started KieScanner sucessfully...");
System.out.println();*/
}
示例14: main
import org.kie.api.KieServices; //導入方法依賴的package包/類
public static void main(String[] args) {
BRMSUtil bUtil = new BRMSUtil();
/*KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption( ClockTypeOption.get( "pseudo" ) );
*/
KieServices kServices = KieServices.Factory.get();
ReleaseId releaseId = kServices.newReleaseId( "com.redhat.poc.banking", "SLAMgmtRules", "LATEST" );
KieContainer kContainer = kServices.newKieContainer( releaseId );
//KieSession kSession = kContainer.newKieSession(conf);
KieSession kSession = kContainer.newKieSession();
BatchJobInfo info = new BatchJobInfo();
info.setTotalTransactions(100);
info.setNoOfTransProcessed(0);
info.setTransactionType("TX1");
info.setPctTransComplete(0.0);
kSession.insert(info);
BatchJobUpdate update1 = new BatchJobUpdate();
update1.setTransactionType("TX1");
update1.setNoOfTransProcessed(50);
kSession.insert(update1);
kSession.fireAllRules();
//kSession.fireUntilHalt();
System.out.println(info.getTransactionType());
System.out.println(info.getNoOfTransProcessed());
System.out.println(info.getPctTransComplete());
/* try {
Thread.sleep(25000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
kSession.fireAllRules();*/
kSession.fireUntilHalt();
/*
PseudoClockScheduler timeService = ( PseudoClockScheduler ) kSession.<SessionClock>getSessionClock();
timeService.advanceTime( new Date().getTime(), TimeUnit.MILLISECONDS );
*/
/*
timeService.advanceTime( 30, TimeUnit.SECONDS );
kSession.fireAllRules();*/
kSession.dispose();
}
示例15: getKieFromFile
import org.kie.api.KieServices; //導入方法依賴的package包/類
@Test @Ignore
public void getKieFromFile() {
KieServices ks = KieServices.Factory.get();
KieRepository repo = ks.getRepository();
InputStream is = this.getClass().getResourceAsStream("/dtgov-workflows.jar"); //$NON-NLS-1$
KieModule kModule = repo.addKieModule(ks.getResources().newInputStreamResource(is));
@SuppressWarnings("unused")
ReleaseId releaseId = kModule.getReleaseId();
KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());
Assert.assertNotNull(kContainer);
KieBase kieBase = kContainer.getKieBase("SRAMPPackage"); //$NON-NLS-1$
Assert.assertNotNull(kieBase);
System.out.println("KieBase=" + kieBase); //$NON-NLS-1$
}