1 /*------------------------------------------------------------------------------
2 Name: PublishReturnQos.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 ------------------------------------------------------------------------------*/
6 package org.xmlBlaster.client.qos;
7
8 import java.util.Properties;
9
10 import org.xmlBlaster.util.Global;
11 import org.xmlBlaster.util.XmlBlasterException;
12 import org.xmlBlaster.util.qos.StatusQosData;
13 import org.xmlBlaster.util.Timestamp;
14 import org.xmlBlaster.util.def.MethodName;
15
16 /**
17 * Handling the returned QoS (quality of service) of a publish() call.
18 * <p />
19 * If you are a Java client and use the I_XmlBlasterAccess interface
20 * you get this object as the publish() return value.
21 * <p />
22 * Example:
23 * <pre>
24 * <qos>
25 * <state id='OK' info='QUEUED[bilbo]'/>
26 * <key oid='HelloWorld'/>
27 * <rcvTimestamp nanos='1007764305862000002'/>
28 * <!-- UTC time when message was created in xmlBlaster server with a publish() call, in nanoseconds since 1970 -->
29 * </qos>
30 * </pre>
31 * @see org.xmlBlaster.test.classtest.qos.StatusQosFactoryTest
32 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.publish.html" target="others">the interface.publish requirement</a>
33 */
34 public final class PublishReturnQos
35 {
36 private final StatusQosData statusQosData;
37
38 /**
39 * Constructor which parses XML string.
40 */
41 public PublishReturnQos(Global glob, String xmlQos) throws XmlBlasterException {
42 this.statusQosData = glob.getStatusQosFactory().readObject(xmlQos);
43 this.statusQosData.setMethod(MethodName.PUBLISH);
44 }
45
46 /**
47 * Constructor which reuses a StatusQosData object.
48 */
49 public PublishReturnQos(Global glob, StatusQosData statusQosData) {
50 this.statusQosData = statusQosData;
51 this.statusQosData.setMethod(MethodName.PUBLISH);
52 }
53
54 /**
55 * Access the raw data object, usually you shouldn't do it.
56 * @return The raw data object
57 */
58 public StatusQosData getData() {
59 return statusQosData;
60 }
61
62 /**
63 * Access the state of message.
64 * @return OK (Other values are not yet supported)
65 */
66 public final String getState() {
67 return this.statusQosData.getState();
68 }
69
70 /**
71 * Additional structured information about a state.
72 * @return "QUEUED" or "QUEUED[bilbo]"
73 * @see org.xmlBlaster.util.def.Constants
74 */
75 public final String getStateInfo() {
76 return this.statusQosData.getStateInfo();
77 }
78
79 /**
80 * Access key oid.
81 * @return The unique identifier of a message
82 */
83 public final String getKeyOid() {
84 return this.statusQosData.getKeyOid();
85 }
86
87 /**
88 * The approximate receive timestamp (UTC time),
89 * when message arrived in requestBroker.publish() method.<br />
90 * In milliseconds elapsed since midnight, January 1, 1970 UTC<br />
91 * <p>
92 * This timestamp is unique for a message instance published and may be
93 * used to identify this message. For example a publisher and a receiver
94 * of a message can identify this message by its topic (key oid) and its
95 * receive timestamp.
96 * </p>
97 * <p>
98 * To get a human readable view on the timestamp try:
99 * </p>
100 * <pre>
101 * String time = publishReturnQos.getRcvTimestamp().toString();
102 *
103 * -> "2002-02-10 10:52:40.879456789"
104 * </pre>
105 */
106 public final Timestamp getRcvTimestamp() {
107 return this.statusQosData.getRcvTimestamp();
108 }
109
110 /**
111 * @see #toXml(String)
112 */
113 public final String toXml() {
114 return toXml((String)null);
115 }
116
117 /**
118 * Dump state of this object into a XML ASCII string.
119 * @param extraOffset indenting of tags for nice output
120 * @return The XML representation
121 */
122 public final String toXml(String extraOffset) {
123 return this.statusQosData.toXml(extraOffset, (Properties)null);
124 }
125
126 public final String toString() {
127 return toXml(null);
128 }
129 }
syntax highlighted by Code2HTML, v. 0.9.1