As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
<br>import javax.ejb.ActivationConfigProperty;<br>import javax.ejb.MessageDriven;<br>import javax.inject.Inject;<br>import javax.jms.JMSException;<br>import javax.jms.Message;<br>import javax.jms.MessageListener;<br>import javax.jms.TextMessage;<br><br>import org.activiti.engine.ProcessEngine;<br>import org.slf4j.Logger;<br>import org.slf4j.LoggerFactory;<br><br>@MessageDriven(activationConfig = {<br> @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/activitiJobExecutor"),<br> @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),<br> @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") })<br>public class JobExecutorBean implements MessageListener {<br><br> protected static Logger log = LoggerFactory.getLogger(JobExecutorBean.class);<br><br> @Inject<br> protected ProcessEngine processEngine;<br><br> @Override<br> public void onMessage(Message message) {<br> String jobId = getJobIdFromMessage(message);<br><br> if (jobId != null) {<br> processEngine.getManagementService().executeJob(jobId);<br> }<br> }<br><br> protected String getJobIdFromMessage(Message message) {<br> if (message instanceof TextMessage) {<br> try {<br> TextMessage textMessage = (TextMessage) message;<br> log.debug("Recevied message over JMS: '{}'", textMessage.getText());<br> return textMessage.getText();<br> } catch (JMSException e) {<br> log.error("Error occured while reading JMS TextMessage", e);<br> return null;<br> }<br> }<br><br> return null;<br> }<br>}<br>
<br>/**<br> * Interface to be implemented by a MessageDriven bean handling the execution of<br> * a job.<br> * <br> * @author Daniel Meyer<br> * <br> */<br>public interface JobExecutionHandler {<br><br> public void executeJob(String jobId, CommandExecutor commandExecutor);<br><br>}