View Javadoc
1 package org.smartcomps.twister.engine.priv.messaging; 2 3 import org.dom4j.Element; 4 import org.dom4j.DocumentHelper; 5 import org.dom4j.Document; 6 import org.smartcomps.twister.worklist.TwisterWorkListFactory; 7 import org.smartcomps.twister.worklist.exception.InvalidMessageException; 8 import org.smartcomps.twister.common.util.logger.Logger; 9 import org.smartcomps.twister.common.persistence.CreationException; 10 import org.smartcomps.twister.engine.priv.messaging.impl.DefaultMessageBrokerImpl; 11 12 /*** 13 * Creates and sends messages as ordered by the engine core. This class is abstract and 14 * therefore must be subclassed to do anything interesting. By subclassing it you'll be 15 * able to receive those messages and forward them to your own services in a relevent 16 * way for your own business. To make this class call your services you will have to 17 * provide your own implementation, put it in the classpath and change the 18 * <i>twister.messagebroker.impl</i> property in the twister-implementation.properties 19 * file. 20 */ 21 public abstract class MessageBroker { 22 23 public static final String WORKLIST_PT = "WORKLISTPT"; 24 public static final String WORKLIST_OP = "CREATEWORK"; 25 26 private static Logger log = Logger.getLogger(DefaultMessageBrokerImpl.class); 27 28 /*** 29 * Sends asynchronously a message to the specified (operation, portType, partner). 30 * As it's asynchronous, no response are expected. Keep in mind that the provided 31 * message can be null if we're simply invoking a service with no input parameter. 32 * Check if the message is not targeted at the WorkList Manager. If it is, creates 33 * a new WorkItem, if it isn't, just forward the call to <code>asyncCall</call>. 34 * @param partner 35 * @param portType 36 * @param operation 37 * @param message 38 */ 39 public final void asyncInvoke(String partner, String portType, String operation, Document message) { 40 asyncSend(partner, portType, operation, message); 41 } 42 43 /*** 44 * Syncronously send a message to the specified (operation, portType, partner). A 45 * response is expected in return. 46 * @param partner 47 * @param portType 48 * @param operation 49 * @param message 50 * @return 51 */ 52 public final Document syncInvoke(String partner, String portType, String operation, Document message) { 53 if (WORKLIST_PT.equals(portType.toUpperCase().trim()) 54 && WORKLIST_OP.equals(operation.toUpperCase().trim())) { 55 Long wiId = null; 56 try { 57 wiId = TwisterWorkListFactory.getWorkList().createWorkItem(message); 58 } catch (InvalidMessageException e) { 59 log.error("Could not create a WorkItem, the message sent to the WorkList Manager is " + 60 "not valid", e); 61 } catch (CreationException e) { 62 log.error("Could not create a WorkItem", e); 63 } 64 65 Document resultDoc = DocumentHelper.createDocument(); 66 Element resultMsg = resultDoc.addElement("message"); 67 resultMsg.addElement("wipart").addElement("workitemid").setText(wiId.toString()); 68 return resultDoc; 69 } else { 70 return syncSend(partner, portType, operation, message); 71 } 72 } 73 74 /*** 75 * Implement this method in your subclass to receive messages from the process 76 * engine and execute your own tasks accordingly. Keep in mind that the provided 77 * message can be null if we're simply invoking a service with no input parameter. 78 * @param partner 79 * @param portType 80 * @param operation 81 * @param message 82 */ 83 protected abstract void asyncSend(String partner, String portType, String operation, Document message); 84 85 /*** 86 * Implement this method in your subclass to receive messages from the process 87 * engine and execute your own tasks accordingly. Keep in mind that the provided 88 * message can be null if we're simply invoking a service with no input parameter. 89 * @param partner 90 * @param portType 91 * @param operation 92 * @param message 93 * @return 94 */ 95 protected abstract Document syncSend(String partner, String portType, String operation, Document message); 96 }

This page was automatically generated by Maven