1 /*------------------------------------------------------------------------------
2 Name: MsgQueueGetEntry.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 ------------------------------------------------------------------------------*/
6 package org.xmlBlaster.client.queuemsg;
7
8 import org.xmlBlaster.client.key.GetKey;
9 import org.xmlBlaster.client.qos.GetQos;
10 import org.xmlBlaster.util.Global;
11 import org.xmlBlaster.util.MsgUnit;
12 import org.xmlBlaster.util.SessionName;
13 import org.xmlBlaster.util.Timestamp;
14 import org.xmlBlaster.util.XmlBlasterException;
15 import org.xmlBlaster.util.def.MethodName;
16 import org.xmlBlaster.util.def.PriorityEnum;
17 import org.xmlBlaster.util.queue.StorageId;
18 import org.xmlBlaster.util.queuemsg.MsgQueueEntry;
19
20
21 /**
22 * Wraps an get() message into an entry for a sorted queue.
23 * @author xmlBlaster@marcelruff.info
24 */
25 public final class MsgQueueGetEntry extends MsgQueueEntry
26 {
27 private final static String ME = "GetQueueEntry";
28 private final GetQos getQos;
29 private final GetKey getKey;
30 private SessionName receiver;
31 private final long immutableSizeInBytes;
32
33 /**
34 * Use this constructor for a get() request.
35 * <p />
36 */
37 public MsgQueueGetEntry(Global glob, StorageId storageId,
38 GetKey getKey, GetQos getQos)
39 throws XmlBlasterException {
40 super(glob, MethodName.GET, PriorityEnum.NORM_PRIORITY, storageId, getQos.getData().isPersistent());
41 this.getQos = getQos;
42 this.getKey = getKey;
43 this.immutableSizeInBytes = 500 + this.getQos.getData().size() + this.getKey.getData().size();
44 }
45
46 /**
47 * For persistence recovery
48 */
49 public MsgQueueGetEntry(Global glob, PriorityEnum priority, StorageId storageId,
50 Timestamp timestamp, long sizeInBytes,
51 GetKey getKey, GetQos getQos) {
52 super(glob, MethodName.GET.toString(), priority,
53 timestamp, storageId,
54 (getQos == null) ? false : getQos.getData().isPersistent());
55 this.getQos = (getQos == null) ? new GetQos(glob) : getQos;
56 this.getKey = getKey;
57 this.immutableSizeInBytes = sizeInBytes;
58 }
59
60 /**
61 * @see MsgQueueEntry#isExpired
62 */
63 public boolean isExpired() {
64 return false;
65 }
66
67 /**
68 * @see MsgQueueEntry#isDestroyed
69 */
70 public boolean isDestroyed() {
71 return false;
72 }
73
74 public GetQos getGetQos() {
75 return this.getQos;
76 }
77
78 public GetKey getGetKey() {
79 return this.getKey;
80 }
81
82 public MsgUnit getMsgUnit() {
83 return new MsgUnit(getGetKey().getData(), null, getGetQos().getData());
84 }
85
86 /**
87 * Access the unique login name of the getr.
88 * @return loginName of the source
89 * @see MsgQueueEntry#getSender()
90 */
91 public SessionName getSender() {
92 return null;
93 }
94
95 /**
96 * @return The name of the receiver (data sink) or null
97 * @see MsgQueueEntry#getReceiver()
98 */
99 public void setReceiver(SessionName receiver) {
100 this.receiver = receiver;
101 }
102
103 /**
104 * @return The name of the receiver (data sink) or null
105 * @see MsgQueueEntry#getReceiver()
106 */
107 public SessionName getReceiver() {
108 return this.receiver;
109 }
110
111 /**
112 * @see MsgQueueEntry#getKeyOid()
113 */
114 public String getKeyOid() {
115 return null;
116 }
117
118 /**
119 * return null
120 */
121 public Timestamp getRcvTimestamp() {
122 return null;
123 }
124
125 /**
126 * The embeddded object for this implementing class is an Object[2] where
127 * Object[0] = qos.toXml()
128 * Object[1] = key.toXml()
129 */
130 public Object getEmbeddedObject() {
131 Object[] obj = { this.getQos.toXml(), this.getKey.toXml() };
132 return obj;
133 }
134
135 public long getSizeInBytes() {
136 return this.immutableSizeInBytes;
137 }
138
139 /**
140 * @return true
141 */
142 public boolean isInternal() {
143 return true;
144 }
145
146 public final void embeddedObjectToXml(java.io.OutputStream out, java.util.Properties props) throws java.io.IOException {
147 out.write(this.getKey.toXml().getBytes());
148 out.write(this.getQos.toXml(props).getBytes());
149 }
150
151 /**
152 * Returns a shallow clone
153 */
154 public Object clone() {
155 MsgQueueGetEntry entry = null;
156 entry = (MsgQueueGetEntry)super.clone();
157 return entry;
158 }
159 }
syntax highlighted by Code2HTML, v. 0.9.1