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


syntax highlighted by Code2HTML, v. 0.9.1