Author: tsurdilovic
Date: 2010-01-08 12:32:48 -0500 (Fri, 08 Jan 2010)
New Revision: 11941
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-08
17:29:57 UTC (rev 11940)
+++
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java 2010-01-08
17:32:48 UTC (rev 11941)
@@ -1,14 +1,10 @@
package org.jboss.seam.drools;
import java.io.InputStream;
-import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
-import javax.annotation.PreDestroy;
-import javax.enterprise.context.Dependent;
-import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.BeanManager;
@@ -18,8 +14,8 @@
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
-import org.drools.builder.KnowledgeBuilderFactory;
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;
@@ -37,7 +33,6 @@
private static final Logger log =
LoggerFactory.getLogger(KnowledgeSessionManager.class);
private KnowledgeSessionManagerConfig ksessionManagerConfig;
- private KnowledgeRuntimeLogger statelessKLogger;
private Map<Integer, KnowledgeRuntimeLogger> statefulKnowledgeLoggers = new
Hashtable<Integer, KnowledgeRuntimeLogger>();
@Inject
@@ -59,7 +54,7 @@
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession(getKSessionConfig(), null);
//addEventListeners(ksession);
//addWorkItemHandlers(ksession);
- //addAuditLog(ksession);
+ addAuditLog(ksession);
manager.fireEvent(new KnowledgeSessionCreatedEvent(ksession.getId()));
return ksession;
}
@@ -79,19 +74,10 @@
{
StatelessKnowledgeSession ksession =
kbase.newStatelessKnowledgeSession(getKSessionConfig());
//addEventListeners(ksession);
- //addAuditLog(ksession);
manager.fireEvent(new KnowledgeSessionCreatedEvent(-1));
return ksession;
}
- public void disposeStatelessSession(@Disposes StatelessKnowledgeSession
statelessSession)
- {
- if (statelessKLogger != null)
- {
- statelessKLogger.close();
- }
- }
-
private KnowledgeSessionConfiguration getKSessionConfig() throws Exception
{
KnowledgeSessionConfiguration ksessionConfig =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
@@ -115,5 +101,26 @@
}
return ksessionConfig;
}
+
+
+ private void addAuditLog(StatefulKnowledgeSession ksession) {
+ if(ksessionManagerConfig.getAuditLog() != null) {
+
if(KnowledgeSessionManagerConfig.isFileLogger(ksessionManagerConfig.getAuditLog())) {
+ String logName =
KnowledgeSessionManagerConfig.getFileLoggerPath(ksessionManagerConfig.getAuditLog()) +
System.currentTimeMillis();
+ KnowledgeRuntimeLogger krLogger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, logName);
+ statefulKnowledgeLoggers.put(ksession.getId(), krLogger);
+ } else
if(KnowledgeSessionManagerConfig.isConsoleLogger(ksessionManagerConfig.getAuditLog())) {
+ KnowledgeRuntimeLogger krLogger =
KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
+ statefulKnowledgeLoggers.put(ksession.getId(), krLogger);
+ } else
if(KnowledgeSessionManagerConfig.isThreadedLogger(ksessionManagerConfig.getAuditLog())) {
+ String logName =
KnowledgeSessionManagerConfig.getThreadedLoggerPath(ksessionManagerConfig.getAuditLog()) +
System.currentTimeMillis();
+ int interval =
KnowledgeSessionManagerConfig.getThreadedLoggerInterval(ksessionManagerConfig.getAuditLog());
+ KnowledgeRuntimeLogger krLogger =
KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, logName, interval);
+ statefulKnowledgeLoggers.put(ksession.getId(), krLogger);
+ } else {
+ log.warn("Invalid logger specified: " +
ksessionManagerConfig.getAuditLog());
+ }
+ }
+ }
}
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-08
17:29:57 UTC (rev 11940)
+++
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManagerConfig.java 2010-01-08
17:32:48 UTC (rev 11941)
@@ -13,12 +13,43 @@
private static final Pattern DIVIDER = Pattern.compile(";");
private static final int WORKITEMHANDLER_NAME = 0;
private static final int WORKITEMHANDLER_TYPE = 1;
+ private static final int AUDIT_LOG_TYPE = 0;
+ private static final int AUDIT_LOG_INFO = 1;
+ private static final int AUDIT_LOG_INTERVAL = 2;
+ private static final String AUDIT_LOG_TYPE_FILE = "file";
+ private static final String AUDIT_LOG_TYPE_CONSOLE = "console";
+ private static final String AUDIT_LOG_TYPE_THREADED = "threaded";
private String[] eventListeners;
private String[] workItemHandlers;
private String knowledgeSessionConfig;
private Properties knowledgeSessionConfigProp;
private String auditLog;
+
+ public static boolean isFileLogger(String auditLog) {
+ return DIVIDER.split(auditLog.trim())[AUDIT_LOG_TYPE] == AUDIT_LOG_TYPE_FILE;
+ }
+
+ public static boolean isConsoleLogger(String auditLog) {
+ return DIVIDER.split(auditLog.trim())[AUDIT_LOG_TYPE] == AUDIT_LOG_TYPE_CONSOLE;
+ }
+
+ public static boolean isThreadedLogger(String auditLog) {
+ return DIVIDER.split(auditLog.trim())[AUDIT_LOG_TYPE] == AUDIT_LOG_TYPE_THREADED;
+ }
+
+ public static String getFileLoggerPath(String auditLog) {
+ return DIVIDER.split(auditLog.trim())[AUDIT_LOG_INFO];
+ }
+
+ public static String getThreadedLoggerPath(String auditLog) {
+ return DIVIDER.split(auditLog.trim())[AUDIT_LOG_INFO];
+ }
+
+ public static int getThreadedLoggerInterval(String auditLog) {
+ return Integer.parseInt(DIVIDER.split(auditLog.trim())[AUDIT_LOG_INTERVAL]);
+ }
+
public String[] getEventListeners()
{
return eventListeners;
Show replies by date