Пример #1
0
        private byte[] bodyRaw;                     // The serialized message body (or null)

        /// <summary>
        /// Constructs an empty message with a unique ID.
        /// </summary>
        public QueuedMsg()
        {
            this.id         = Helper.NewGuid();
            this.expireTime = DateTime.MinValue;
            this.flags      = MsgQueueFlag.None;
            this.priority   = DeliveryPriority.Normal;
            this.body       = null;
            this.bodyRaw    = null;
        }
Пример #2
0
        private QueuedMsgInfo GetMsgInfo(DeliveryPriority priority, int value)
        {
            QueuedMsgInfo msgInfo = new QueuedMsgInfo(null);

            msgInfo.ID           = Helper.NewGuid();
            msgInfo.Priority     = priority;
            msgInfo.ProviderData = value;

            return(msgInfo);
        }
Пример #3
0
 /// <summary>
 /// Initializes the record with information from a <see cref="QueuedMsg" />
 /// and sets default values for all remaining fields.
 /// </summary>
 /// <param name="persistID">
 /// The <see cref="IMsgQueueStore" /> specific ID used to identify and
 /// locate the message.
 /// </param>
 /// <param name="msg">The message</param>
 public QueuedMsgInfo(object persistID, QueuedMsg msg)
 {
     this.PersistID        = persistID;
     this.ID               = msg.ID;
     this.SessionID        = msg.SessionID;
     this.TargetEP         = msg.TargetEP;
     this.ResponseEP       = msg.ResponseEP;
     this.Priority         = msg.Priority;
     this.Flags            = msg.Flags;
     this.SendTime         = msg.SendTime;
     this.ExpireTime       = msg.ExpireTime;
     this.DeliveryTime     = DateTime.MinValue;
     this.BodySize         = msg.BodyRaw.Length;
     this.DeliveryAttempts = 0;
     this.LockID           = Guid.Empty;
     this.ProviderData     = null;
 }
Пример #4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="persistID">
 /// The <see cref="IMsgQueueStore" /> specific ID used to identify and
 /// locate the message.
 /// </param>
 /// <param name="targetEP">The message's target queue <see cref="MsgEP" />.</param>
 public QueuedMsgInfo(object persistID, MsgEP targetEP)
 {
     this.PersistID        = persistID;
     this.ID               =
         this.SessionID    = Guid.Empty;
     this.TargetEP         = targetEP;
     this.ResponseEP       = null;
     this.Priority         = DeliveryPriority.Normal;
     this.Flags            = MsgQueueFlag.None;
     this.SendTime         = DateTime.UtcNow;
     this.ExpireTime       = DateTime.MaxValue;
     this.DeliveryTime     = DateTime.MinValue;
     this.BodySize         = 0;
     this.DeliveryAttempts = 0;
     this.LockID           = Guid.Empty;
     this.ProviderData     = null;
 }
Пример #5
0
        /// <summary>
        /// Updates a message's priority.
        /// </summary>
        /// <param name="persistID">The provider specific ID of the message.</param>
        /// <param name="priority">The new priority value.</param>
        public void SetPriority(object persistID, DeliveryPriority priority)
        {
            using (TimedLock.Lock(this))
            {
                if (messages == null)
                {
                    throw new ObjectDisposedException(this.GetType().Name);
                }

                Guid          msgID = (Guid)persistID;
                QueuedMsgInfo msgInfo;

                if (messages.TryGetValue(msgID, out msgInfo))
                {
                    msgInfo.Priority = priority;
                    WriteMessageMetadata((string)msgInfo.ProviderData, msgInfo);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Parses the metadata from a <see cref="ArgCollection" /> formatted string
        /// generated by a previous <see cref="ToString" /> call.
        /// </summary>
        /// <param name="input">The input string.</param>
        /// <remarks>
        /// <note>
        /// This method does not initialize the <see cref="PersistID" /> and
        /// <see cref="ProviderData" /> properties.
        /// </note>
        /// </remarks>
        public QueuedMsgInfo(string input)
        {
            var args = ArgCollection.Parse(input, '=', '\t');

            this.PersistID        = null;
            this.ID               = args.Get("ID", Guid.Empty);
            this.SessionID        = args.Get("SessionID", Guid.Empty);
            this.TargetEP         = args.Get("TargetEP");
            this.ResponseEP       = args.Get("ResponseEP");
            this.Priority         = args.Get <DeliveryPriority>("Priority", DeliveryPriority.Normal);
            this.Flags            = (MsgQueueFlag)args.Get("Flags", 0);
            this.SendTime         = args.Get("SendTime", DateTime.MinValue);
            this.ExpireTime       = args.Get("ExpireTime", DateTime.MaxValue);
            this.DeliveryTime     = args.Get("DeliveryTime", DateTime.MinValue);
            this.BodySize         = args.Get("BodySize", 0);
            this.DeliveryAttempts = args.Get("DeliveryAttempts", 0);
            this.LockID           = args.Get("LockID", Guid.Empty);
            this.ProviderData     = null;
        }
Пример #7
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="msgInfo">A <see cref="QueuedMsgInfo" /> instance with the header information.</param>
        /// <param name="bodyRaw">The raw message body.</param>
        /// <param name="deserialize">
        /// Pass <c>true</c> to deserialize the message body, <c>false</c> to limit
        /// deserialization to the message headers.
        /// </param>
        /// <remarks>
        /// <note>
        /// This constructor is provided for applications that need to implement
        /// a custom <see cref="IMsgQueueStore" />.
        /// </note>
        /// </remarks>
        public QueuedMsg(QueuedMsgInfo msgInfo, byte[] bodyRaw, bool deserialize)
        {
            this.id         = msgInfo.ID;
            this.targetEP   = msgInfo.TargetEP;
            this.responseEP = msgInfo.ResponseEP;
            this.sessionID  = msgInfo.SessionID;
            this.sendTime   = msgInfo.SendTime;
            this.expireTime = msgInfo.ExpireTime;
            this.flags      = msgInfo.Flags;
            this.priority   = msgInfo.Priority;
            this.bodyRaw    = bodyRaw;

            if (deserialize)
            {
                body = Serialize.FromBinary(bodyRaw);
            }
            else
            {
                body = null;
            }
        }
Пример #8
0
        /// <summary>
        /// Extracts the message headers from a <see cref="ArgCollection" />
        /// encoded string.
        /// </summary>
        /// <param name="headers">The encoded headers.</param>
        private void ParseHeaders(string headers)
        {
            var    args = ArgCollection.Parse(headers, '=', '\t');
            string v;

            this.id         = args.Get("id", Guid.Empty);
            this.sessionID  = args.Get("session-id", Guid.Empty);
            this.sendTime   = args.Get("send-time", DateTime.MinValue);
            this.expireTime = args.Get("expire-time", DateTime.MinValue);
            this.flags      = (MsgQueueFlag)args.Get("flags", 0);
            this.priority   = (DeliveryPriority)args.Get("priority", (int)DeliveryPriority.Normal);

            v = args.Get("target-ep");
            if (v == null)
            {
                this.targetEP = null;
            }
            else
            {
                this.targetEP = MsgEP.Parse(v);
                if (!targetEP.IsLogical)
                {
                    throw new ArgumentException("TargetEP must be logical.");
                }
            }

            v = args.Get("response-ep");
            if (v == null)
            {
                this.responseEP = null;
            }
            else
            {
                this.responseEP = MsgEP.Parse(v);
                if (!responseEP.IsLogical)
                {
                    throw new ArgumentException("ResponseEP must be logical.");
                }
            }
        }
Пример #9
0
 /// <summary>
 /// Constructs a prioritized message from a body object instance.
 /// </summary>
 /// <param name="priority">The message <see cref="DeliveryPriority" />.</param>
 /// <param name="body">The message body object.</param>
 public QueuedMsg(DeliveryPriority priority, object body)
     : this()
 {
     this.priority = priority;
     this.body     = body;
 }
Пример #10
0
 internal ChannelDataEventArgs(ContentType ctype,
                               byte[] payload,
                               DeliveryPriority prio)
     : base(ctype, payload)
 {
     _priority = prio;
 }
Пример #11
0
 internal static Frame Create(uint ptr,
                              DeliveryPriority prio,
                              ContentType ctype,
                              byte[] payload)
 {
     return new Frame(ptr, OpCode.Data, (byte)prio, ctype, payload);
 }
Пример #12
0
        void Send(ContentType ctype, byte[] buffer, DeliveryPriority prio)
        {
            if (_state != ChannelState.Open) {
                throw new InvalidOperationException("Channel is not open");
            }

            if (Writable == false) {
                throw new InvalidOperationException("Channel is not writable");
            }

            if (buffer == null) {
                throw new ArgumentNullException("buffer", "Cannot be null");
            }

            if (buffer.Length > Frame.PayloadMaxSize) {
                throw new ArgumentException("buffer", "Data buffer is to large");
            }

            Frame frame = Frame.Create(_ptr, prio, ctype, buffer);
            _connection.Send(frame);
        }
Пример #13
0
        /// <summary>
        /// Sends binary data to this channel instance, with specified
        /// priority.
        /// </summary>
        /// <param name="buffer">A Byte array that supplies the bytes to be
        /// written to the channel.</param>
        /// <param name="offset">The zero-based location in buffer at which to
        /// begin reading bytes to be written to the channel.</param>
        /// <param name="count">A value that specifies the number of bytes to
        /// read from buffer.</param>
        /// <param name="priority">The priority of this message</param>
        public void Send(byte[] buffer,
                         int offset,
                         int count,
                         DeliveryPriority prio)
        {
            if (offset < 0 || offset + count > buffer.Length) {
                throw new ArgumentException("Index out of bounds");
            }

            byte[] clone = new byte[count - offset];
            Buffer.BlockCopy(buffer, offset, clone, 0, count);

            Send(ContentType.Binary, clone, prio);
        }
Пример #14
0
 /// <summary>
 /// Sends binary data to this channel instance, with specified
 /// priority.
 /// </summary>
 /// <param name="buffer">A Byte array that supplies the bytes to be
 /// written to the channel.</param>
 /// <param name="priority">The priority of this message</param>
 public void Send(byte[] buffer, DeliveryPriority prio)
 {
     Send(ContentType.Binary, buffer, prio);
 }
Пример #15
0
        /// <summary>
        /// Sends an UTF8 encoded string to this channel instance, with
        /// specified priority.
        /// </summary>
        /// <param name="data">The <c>string</c> that should be sent</param>
        /// <param name="priority">The priority of this message</param>
        public void Send(string data, DeliveryPriority prio)
        {
            if (data == null) {
                throw new ArgumentNullException("data", "Cannot be null");
            }

            byte[] buffer = Encoding.UTF8.GetBytes(data);
            Send(ContentType.Utf, buffer, prio);
        }