I don't think the MDB runs in the transaction created by jBPM. But I'm not sure
since I'm still picking up on jBPM. Maybe you are referring to the JbpmContext I
create in the MDB to load the token and signal it.
The MDB is started when JBoss starts up. It's subscribed to a JMS Topic.
The ExternalServiceActionHandler calls a JMS client that creates a TextMessage (procesd
defn id, process instance id, root token id, token id, token name, token full name) and
posts it on the Topic. The MDB takes this TextMessage does some processing, creates a
JbpmContext, gets the GraphSession, loads the token using the token id that was posted,
and then calls signal on it.
Below is the code. I can attach the files and process defn if required. Thanks for your
help and time.
ExternalServiceActionHandler:
| public class ExternalServiceActionHandler implements ActionHandler
| {
| private static final long serialVersionUID = 1L;
|
| private static final Logger log =
Logger.getLogger(ExternalServiceActionHandler.class);
|
| public void execute(ExecutionContext executionContext) throws Exception
| {
| String inputName = (String)executionContext.getVariable("inputName");
|
| String defaultTransitionName =
executionContext.getNode().getDefaultLeavingTransition().getName();
| System.out.println("ExternalServiceActionHandler.execute : ##########
DefaultTransitionName : " + defaultTransitionName);
|
| long processDefnId =
executionContext.getProcessInstance().getProcessDefinition().getId();
| System.out.println("ExternalServiceActionHandler.execute : ##########
getProcessInstance().getProcessDefinition().getId() PROCESS DEFINITION ID : " +
processDefnId);
|
| long processInstanceId = executionContext.getProcessInstance().getId();
| System.out.println("ExternalServiceActionHandler.execute : ##########
getProcessInstance().getId() PROCESS INSTANCE ID : " + processInstanceId);
|
| long rootTokenId = executionContext.getProcessInstance().getRootToken().getId();
| System.out.println("ExternalServiceActionHandler.execute : ##########
getRootToken().getId() TOKEN ID : " + rootTokenId);
|
| String tokenName = executionContext.getToken().getName();
| String tokenFullName = executionContext.getToken().getFullName();
| long tokenId = executionContext.getToken().getId();
| System.out.println("ExternalServiceActionHandler.execute : ##########
executionContext.getToken().getName() : " + tokenName);
| System.out.println("ExternalServiceActionHandler.execute : ##########
executionContext.getToken().getFullName() : " + tokenFullName);
| System.out.println("ExternalServiceActionHandler.execute : ##########
executionContext.getToken().getId() : " + tokenId);
|
| TestProducer.send(inputName, processDefnId, processInstanceId, rootTokenId,
tokenId, tokenName, tokenFullName);
|
| }
|
| }
|
TestProducer is a class that posts messages on to the topic.
TestMessageBean (the MDB):
|
| @MessageDriven(activationConfig =
| {
| @ActivationConfigProperty(propertyName="destinationType",
propertyValue="javax.jms.Topic"),
| @ActivationConfigProperty(propertyName="destination",
propertyValue="topic/eventTopic"),
| })
| public class TestMessageBean implements MessageListener
| {
| static Map<String, String> tokenMap = Collections.synchronizedMap(new
HashMap());
|
| static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
|
| public void onMessage(Message recvMsg)
| {
|
| String personName = "";
| String button = "";
|
| try
| {
| if (recvMsg instanceof TextMessage)
| {
| TextMessage message = (TextMessage)recvMsg;
| String text = message.getText();
|
| if (text != null && text.startsWith("INPUT_NAME:"))
| savePerson(text);
| }
|
| if (recvMsg.propertyExists("PERSON_NAME"))
| {
| person = recvMsg.getStringProperty("PERSON_NAME");
|
| if (tokenMap.containsKey(person))
| {
| String tokenId = tokenMap.get(person);
| System.out.println("Person tokenId : " + tokenId);
| System.out.println("Person tokenId (long) : " +
Long.parseLong(tokenId));
|
| JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
| System.out.println("Got the JbpmContext");
|
| GraphSession graphSession = jbpmContext.getGraphSession();
| System.out.println("Got the GraphSession");
|
| Token token = graphSession.loadToken(Long.parseLong(tokenId));
| System.out.println("Got the token : " + token.getFullName());
|
| token.signal();
| /*
| ProcessInstance processInstance =
DbUtils.loadProcessInstance(Long.parseLong(tokenId));
| System.out.println("Process Instance Id : " +
processInstance.getId());
| System.out.println("Process Instance getRootToken Id : " +
processInstance.getRootToken().getId());
| Token token = processInstance.getRootToken();
| token.signal();
| */
| System.out.println("Called token.signal");
|
| //DbUtils.saveToken(token);
| jbpmContext.save(token);
|
| //jbpmContext.close();
|
| // remove the "matched" rfid=tokenId from the Map
| tokenMap.remove(person);
|
| }
|
| }
|
| }
| catch (JMSException e)
| {
| e.printStackTrace();
| }
|
| }
|
|
| private void savePerson(String text)
| {
| Pattern p = Pattern.compile(",");
| String[] result = p.split(text);
|
| if (result.length > 0)
| {
| String inputPerson = result[0]; // personName
| String processDefnId = result[1]; // processDefnId
| String processInstanceId = result[2]; // processInstanceId
| String rootTokenId = result[3]; // rootTokenId
| String tokenId = result[4]; // tokenId
| String tokenName = result[5]; // tokenName
| String tokenFullName = result[6]; // tokenFullName
|
| tokenMap.put(inputPerson.substring(inputPerson.indexOf(":") + 1),
tokenId.substring(tokenId.indexOf(":") + 1) );
| }
| }
|
| }
|
|
***************************
anonymous wrote :
| You signal the stateA in it's own node-enter, wich is not advised.
|
Is there a reason you stated the above? Is it a bad practice or is there something more to
it?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3962051#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...