Author: tsurdilovic
Date: 2010-01-12 16:53:08 -0500 (Tue, 12 Jan 2010)
New Revision: 11946
Modified:
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManagerConfig.java
Log:
Drools 5 Integration.
Modified:
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java
===================================================================
---
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java 2010-01-12
01:12:46 UTC (rev 11945)
+++
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java 2010-01-12
21:53:08 UTC (rev 11946)
@@ -7,18 +7,24 @@
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;
import javax.inject.Named;
+import javax.security.auth.login.Configuration;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
+import org.drools.event.process.ProcessEventListener;
+import org.drools.event.rule.AgendaEventListener;
+import org.drools.event.rule.WorkingMemoryEventListener;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.StatelessKnowledgeSession;
+import org.drools.runtime.process.WorkItemHandler;
import org.jboss.seam.drools.events.KnowledgeSessionCreatedEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,8 +58,8 @@
public StatefulKnowledgeSession getStatefulSession(InjectionPoint injectionPoint)
throws Exception
{
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession(getKSessionConfig(), null);
- //addEventListeners(ksession);
- //addWorkItemHandlers(ksession);
+ addEventListeners(ksession);
+ addWorkItemHandlers(ksession);
addAuditLog(ksession);
manager.fireEvent(new KnowledgeSessionCreatedEvent(ksession.getId()));
return ksession;
@@ -73,7 +79,7 @@
public StatelessKnowledgeSession getStatelessSession(InjectionPoint injectionPoint)
throws Exception
{
StatelessKnowledgeSession ksession =
kbase.newStatelessKnowledgeSession(getKSessionConfig());
- //addEventListeners(ksession);
+ addEventListeners(ksession);
manager.fireEvent(new KnowledgeSessionCreatedEvent(-1));
return ksession;
}
@@ -103,7 +109,7 @@
}
- private void addAuditLog(StatefulKnowledgeSession ksession) {
+ private void addAuditLog(StatefulKnowledgeSession ksession) throws Exception {
if(ksessionManagerConfig.getAuditLog() != null) {
if(KnowledgeSessionManagerConfig.isFileLogger(ksessionManagerConfig.getAuditLog())) {
String logName =
KnowledgeSessionManagerConfig.getFileLoggerPath(ksessionManagerConfig.getAuditLog()) +
System.currentTimeMillis();
@@ -122,5 +128,58 @@
}
}
}
+
+ public void addEventListeners(StatefulKnowledgeSession ksession) throws Exception {
+ if(ksessionManagerConfig.getEventListeners() != null) {
+ for(String eventListener : ksessionManagerConfig.getEventListeners()) {
+ Class eventListenerClass = Class.forName(eventListener);
+ Object eventListenerObject = eventListenerClass.newInstance();
+
+ if(eventListenerObject instanceof WorkingMemoryEventListener) {
+ ksession.addEventListener((WorkingMemoryEventListener)
eventListenerObject);
+ } else if(eventListenerObject instanceof AgendaEventListener) {
+ ksession.addEventListener((AgendaEventListener) eventListenerObject);
+ } else if(eventListenerObject instanceof ProcessEventListener) {
+ ksession.addEventListener((ProcessEventListener) eventListenerObject);
+ } else {
+ log.debug("Invalid Event Listener: " + eventListener);
+ }
+ }
+ }
+ }
+
+ public void addEventListeners(StatelessKnowledgeSession ksession) throws Exception{
+ if(ksessionManagerConfig.getEventListeners() != null) {
+ for(String eventListener : ksessionManagerConfig.getEventListeners()) {
+ Class eventListenerClass = Class.forName(eventListener);
+ Object eventListenerObject = eventListenerClass.newInstance();
+
+ if(eventListenerObject instanceof WorkingMemoryEventListener) {
+ ksession.addEventListener((WorkingMemoryEventListener)
eventListenerObject);
+ } else if(eventListenerObject instanceof AgendaEventListener) {
+ ksession.addEventListener((AgendaEventListener) eventListenerObject);
+ } else if(eventListenerObject instanceof ProcessEventListener) {
+ ksession.addEventListener((ProcessEventListener) eventListenerObject);
+ } else {
+ log.debug("Invalid Event Listener: " + eventListener);
+ }
+ }
+ }
+ }
+
+ public void addWorkItemHandlers(StatefulKnowledgeSession ksession) {
+ if(ksessionManagerConfig.getWorkItemHandlers() != null) {
+ for(String workItemHandlerStr : ksessionManagerConfig.getWorkItemHandlers()) {
+ if(KnowledgeSessionManagerConfig.isValidWorkItemHandler(workItemHandlerStr))
{
+ @SuppressWarnings("unchecked")
+ Bean<WorkItemHandler> workItemHandlerBean =
(Bean<WorkItemHandler>)
manager.getBeans(KnowledgeSessionManagerConfig.getWorkItemHandlerType(workItemHandlerStr)).iterator().next();
+ WorkItemHandler handler = (WorkItemHandler)
manager.getReference(workItemHandlerBean, Configuration.class,
manager.createCreationalContext(workItemHandlerBean));
+ log.debug("Registering new WorkItemHandler: " +
KnowledgeSessionManagerConfig.getWorkItemHandlerName(workItemHandlerStr));
+
ksession.getWorkItemManager().registerWorkItemHandler(KnowledgeSessionManagerConfig.getWorkItemHandlerName(workItemHandlerStr),
handler);
+ }
+ }
+ }
+ }
+
}
Modified:
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManagerConfig.java
===================================================================
---
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManagerConfig.java 2010-01-12
01:12:46 UTC (rev 11945)
+++
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManagerConfig.java 2010-01-12
21:53:08 UTC (rev 11946)
@@ -26,6 +26,18 @@
private Properties knowledgeSessionConfigProp;
private String auditLog;
+ public static String getWorkItemHandlerName(String workItemHandlerStr) {
+ return DIVIDER.split(workItemHandlerStr.trim())[WORKITEMHANDLER_NAME];
+ }
+
+ public static String getWorkItemHandlerType(String workItemHandlerStr) {
+ return DIVIDER.split(workItemHandlerStr.trim())[WORKITEMHANDLER_TYPE];
+ }
+
+ public static boolean isValidWorkItemHandler(String workItemHandlerStr) {
+ return DIVIDER.split(workItemHandlerStr.trim()).length == 2;
+ }
+
public static boolean isFileLogger(String auditLog) {
return DIVIDER.split(auditLog.trim())[AUDIT_LOG_TYPE] == AUDIT_LOG_TYPE_FILE;
}
Show replies by date