1 /*------------------------------------------------------------------------------
  2 Name:      MsgQueueEraseEntry.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.EraseKey;
  9 import org.xmlBlaster.client.qos.EraseQos;
 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 erase() message into an entry for a sorted queue.
 23  * @author xmlBlaster@marcelruff.info
 24  */
 25 public final class MsgQueueEraseEntry extends MsgQueueEntry
 26 {
 27    private static final long serialVersionUID = 3720551167058323026L;
 28    private final EraseQos eraseQos;
 29    private final EraseKey eraseKey;
 30    private SessionName receiver;
 31    private final long immutableSizeInBytes;
 32 
 33    /**
 34     * Use this constructor if a new message object is fed by method erase(). 
 35     * <p />
 36     */
 37    public MsgQueueEraseEntry(Global glob, StorageId storageId, 
 38                                  EraseKey eraseKey, EraseQos eraseQos)
 39          throws XmlBlasterException {
 40       super(glob, MethodName.ERASE, PriorityEnum.MIN_PRIORITY, storageId, eraseQos.getData().isPersistent());
 41       this.eraseQos = eraseQos;
 42       this.eraseKey = eraseKey;
 43       /*  TODO: This check to be done only when in POLLING mode !!!!
 44       if (!eraseKey.isQuery()) {
 45          throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Only erase request with exact topic oid are supported in fail safe mode");
 46       }
 47       */
 48       this.immutableSizeInBytes = 567 + this.eraseQos.getData().size() + this.eraseKey.getData().size();
 49    }
 50 
 51    /**
 52     * For persistence recovery
 53     */
 54    public MsgQueueEraseEntry(Global glob, PriorityEnum priority, StorageId storageId,
 55                                 Timestamp timestamp, long sizeInBytes,
 56                                 EraseKey eraseKey, EraseQos eraseQos) {
 57       super(glob, MethodName.ERASE.toString(), priority,
 58             timestamp, storageId,
 59             (eraseQos == null) ? false : eraseQos.getData().isPersistent());
 60       this.eraseQos = (eraseQos == null) ? new EraseQos(glob) : eraseQos;
 61       this.eraseKey = eraseKey;
 62       this.immutableSizeInBytes = sizeInBytes;
 63    }
 64 
 65    /**
 66     * @see MsgQueueEntry#isExpired
 67     */
 68    public boolean isExpired() {
 69       return false;
 70    }
 71 
 72    /**
 73     * @see MsgQueueEntry#isDestroyed
 74     */
 75    public boolean isDestroyed() {
 76       return false;
 77    }
 78 
 79    public EraseQos getEraseQos() {
 80       return this.eraseQos;
 81    }
 82 
 83    public EraseKey getEraseKey() {
 84       return this.eraseKey;
 85    }
 86 
 87    public MsgUnit getMsgUnit() {
 88       return new MsgUnit(getEraseKey().getData(), null, getEraseQos().getData());
 89    }
 90 
 91    /**
 92     * Access the unique login name of the eraser. 
 93     * @return loginName of the source
 94     * @see MsgQueueEntry#getSender()
 95     */
 96    public SessionName getSender() {
 97       return null;
 98    }
 99 
100    /**
101     * @return The name of the receiver (data sink) or null
102     * @see MsgQueueEntry#getReceiver()
103     */
104    public void setReceiver(SessionName receiver) {
105       this.receiver = receiver;
106    }
107 
108    /**
109     * @return The name of the receiver (data sink) or null
110     * @see MsgQueueEntry#getReceiver()
111     */
112    public SessionName getReceiver() {
113       return this.receiver;
114    }
115 
116    /**
117     * @see MsgQueueEntry#getKeyOid()
118     */
119    public String getKeyOid() {
120       return null;
121    }
122 
123    /**
124     * return null
125     */
126    public Timestamp getRcvTimestamp() {
127       return null;
128    }
129 
130    /**
131     * The embeddded object for this implementing class is an Object[2] where
132     * Object[0] = qos.toXml()
133     * Object[1] = key.toXml()
134     */
135    public Object getEmbeddedObject() {
136       Object[] obj = { this.eraseQos.toXml(), this.eraseKey.toXml() };
137       return obj;
138    }
139 
140    public long getSizeInBytes() {
141       return this.immutableSizeInBytes;
142    }
143 
144    /**
145     * @return true
146     */
147    public boolean isInternal() {
148       return true;
149    }
150 
151    public final void embeddedObjectToXml(java.io.OutputStream out, java.util.Properties props) throws java.io.IOException {
152       out.write(this.eraseKey.toXml().getBytes());
153       out.write(this.eraseQos.toXml(props).getBytes());
154    }
155 
156    /**
157     * Returns a shallow clone
158     */
159    public Object clone() {
160       MsgQueueEraseEntry entry = null;
161       entry = (MsgQueueEraseEntry)super.clone();
162       return entry;
163    }
164 }


syntax highlighted by Code2HTML, v. 0.9.1