1 /*------------------------------------------------------------------------------
  2 Name:      GetReturnQos.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.logging.Logger;
  9 import java.util.logging.Level;
 10 import org.xmlBlaster.util.Global;
 11 import org.xmlBlaster.util.Timestamp;
 12 import org.xmlBlaster.util.XmlBlasterException;
 13 import org.xmlBlaster.util.SessionName;
 14 import org.xmlBlaster.util.cluster.RouteInfo;
 15 import org.xmlBlaster.util.def.PriorityEnum;
 16 import org.xmlBlaster.util.qos.MsgQosData;
 17 import org.xmlBlaster.util.qos.ClientProperty;
 18 import org.xmlBlaster.util.def.MethodName;
 19 import java.util.Map;
 20 
 21 
 22 /**
 23  * QoS (quality of service) informations sent from server to client<br />
 24  * via the return value of the get() method. 
 25  * <p />
 26  * If you are a Java client you may use this class to parse the QoS argument.
 27  * <p />
 28  * Example:
 29  * <pre>
 30  *   &lt;qos> &lt;!-- GetReturnQos -->
 31  *     &lt;state id='OK'/>
 32  *     &lt;sender>Tim&lt;/sender>
 33  *     &lt;priority>5&lt;/priority>
 34  *     &lt;rcvTimestamp nanos='1007764305862000002'> &lt;!-- UTC time when message was created in xmlBlaster server with a publish() call, in nanoseconds since 1970 -->
 35  *           2001-12-07 23:31:45.862000002   &lt;!-- The nanos from above but human readable -->
 36  *     &lt;/rcvTimestamp>
 37  *     &lt;expiration lifeTime='1200'/> &lt;!-- The overall life time of the message [milliseconds] -->
 38  *     &lt;route>
 39  *        &lt;node id='heron'/>
 40  *     &lt;/route>
 41  *  &lt;/qos>
 42  * </pre>
 43  * @author xmlBlaster@marcelruff.info
 44  */
 45 public final class GetReturnQos
 46 {
 47    private String ME = "GetReturnQos";
 48    private final Global glob;
 49    private static Logger log = Logger.getLogger(GetReturnQos.class.getName());
 50    private final MsgQosData msgQosData;
 51 
 52    /**
 53     * Default constructor for transient messages.
 54     */
 55    public GetReturnQos(Global glob, MsgQosData msgQosData) {
 56       this.glob = (glob==null) ? Global.instance() : glob;
 57 
 58       this.msgQosData = msgQosData;
 59       this.msgQosData.setMethod(MethodName.GET);
 60    }
 61 
 62    /**
 63     * Constructs the specialized quality of service object for a get() call.
 64     */
 65    public GetReturnQos(Global glob, String xmlQos) throws XmlBlasterException {
 66       this(glob, glob.getMsgQosFactory().readObject(xmlQos));
 67    }
 68 
 69    /**
 70     * Get the QoS data object which i'm hiding
 71     */
 72    public MsgQosData getData() {
 73       return this.msgQosData;
 74    }
 75 
 76    /**
 77     * Access sender name.
 78     * @return loginName of sender
 79     */
 80    public SessionName getSender() {
 81       return this.msgQosData.getSender();
 82    }
 83 
 84    /**
 85     * Message priority.
 86     * @return priority 0-9
 87     */
 88    public PriorityEnum getPriority() {
 89       return this.msgQosData.getPriority();
 90    }
 91 
 92    /**
 93     * Access state of message.
 94     * @return OK (Other values are not yet supported)
 95     */
 96    public String getState() {
 97       return this.msgQosData.getState();
 98    }
 99 
100    /**
101     * True if the message is OK
102     */
103    public boolean isOk() {
104       return this.msgQosData.isOk();
105    }
106 
107    /**
108     * True if the message was erased by timer or by a
109     * client invoking erase(). 
110     */
111    public boolean isErased() {
112       return this.msgQosData.isErased();
113    }
114 
115    /**
116     * Is this a volatile message?
117     */
118    public boolean isVolatile() {
119       return this.msgQosData.isVolatile();
120    }
121 
122    /**
123     * Is this a persistent message?
124     */
125    public boolean isPersistent() {
126       return this.msgQosData.isPersistent();
127    }
128 
129    /**
130     * Is this a readonly message?
131     */
132    public boolean isReadonly() {
133       return this.msgQosData.isReadonly();
134    }
135 
136    /**
137     * True if a timeout on this message occurred. 
138     * <p />
139     * Timeouts are spanned by the publisher and thrown by xmlBlaster
140     * on timeout to indicate for example
141     * STALE messages or any other user problem domain specific event.
142     */
143    public boolean isTimeout() {
144       return this.msgQosData.isTimeout();
145    }
146 
147    /** 
148     * The approximate receive timestamp (UTC time),
149     * when message was created - arrived at xmlBlaster server.<br />
150     * In nanoseconds elapsed since midnight, January 1, 1970 UTC
151     */
152    public Timestamp getRcvTimestamp() {
153       return this.msgQosData.getRcvTimestamp();
154    }
155 
156    /**
157     * Human readable form of message receive time in xmlBlaster server,
158     * in SQL representation e.g.:<br />
159     * 2001-12-07 23:31:45.862000004
160     */
161    public String getRcvTime() {
162       return this.msgQosData.getRcvTimestamp().toString();
163    }
164 
165    /**
166     * Approxiamte millis counted from now when message will be discarded
167     * by xmlBlaster.
168     * Calculated by xmlBlaster just before sending the get, so there
169     * will be an offset (the time sending the message to us).
170     * @return The time to live for this message or -1 (unlimited) if not known
171     */
172    public long getRemainingLifeStatic() {
173       return this.msgQosData.getRemainingLifeStatic();
174    }
175 
176    /**
177     * @return never null, but may have length==0
178     */
179    public RouteInfo[] getRouteNodes() {
180       return this.msgQosData.getRouteNodes();
181    }
182 
183    /**
184     * Access all client properties. 
185     * @return a map The return is unordered and the map values are of type ClientProperty. 
186     * @see org.xmlBlaster.util.qos.ClientProperty
187     */
188    public final Map getClientProperties() {
189       return this.msgQosData.getClientProperties();
190    }
191 
192    /**
193     * Read back a property. 
194     * @return The client property or null if not found
195     */
196    public ClientProperty getClientProperty(String key) {
197       return this.msgQosData.getClientProperty(key);
198    }
199 
200    /**
201     * Access the String client property. 
202     * @param name The property key
203     * @param defaultValue The value to return if the property is not known
204     */
205    public final String getClientProperty(String name, String defaultValue) {
206       return this.msgQosData.getClientProperty(name, defaultValue);
207    }
208    
209    /**
210     * Access the integer client property. 
211     * @param name The property key
212     * @param defaultValue The value to return if the property is not known
213     */
214    public final int getClientProperty(String name, int defaultValue) {
215       return this.msgQosData.getClientProperty(name, defaultValue);
216    }
217    
218    /**
219     * Access the boolean client property. 
220     * @param name The property key
221     * @param defaultValue The value to return if the property is not known
222     */
223    public final boolean getClientProperty(String name, boolean defaultValue) {
224       return this.msgQosData.getClientProperty(name, defaultValue);
225    }
226    
227    /**
228     * Access the double client property. 
229     * @param name The property key
230     * @param defaultValue The value to return if the property is not known
231     */
232    public final double getClientProperty(String name, double defaultValue) {
233       return this.msgQosData.getClientProperty(name, defaultValue);
234    }
235    
236    /**
237     * Access the float client property. 
238     * @param name The property key
239     * @param defaultValue The value to return if the property is not known
240     */
241    public final float getClientProperty(String name, float defaultValue) {
242       return this.msgQosData.getClientProperty(name, defaultValue);
243    }
244    
245    /**
246     * Access the byte client property. 
247     * @param name The property key
248     * @param defaultValue The value to return if the property is not known
249     */
250    public final byte getClientProperty(String name, byte defaultValue) {
251       return this.msgQosData.getClientProperty(name, defaultValue);
252    }
253    
254    /**
255     * Access the byte[] client property. 
256     * @param name The property key
257     * @param defaultValue The value to return if the property is not known
258     */
259    public final byte[] getClientProperty(String name, byte[] defaultValue) {
260       return this.msgQosData.getClientProperty(name, defaultValue);
261    }
262    
263    /**
264     * Access the long client property. 
265     * @param name The property key
266     * @param defaultValue The value to return if the property is not known
267     */
268    public final long getClientProperty(String name, long defaultValue) {
269       return this.msgQosData.getClientProperty(name, defaultValue);
270    }
271    
272    /**
273     * Access the short client property. 
274     * @param name The property key
275     * @param defaultValue The value to return if the property is not known
276     */
277    public final short getClientProperty(String name, short defaultValue) {
278       return this.msgQosData.getClientProperty(name, defaultValue);
279    }
280    
281    /**
282     * Dump state of this object into a XML ASCII string.
283     * <br>
284     * @return internal state of the RequestBroker as a XML ASCII string
285     */
286    public String toXml() {
287       return toXml((String)null);
288    }
289 
290    /**
291     * Dump state of this object into a XML ASCII string.
292     * <br>
293     * @param extraOffset indenting of tags for nice output
294     * @return internal state of the RequestBroker as a XML ASCII string
295     */
296    public String toXml(String extraOffset) {
297       return this.msgQosData.toXml(extraOffset);
298    }
299 
300    public String toString() {
301       return toXml(null);
302    }
303 }


syntax highlighted by Code2HTML, v. 0.9.1