[jBPM] - Using KnowledgeAgentEventListener to detect new processes (v5.4.0)
by cold gin
cold gin [https://community.jboss.org/people/cold_gin] created the discussion
"Using KnowledgeAgentEventListener to detect new processes (v5.4.0)"
To view the discussion, visit: https://community.jboss.org/message/820162#820162
--------------------------------------------------------------
I am trying to implement a KnowledgeAgentEventListener so that I can detect *newly added* processes, and I would also like to be able to detect the creation of new packages somehow. So far, I have created a KnowledgeAgent, added a KnowledgeAgentEventListener, but all that comes back on the beforeResourceAdded() and afterResourceAdded() event handlers are RESOURCE_DELETED statuses. When I print out the event source object type, it's ChangeSetImpl, which I guess makes sense since I am adding the change set as the resource type to the knowledge agent, and I guess that the change set is being replaced, so I get the RESOURCE_DELETED status. But I am trying to figure out how to configure the knowledge agent so that I can receive more fine-grained change events such as PROCESS_ADDED and PROCESS_UPDATED statuses (if such jbpm statuses exist).
Here is the relevant code so far:
KnowledgeAgentConfiguration agentConfig = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
// Tells jBPM to update existing knowledge base and not to create a new one each time:
agentConfig.setProperty("drools.agent.newInstance", "false");
// Tells jBPM what to scan:
agentConfig.setProperty("drools.agent.monitorChangeSetEvents", "true");
agentConfig.setProperty("drools.agent.scanDirectories", "true");
agentConfig.setProperty("drools.agent.scanResources", "true");
KnowledgeAgent knowledgeAgent = KnowledgeAgentFactory.newKnowledgeAgent(knowledgeAgentName,agentConfig);
org.drools.io.Resource changeSetResource = createChangeSetResouceUsing(changeSetXmlAsString);
knowledgeAgent.applyChangeSet(changeSetResource);
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
knowledgeAgent.addEventListener(new KnowledgeAgentEventListener() {
@Override
public void beforeChangeSetApplied(BeforeChangeSetAppliedEvent event) {
logger.debug("beforeChangeSetApplied() event handler called");
}
@Override
public void afterChangeSetApplied(AfterChangeSetAppliedEvent eve nt) {
logger.debug("afterChangeSetApplied() event handler called");
}
@Override
public void beforeChangeSetProcessed(BeforeChangeSetProcessedEvent event) {
logger.debug("beforeChangeSetProcessed() event handler called");
}
@Override
public void afterChangeSetProcessed(AfterChangeSetProcessedEvent event) {
logger.debug("afterChangeSetProcessed() event handler called");
}
@Override
public void beforeResourceProcessed(BeforeResourceProcessedEvent event) {
logger.debug("=======================================================");
logger.debug("beforeResourceProcessed() event handler called");
logger.debug("beforeResourceProcessed() - event.getResource(): " + event.getResource().toString());
logger.debug("beforeResourceProcessed() - event.getResourceType(): [ " + event.getResourceType().getName() + ", " + event.getResourceType().getDescription() + " ]");
logger.debug("beforeResourceProcessed() - event.getStatus().name(): " + event.getStatus().name());
logger.debug("beforeResourceProcessed() - event.getStatus(): " + event.getStatus());
logger.debug("beforeResourceProcessed() - event.getSource().getClass().getCanonicalName(): " + event.getSource().getClass().getCanonicalName());
logger.debug("=======================================================");
}
@Override
public void afterResourceProcessed(AfterResourceProcessedEvent event) {
logger.debug("=======================================================");
logger.debug("afterResourceProcessed() event handler called");
logger.debug("afterResourceProcessed() - event.getResource(): " + event.getResource().toString());
logger.debug("afterResourceProcessed() - event.getResourceType(): [ " + event.getResourceType().getName() + ", " + event.getResourceType().getDescription() + " ]");
logger.debug("afterResourceProcessed() - event.getStatus().name(): " + event.getStatus().name());
logger.debug("afterResourceProcessed() - event.getStatus(): " + event.getStatus());
logger.debug("afterResourceProcessed() - event.getSource().getClass().getCanonicalName(): " + event.getSource().getClass().getCanonicalName());
logger.debug("=======================================================");
}
@Override
public void knowledgeBaseUpdated(KnowledgeBaseUpdatedEvent event) {
logger.debug("knowledgeBaseUpdated() event handler called");
logger.debug("knowledgeBaseUpdated(): Logging kbase process names after update...");
for(org.drools.definition.process.Process process:event.getKnowledgeBase().getProcesses())
{
logger.debug("knowledgeBaseUpdated(): process name == " + process.getName());
}
}
@Override
public void resourceCompilationFailed(ResourceCompilationFailedEvent event) {
logger.debug("resourceCompilationFailed() event handler called");
}
});
Questions:
1.) Is it possible to configure the knowledge agent in such a way that I could receive specific "PROCESS_ADDED / PROCESS_UPDATED" events when a process is added/updated in a package?
(currently I only see the new process logged in the code above inside of the knowledgeBaseUpdated() handler, but I am not receiving a specific event as to *what caused* the knowledge base to be updated
2.) I have seen a few references warning that the change notifier and change scanner services must be stopped or a memory leak can occur, but where would you stop them? The
knowledge base needs to "live on" and be updated as new knowledge sessions are created from it. So the only place I would be stopping these services and disposing of the
knowledge agent, would be when the server is rebooted. Is this incorrect? If so, *when* would be an appropriate time to stop these services?
3.) Is it possible to detect newly created packages using KnowledgeAgentEventListener? If not, is there some other listener that can be implemented to detect new packages?
Just as some additional info, the change set resource is created with change set xml that specifies resource type = PKG for all of the packages that I want to be monitored for adds/updates (inside of 'add' xml tags), and then:
private org.drools.io.Resource createChangeSetResouceUsing(String changeSetXmlAsString) {
org.drools.io.Resource changeSetResource = new ByteArrayResource(changeSetXmlAsString.getBytes());
((InternalResource) changeSetResource).setResourceType(ResourceType.CHANGE_SET);
return changeSetResource;
}
Thanks in advance for any insights.
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/820162#820162]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
12 years, 10 months
[jBPM] - Why the first User Task was executed by ksession.startProcess
by eden li
eden li [https://community.jboss.org/people/eden_li] created the discussion
"Why the first User Task was executed by ksession.startProcess"
To view the discussion, visit: https://community.jboss.org/message/820072#820072
--------------------------------------------------------------
Hi JBPMers.
When I create a process within three user task nodes and run it, I found the first user task was executed by the method startprocess. It results to the case that still three task records has been generated. But only first two records has been completed and the last record was in Ready status. Also the first two records was completed by the next two user task's node. Then the first user task's information like owner_id and initiator_id totally can not be found in those task records.
So could please tell me hwo to avoid the first user task executed by the method startprocess from ksession. I think it should be more resonable. Following are my relevant sources and BPMN2 file.
private static KnowledgeBase readKnowledgeBase() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newFileResource("D:\\workSpace\\PoC2\\ExperimentOA\\bin\\MainBusinessProcess.bpmn2"), ResourceType.BPMN2);
return kbuilder.newKnowledgeBase();
}
public static StatefulKnowledgeSession newKsession() {
StatefulKnowledgeSession ksession;
try {
KnowledgeBase kbase = readKnowledgeBase();
ksession = JBPMHelper.newStatefulKnowledgeSession(kbase);
} catch(Exception e) {
throw new RuntimeException(e);
}
return ksession;
}
public static void startProcess(StatefulKnowledgeSession ksession, String s, Map params) {
HashMap<String, Object> results = new HashMap<String, Object>();
params.put("results", results);
params.put("ksessionId", String.valueOf(ksession.getId()));
ksession.startProcess(s, params);
}
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/820072#820072]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
12 years, 10 months
[jBPM] - BPMN2 Designer Stuck loading after adding custom work item definition
by Andrew Tan
Andrew Tan [https://community.jboss.org/people/atan20] created the discussion
"BPMN2 Designer Stuck loading after adding custom work item definition"
To view the discussion, visit: https://community.jboss.org/message/820047#820047
--------------------------------------------------------------
I am trying to create a simple BPMN2 process that uses a domain specific service. However, after I add a new work item definition in drools-guvnor 5.3.1 and I attempt to create or open an existing bpmn2 process the designer gets stuck on the "Please Wait Loading" screen.
https://community.jboss.org/servlet/JiveServlet/showImage/2-820047-20876/... https://community.jboss.org/servlet/JiveServlet/downloadImage/2-820047-20...
Here is my work item definition:
import org.drools.process.core.datatype.impl.type.ObjectDataType;import org.drools.process.core.datatype.impl.type.StringDataType;
[
[ "name" : "MyTask", "parameters" : [ "MyFirstParam" : new StringDataType(), "MySecondParam" : new StringDataType(), "MyThirdParam" : new ObjectDataType() ], "results" : [ "Result" : new ObjectDataType() ], "displayName" : "My Task", "icon" : "", ] ]
Looking at the server.log file of JBoss ESB I can see drools-guvnor loading the custom work item definition, and I am able to build my package in drools guvnor
2013-05-29 18:20:49,120 INFO com.intalio.web.preprocessing.impl.JbpmPreprocessingUnit com.intalio.web.preprocessing.impl.JbpmPreprocessingUnit (http-127.0.0.1-8080-1) Created file:/opt/jboss-soa-p-5/jboss-as/server/all/tmp/4st5t49-27ns8v-hha869gx-1-hha88mdt-c7/designer.war/stencilsets/bpmn2.0jbpm/view/activity/workitems/Log.svg
2013-05-29 18:20:49,121 INFO com.intalio.web.preprocessing.impl.JbpmPreprocessingUnit com.intalio.web.preprocessing.impl.JbpmPreprocessingUnit (http-127.0.0.1-8080-1) Created file:/opt/jboss-soa-p-5/jboss-as/server/all/tmp/4st5t49-27ns8v-hha869gx-1-hha88mdt-c7/designer.war/stencilsets/bpmn2.0jbpm/view/activity/workitems/Email.svg
2013-05-29 18:20:49,122 INFO com.intalio.web.preprocessing.impl.JbpmPreprocessingUnit com.intalio.web.preprocessing.impl.JbpmPreprocessingUnit (http-127.0.0.1-8080-1) Created file:/opt/jboss-soa-p-5/jboss-as/server/all/tmp/4st5t49-27ns8v-hha869gx-1-hha88mdt-c7/designer.war/stencilsets/bpmn2.0jbpm/view/activity/workitems/MyTask.svg
Does anyone have any ideas about why the designer is getting stuck in the "Please Wait Loading" Screen?
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/820047#820047]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
12 years, 10 months