1 /*------------------------------------------------------------------------------
2 Name: BlasterCallbackImpl.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Handling the Client callback
6 YOU MAY USE THIS AS YOUR Callback implementation, JUST TAKE A COPY OF IT
7 Version: $Id: BlasterCallbackImpl.java 14915 2006-03-12 20:48:39Z ruff $
8 ------------------------------------------------------------------------------*/
9 package javaclients.corba;
10
11 import org.xmlBlaster.util.Global;
12 import java.util.logging.Logger;
13 import java.util.logging.Level;
14 import org.xmlBlaster.util.XmlBlasterException;
15 import org.xmlBlaster.client.key.UpdateKey;
16 import org.xmlBlaster.util.MsgUnitRaw;
17 import org.xmlBlaster.util.def.Constants;
18 import org.xmlBlaster.util.protocol.corba.OrbInstanceFactory;
19 import org.xmlBlaster.protocol.corba.clientIdl.*;
20
21
22 /**
23 * Demo Client implementation of the CORBA callback.
24 * <p />
25 * YOU MAY USE THIS AS YOUR CALLBACK IMPLEMENTATION, JUST TAKE A COPY OF IT.
26 * <p />
27 * Note that there is a default Callback implementation hidden behind I_XmlBlasterAccess.java<br />
28 * (see xmlBlaster/src/java/org/xmlBlaster/client/protocol/corba/CorbaCallbackServer.java)
29 * which is usually sufficient, so you don't really need to implement the callback code yourself.<br />
30 * See xmlBlaster/demo/javaclients/ClientSub.java for an example how to use it.
31 * <p />
32 */
33 //public class BlasterCallbackImpl extends BlasterCallbackPOA { // inheritance approach
34 public class BlasterCallbackImpl implements BlasterCallbackOperations { // tie approach
35 final String ME;
36 private final Global glob;
37 private static Logger log = Logger.getLogger(BlasterCallbackImpl.class.getName());
38
39 /**
40 * Construct the client CORBA side callback server.
41 */
42 public BlasterCallbackImpl(java.lang.String name) {
43 this.ME = "BlasterCallbackImpl-" + name;
44 this.glob = Global.instance();
45
46 if (log.isLoggable(Level.FINER)) log.fine("Entering constructor with argument");
47 }
48
49 /**
50 * Construct the client CORBA side callback server.
51 */
52 public BlasterCallbackImpl() {
53 this("");
54 }
55
56 /**
57 * This is the callback method invoked from the server
58 * informing the client in an asynchronous mode about new messages
59 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>
60 */
61 public String[] update(String cbSessionId, org.xmlBlaster.protocol.corba.serverIdl.MessageUnit[] corbaMsgUnitArr)
62 {
63 log.info("#================== BlasterCallback update START =============");
64 log.info("cbSessionId=" + cbSessionId);
65 String[] ret = new String[corbaMsgUnitArr.length];
66 try {
67 MsgUnitRaw[] msgUnitArr = OrbInstanceFactory.convert(glob, corbaMsgUnitArr);
68 for (int ii=0; ii<msgUnitArr.length; ii++) {
69 MsgUnitRaw msgUnit = msgUnitArr[ii];
70 UpdateKey xmlKey = null;
71 try {
72 xmlKey = new UpdateKey(null, msgUnit.getKey());
73 } catch (XmlBlasterException e) {
74 log.severe(e.getMessage());
75 }
76 log.info("Callback invoked for " + xmlKey.toString() + " content length = " + msgUnit.getContent().length);
77 log.info(new String(msgUnit.getContent()));
78 ret[ii] = Constants.RET_OK; // "<qos><state id='OK'/></qos>";
79 }
80 }
81 catch (XmlBlasterException e) {
82 log.severe(e.getMessage());
83 }
84 log.info("#================== BlasterCallback update END ===============");
85 return ret;
86 }
87
88 /**
89 * This is the callback method invoked from the CORBA server
90 * informing the client in an asynchronous mode about new messages.
91 * <p />
92 * This oneway method does not return something, it is high performing but
93 * you loose the application level hand shake.
94 *
95 * @param msgUnitArr Contains a MessageUnit structs (your message) for CORBA
96 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>
97 */
98 public void updateOneway(String cbSessionId, org.xmlBlaster.protocol.corba.serverIdl.MessageUnit[] msgUnitArr)
99 {
100 try {
101 update(cbSessionId, msgUnitArr);
102 }
103 catch (Throwable e) {
104 log.severe("updateOneway() failed, exception is not sent to xmlBlaster: " + e.toString());
105 e.printStackTrace();
106 }
107 }
108
109 /**
110 * Ping to check if the callback server is alive.
111 * @param qos ""
112 * @return ""
113 */
114 public String ping(String qos)
115 {
116 if (log.isLoggable(Level.FINER)) log.finer("Entering ping() ...");
117 return "";
118 }
119 }
syntax highlighted by Code2HTML, v. 0.9.1