TC ONG [
https://community.jboss.org/people/devilkazuya99] created the discussion
"Working with KnowledgeAgent and ChangeSet.xml"
To view the discussion, visit:
https://community.jboss.org/message/722692#722692
--------------------------------------------------------------
Seeking for help.
I have a changeset.xml adding my JavaInteractiveFlow.rf.
I have id="interactiveJava" in JavaInteractiveFlow.rf.
But when I run the code below, it gives me
Unknown process ID: interactiveJava
Can anyone show me how to get this works?
Here is my code.
package com.geneoz.procedureengine;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.log4j.Logger;
import org.drools.KnowledgeBase;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentConfiguration;
import org.drools.agent.KnowledgeAgentFactory;
import org.drools.event.knowledgeagent.AfterChangeSetAppliedEvent;
import org.drools.event.knowledgeagent.AfterChangeSetProcessedEvent;
import org.drools.event.knowledgeagent.AfterResourceProcessedEvent;
import org.drools.event.knowledgeagent.BeforeChangeSetAppliedEvent;
import org.drools.event.knowledgeagent.BeforeChangeSetProcessedEvent;
import org.drools.event.knowledgeagent.BeforeResourceProcessedEvent;
import org.drools.event.knowledgeagent.KnowledgeAgentEventListener;
import org.drools.event.knowledgeagent.KnowledgeBaseUpdatedEvent;
import org.drools.event.knowledgeagent.ResourceCompilationFailedEvent;
import org.drools.io.ResourceChangeScannerConfiguration;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
public class KnowledgeAgentTest {
static String CHANGE_SET_URL = "
http://192.168.10.13/drools/changeset.xml
http://192.168.10.13/drools/changeset.xml";
static String JAVA_INTERACTIVE_URL = "
http://192.168.10.13/drools/JavaInteractiveFlow.rf
http://192.168.10.13/drools/JavaInteractiveFlow.rf";
static Logger logger = Logger.getLogger(KnowledgeAgentTest.class);
public static void main(String[] args) {
try {
KnowledgeAgentConfiguration agentConfig =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
agentConfig.setProperty("drools.agent.newInstance",
"true");
agentConfig.setProperty("drools.agent.scanDirectories",
"false");
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent( "MyKnowledgeAgent", agentConfig );
KnowledgeAgentEventListener kaListener = new
KnowledgeAgentEventListener() {
@Override
public void
resourceCompilationFailed(ResourceCompilationFailedEvent arg0) {
logger.debug("resourceCompilationFailed");
}
@Override
public void
knowledgeBaseUpdated(KnowledgeBaseUpdatedEvent arg0) {
logger.debug("knowledgeBaseUpdated");
}
@Override
public void
beforeResourceProcessed(BeforeResourceProcessedEvent arg0) {
logger.debug("beforeResourceProcessed");
}
@Override
public void
beforeChangeSetProcessed(BeforeChangeSetProcessedEvent arg0) {
logger.debug("beforeChangeSetProcessed");
}
@Override
public void
beforeChangeSetApplied(BeforeChangeSetAppliedEvent arg0) {
logger.debug("beforeChangeSetApplied");
}
@Override
public void
afterResourceProcessed(AfterResourceProcessedEvent arg0) {
logger.debug("afterResourceProcessed");
}
@Override
public void
afterChangeSetProcessed(AfterChangeSetProcessedEvent arg0) {
logger.debug("afterChangeSetProcessed");
}
@Override
public void
afterChangeSetApplied(AfterChangeSetAppliedEvent arg0) {
logger.debug("afterChangeSetApplied");
}
};
kagent.addEventListener(kaListener);
kagent.applyChangeSet(
ResourceFactory.newUrlResource(CHANGE_SET_URL) );
kagent.monitorResourceChangeEvents(true);
ResourceChangeScannerConfiguration scannerConfig =
ResourceFactory
.getResourceChangeScannerService()
.newResourceChangeScannerConfiguration();
scannerConfig.setProperty("drools.resource.scanner.interval",
"2");
ResourceFactory.getResourceChangeScannerService().configure(scannerConfig);
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
KnowledgeBase kbase = kagent.getKnowledgeBase();
System.out.println(kbase.getClass());
logger.debug("Creting new KnowledgeSession");
final StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
logger.debug("Executing session.");
String input = null;
while(!"yes".equals(input)) {
ksession.startProcess("interactiveJava");
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
try {
System.out.print("Exit?");
input = br.readLine();
} catch (IOException e) {
System.out.println("Error!");
}
}
logger.debug("Finish execution.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/722692#722692]
Start a new discussion in jBPM at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]