1 package org.smartcomps.twister.engine.priv.messaging.impl;
2
3 import org.smartcomps.twister.engine.priv.messaging.MessageBroker;
4 import org.smartcomps.twister.common.util.logger.Logger;
5 import org.dom4j.Element;
6 import org.dom4j.DocumentHelper;
7 import org.dom4j.Document;
8
9 import java.util.HashMap;
10
11 /***
12 * A default implementation of the MessageBroker interface that
13 * does absolutely nothing.
14 */
15 public class DefaultMessageBrokerImpl extends MessageBroker {
16
17 private static Logger log = Logger.getLogger(DefaultMessageBrokerImpl.class);
18 private static HashMap messages = new HashMap();
19
20 public void asyncSend(String partner, String portType, String operation, Document message) {
21 log.info("Send an asynchronous message with partner = " + partner + ", portType = " +
22 portType + ", operation = " + operation + " and message " + message);
23 if (message != null) {
24 messages.put(partner + "/" + portType + "/" + operation + "/", message);
25 } else {
26 Document nullDoc = DocumentHelper.createDocument();
27 nullDoc.addElement("null");
28 messages.put(partner + "/" + portType + "/" + operation + "/", nullDoc);
29 }
30 }
31
32 public Document syncSend(String partner, String portType, String operation, Document message) {
33 Document doc = DocumentHelper.createDocument();
34 Element elmt = doc.addElement("message");
35 elmt.addElement("reply").addElement("status").setText("ok");
36 if (message != null) {
37 messages.put(partner + "/" + portType + "/" + operation + "/", message);
38 } else {
39 Document nullDoc = DocumentHelper.createDocument();
40 nullDoc.addElement("null");
41 messages.put(partner + "/" + portType + "/" + operation + "/", nullDoc);
42 }
43 log.info("Send a synchronous message with partner = " + partner + ", portType = " +
44 portType + ", operation = " + operation + " and message " + message);
45 return doc;
46 }
47
48 public static Document getMessage(String partner, String portType, String operation) {
49 return (Document) messages.get(partner + "/" + portType + "/" + operation + "/");
50 }
51 }
This page was automatically generated by Maven