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