本文整理汇总了Java中org.drools.runtime.StatefulKnowledgeSession.setGlobal方法的典型用法代码示例。如果您正苦于以下问题:Java StatefulKnowledgeSession.setGlobal方法的具体用法?Java StatefulKnowledgeSession.setGlobal怎么用?Java StatefulKnowledgeSession.setGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.drools.runtime.StatefulKnowledgeSession
的用法示例。
在下文中一共展示了StatefulKnowledgeSession.setGlobal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exec
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
@Override
public void exec(FrameTask ctx) {
StatefulKnowledgeSession kbsess = kb.newStatefulKnowledgeSession();
try {
// this knowledge session will be the session for all Drools rules
kbsess.insert(ctx.getTriggerEvent());
kbsess.setGlobal("DAO", ctx.getResource(IGenericPatientObjectDAO.class));
kbsess.fireAllRules();
// Harvest all the actions out of working memory
ObjectFilter frameActionFilter = new ObjectFilter() {
@Override
public boolean accept(Object object) {
return object instanceof FrameAction;
}
};
Collection<FactHandle> actions = kbsess.getFactHandles(frameActionFilter);
for (FactHandle handle : actions) {
FrameAction action = (FrameAction) kbsess.getObject(handle);
ctx.addAction(action);
}
} finally {
// clear working memory for next transaction
kbsess.dispose();
}
}
示例2: addGlobals
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
* Method to add globals.
*
* @param ksession Drools Knowledge session.
*/
private void addGlobals(StatefulKnowledgeSession ksession) {
ksession.setGlobal("cList", new ArrayList<Integer>());
ksession.setGlobal("dList", new ArrayList<String>());
ksession.setGlobal("vList", new ArrayList<String>());
ksession.setGlobal("fList", new ArrayList<String>());
ArrayList<String> definedList = (ArrayList<String>) droolsVisitor.getdList();
java.util.Set<String> tempSet = new HashSet<String>();
tempSet.addAll(definedList);
definedList.removeAll(definedList);
definedList.addAll(tempSet);
@SuppressWarnings("unchecked")
List<String> defL = (ArrayList<String>) ksession.getGlobal("dList");
for (int i = 0; i < definedList.size(); i++) {
defL.add(definedList.get(i));
}
Map<String, Integer> enumMap = new HashMap<String, Integer>();
enumMap = droolsVisitor.getEnumMap();
Iterator<String> itr = enumMap.keySet().iterator();
while (itr.hasNext()) {
String k = itr.next();
ksession.setGlobal(k, enumMap.get(k));
}
}
示例3: executeViewRule
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
@Override
public boolean executeViewRule(ServiceContext context, Long ruleId, BaseObject<?> baseObject) {
EntityRuleDO rule = entityRuleDAO.getById(ruleId);
if (rule != null) {
KnowledgeBase knowlegeBase = getKnowlegeBase(Lists.newArrayList(rule));
StatefulKnowledgeSession session = knowlegeBase.newStatefulKnowledgeSession();
for (Permission permission : userService.findAvailablePermissions(context)) {
session.insert(permission);
}
List<ValidationError> errorList = Lists.newArrayList();
session.setGlobal("errorList", errorList);
session.insert(baseObject);
session.fireAllRules();
session.dispose();
return errorList.isEmpty();
}
return true;
}
示例4: performCrossFieldValidation
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
public List<ValidationError> performCrossFieldValidation(ServiceContext context,
final Map<String, String> extAttributes, Long scopeId, EntityTypeCode entityType) {
List<ValidationError> errorList = new ArrayList<>();
if (extAttributes != null) {
StatefulKnowledgeSession ksession = ruleService.getRuleSessionForScopePath(context, scopeId, entityType);
if (ksession != null) {
ksession.setGlobal("errorList", errorList);
ksession.insert(extAttributes);
ksession.fireAllRules();
ksession.dispose();
}
}
return errorList;
}
示例5: createTicketFromAlarm
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
* Called from API implemented method after successful retrieval of Alarm.
*
* @param alarm OpenNMS Model class alarm
* @return OpenNMS Ticket processed by Drools logic.
*/
protected Ticket createTicketFromAlarm(OnmsAlarm alarm) {
log().debug("createTicketFromAlarm: Processing ticket.");
// Call superclass method if the knowledge-base was not properly created.
if( m_knowledgeBase == null ) {
log().error("KnowledgeBase is NULL, creating basic ticket form alarm.");
return super.createTicketFromAlarm(alarm);
}
Ticket ticket = new Ticket();
StatefulKnowledgeSession session = m_knowledgeBase.newStatefulKnowledgeSession();
try {
// Pass the ticket as a global - the logic will fill the appropriate fields
session.setGlobal("ticket", ticket);
// Pass the alarm and the node objects
session.insert(alarm);
session.insert(alarm.getNode());
session.fireAllRules();
} finally {
session.dispose();
}
log().debug("createTicketFromAlarm: Succesfully processed ticket.");
return ticket;
}
示例6: waltz
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
@WebMethod
public String waltz(@WebParam(name="WaltzDTO")WaltzDTO dto) {
StatefulKnowledgeSession session = waltzKb.getKbase().newStatefulKnowledgeSession();
for (Line l : dto.getLine()) {
session.insert(l);
}
session.insert(dto.getStage());
long start = System.currentTimeMillis();
session.setGlobal( "time", start );
session.fireAllRules();
long time = System.currentTimeMillis() - start;
System.err.println( time );
session.dispose();
return "time: "+time;
}
示例7: createStatefulKnowledgeSession
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
* Creates the stateful knowledge session.
*
* @return the stateful knowledge session
*/
StatefulKnowledgeSession createStatefulKnowledgeSession() {
StatefulKnowledgeSession session = null;
try {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
final String casRules = guvnorService
.getVersionedRulesFromPackage();
kbuilder.add(
ResourceFactory.newByteArrayResource(casRules.getBytes()),
ResourceType.DRL);
final KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (final KnowledgeBuilderError error : errors) {
logger.error(error.toString());
}
}
final KnowledgeBase knowledgeBase = KnowledgeBaseFactory
.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
session = knowledgeBase.newStatefulKnowledgeSession();
session.setGlobal("ruleExecutionContainer",
new RuleExecutionContainer());
} catch (final Exception e) {
logger.error(e.toString(), e);
}
return session;
}
示例8: addDroolsGlobals
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
* Method to add drools globals.
* @param ksession Drools KNowledge session.
* @return Returns the packagename of the .drl (drools rule) file.
*/
private String addDroolsGlobals(StatefulKnowledgeSession ksession) {
this.pckg = DroolsEngine.class.getPackage().getName();
/**
* cList contains the rule ids of the rules that are not satisfied.
*/
ksession.setGlobal("cList", new ArrayList<Integer>());
ksession.setGlobal("aList", new ArrayList<String>());
ksession.setGlobal("dList", new ArrayList<Object>());
ksession.setGlobal("vList", new ArrayList<String>());
/*
* flist is the list containing names of the variables with fixed status.
*/
ksession.setGlobal("fList", new ArrayList<String>());
ArrayList<String> definedList = (ArrayList<String>) droolsVisitor.getdList();
java.util.Set<String> tempSet = new HashSet<String>();
tempSet.addAll(definedList);
definedList.removeAll(definedList);
definedList.addAll(tempSet);
@SuppressWarnings("unchecked")
List<String> defL = (ArrayList<String>) ksession.getGlobal("dList");
for (int i = 0; i < definedList.size(); i++) {
defL.add(definedList.get(i));
}
addEnums(ksession);
return this.pckg;
}
示例9: addEnums
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
* Private method to load enumerations as global values in the drools rule file.
* @param ksession Drools Knowledge Session.
*/
private void addEnums(StatefulKnowledgeSession ksession) {
Map<String, Integer> enumMap = new HashMap<String, Integer>();
enumMap = droolsVisitor.getEnumMap();
Iterator<String> itr = enumMap.keySet().iterator();
while (itr.hasNext()) {
String k = itr.next();
ksession.setGlobal(k, enumMap.get(k));
}
}
示例10: createStatefulKnowledgeSession
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
* Creates the stateful knowledge session.
*
* @return the stateful knowledge session
*/
private StatefulKnowledgeSession createStatefulKnowledgeSession() {
StatefulKnowledgeSession session = null;
try {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
String casRules = guvnorService.getVersionedRulesFromPackage();
kbuilder.add(
ResourceFactory.newByteArrayResource(casRules.getBytes()),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
LOGGER.error(error.toString());
}
}
KnowledgeBase knowledgeBase = KnowledgeBaseFactory
.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
session = knowledgeBase.newStatefulKnowledgeSession();
session.setGlobal("ruleExecutionContainer",
new RuleExecutionContainer());
} catch (Exception e) {
LOGGER.error(e.toString(), e);
}
return session;
}
示例11: executeEntityRule
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
* Execute a given entity rule
*
* @throws ValidationServiceException
* if the rule does not pass validations
*/
@Override
public void executeEntityRule(ServiceContext context, Long entityRuleId, Map<String, String> entity)
throws ValidationServiceException {
EntityRuleDO entityRule = entityRuleDAO.getById(entityRuleId);
List<EntityRuleDO> asList = Arrays.asList(entityRule);
StatefulKnowledgeSession ruleSession = getRuleSessionForEntityRules(context, asList);
List<ValidationError> errorList = Lists.newArrayList();
ruleSession.setGlobal("errorList", errorList);
ruleSession.insert(entity);
ruleSession.fireAllRules();
ruleSession.dispose();
}
示例12: evaluate
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
private FactHandle evaluate(StatefulKnowledgeSession ksession, FactHandle handle, Object obj) {
if (handle == null) {
ksession.setGlobal("delegator", new RuleTasksDelegator());
handle = ksession.insert(obj);
} else {
ksession.update(handle, obj);
}
ksession.fireAllRules();
if (log.isDebugEnabled()) {
log.debug(String.format("Rule executed for: %s ", obj));
}
return handle;
}
示例13: main
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
KnowledgeBuilderConfiguration conf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(conf);
kBuilder.add(ResourceFactory.newClassPathResource("ru/joker/drools/drl/logic/Smart.drl"), ResourceType.DRL);
kBuilder.add(ResourceFactory.newClassPathResource("ru/joker/drools/drl/billing/Accounting.drl"), ResourceType.DRL);
kBuilder.add(ResourceFactory.newClassPathResource("ru/joker/drools/drl/logic/General.drl"), ResourceType.DRL);
KnowledgeBase kBase = kBuilder.newKnowledgeBase();
StatefulKnowledgeSession session = kBase.newStatefulKnowledgeSession();
try {
session.setGlobal("log", LOG);
for (Customer customer : DAO.findCustomers()) {
session.insert(customer);
}
for (Sms sms : DAO.findSmses()) {
session.insert(sms);
}
DateTime startOfMonth = new DateTime().withDayOfMonth(1).withMillisOfDay(0);
session.insert(new Interval(startOfMonth, startOfMonth.plusMonths(1)));
session.fireAllRules();
Collection<Object> invoices = session.getObjects(new ClassObjectFilter(Invoice.class));
LOG.info("Invoices: {}", new ArrayList<Object>(invoices));
} finally {
session.dispose();
}
}
示例14: getStatefulSession
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
public StatefulKnowledgeSession getStatefulSession(String drlFileName) {
StatefulKnowledgeSession ksession;
ksession = knowledgeBases.get(drlFileName).newStatefulKnowledgeSession();
ksession.setGlobal("log", RuleLog.getInstance());
return ksession;
}
示例15: execute
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
public void execute() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
/*
* The KnowlegeBase is a repository of all the application's knowledge
* definitions. It will contain rules, processes, functions, and type
* models but NOT DATA. Creating the KnowlegeBase can be heavy, whereas
* session creation is very light, so it is recommended that Knowledge
* Bases be cached where possible to allow for repeated session
* creation.
*/
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbuilder.add(ResourceFactory.newClassPathResource("firealarm.drl",
getClass()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
LOGGER.error(kbuilder.getErrors().toString());
}
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
/*
* StatefulKnowledgeSession will maintain the reference to the objects
* that were added in the current session
*/
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
// Advanced debugging options
/*
* ksession.addEventListener(new DefaultWorkingMemoryEventListener());
* ksession.addEventListener(new DebugAgendaEventListener());
*/
ksession.setGlobal("LOGGER", Logger.getLogger("fireAlarmDRL"));
String[] names = new String[] { "kitchen", "bedroom", "office",
"livingroom" };
Map<String, Room> name2room = new HashMap<String, Room>();
for (String name : names) {
Room room = new Room(name);
name2room.put(name, room);
}
LOGGER.debug("----------------------------------");
LOGGER.debug("Before calling fireAllOk()");
this.fireAllOk(ksession, name2room);
LOGGER.debug("----------------------------------");
LOGGER.debug("Before calling startAndStopSprinkler()");
this.startAndStopSprinkler(ksession, name2room);
LOGGER.debug("----------------------------------");
ksession.dispose();
}