Пример #1
0
		private void SetConfig(QueueConfig config)
		{
			if (config != null)
			{
				if (!config.Enabled)
					_enabled = false;

				_itemsPerDequeue = config.ItemsPerDequeue;
				_maxCount = config.MaxCount;

				_persistence = ErrorQueuePersistence.Initialize(config.PersistenceFolder, _nodeName, _itemsPerDequeue,
				                                                config.PersistenceFileSize, config.MaxPersistedMB,
				                                                DequeueAllMessages, ProbeMessages);

				if (config.Enabled)
					_enabled = true;
			}
		}
Пример #2
0
		/// <summary>
		/// Populates this error queue from the messages stored in a previous instance of the error queue.
		/// </summary>
		/// <remarks>
		/// <para>
		/// When an AppDomain restart occurs the error queues are serialized into the Forwarding component's
		/// RunState.  Upon restart they are deserialized and all messages from the memory queue from the old
		/// AppDomain are copied into the error queues for the new AppDomain.
		/// </para>
		/// <para>
		/// If persistent error queues are enabled then the memory queues will normally be empty as they are
		/// flushed to perisistent storage before serializing the error queues.
		/// </para>
		/// </remarks>
		/// <param name="errorQueue">The original error queue.</param>
		/// <param name="incrementCounters">if set to <see langword="true"/> the performance counter for messages
		/// in the error queue will be incremented by the number of messages in the source error queue.</param>
		internal void Populate(ErrorQueue errorQueue, bool incrementCounters)
		{
			if (errorQueue.InMessageQueueCount == 0) return;

			if (_persistence != null && !_persistence.CreateSpillFolder())
				_persistence = null;

			lock (_inMessageQueueLock)
			{
				SerializedRelayMessage[] curMessages = null;
				if (InMessageQueue.Count > 0)
				{
					curMessages = InMessageQueue.ToArray();
					InMessageQueue.Clear();
				}

				foreach (var message in errorQueue.InMessageQueue)
				{
					InMessageQueue.Enqueue(message);
				}

				if (curMessages != null)
				{
					foreach (var message in curMessages)
					{
						InMessageQueue.Enqueue(message);
					}
				}
			}

			if (incrementCounters)
			{
				NodeManager.Instance.Counters.IncrementErrorQueueBy(errorQueue.InMessageQueue.Count);
			}

			StartSpill();
		}
Пример #3
0
        /// <summary>
        /// Initializes persistent error queues.
        /// </summary>
        /// <param name="rootFolder">The root folder for persistent error queue storage.</param>
        /// <param name="nodeName">Name of the node.  Used as a sub-folder name, for this node, under rootFolder.</param>
        /// <param name="itemsPerFile">The number of messages per file.</param>
        /// <param name="maxFileSize">The maximum file size in bytes.</param>
        /// <param name="globalMaxMb">The maximum aggregate files sizes in MB.  Zero is unlimited.</param>
        /// <param name="getMessages">A delegate that will be called to retrieve messages from the <see cref="ErrorQueue"/>.</param>
        /// <param name="probeMessages">A delegate that will be called to determine if the <see cref="ErrorQueue"/> has any
        /// messages waiting to be persisted.</param>
        /// <returns>An <see cref="ErrorQueuePersistence"/> object if persistence is enabled.  Returns <see langword="null"/>
        /// if persistence is disabled or the storage folder is inaccessable.</returns>
        public static ErrorQueuePersistence Initialize(
            string rootFolder,
            string nodeName,
            int itemsPerFile,
            int maxFileSize,
            int globalMaxMb,
            Func <SerializedRelayMessage[]> getMessages,
            Func <bool> probeMessages)
        {
            if (string.IsNullOrEmpty(rootFolder))
            {
                return(null);
            }

            if (nodeName == null)
            {
                throw new ArgumentNullException("nodeName");
            }
            if (nodeName == string.Empty)
            {
                throw new ArgumentException("Node name may not be empty.", "nodeName");
            }
            if (itemsPerFile <= 0)
            {
                throw new ArgumentException("Items per file must be greater than zero.", "itemsPerFile");
            }
            if (maxFileSize <= 0)
            {
                throw new ArgumentException("Max file size must be greater than zero.", "maxFileSize");
            }
            if (globalMaxMb < 0)
            {
                throw new ArgumentException("Global Max MB must be non-negative", "globalMaxMB");
            }
            if (getMessages == null)
            {
                throw new ArgumentNullException("getMessages");
            }
            if (probeMessages == null)
            {
                throw new ArgumentNullException("probeMessages");
            }

            try
            {
                var spillFolder = Path.Combine(rootFolder, nodeName);

                var peristence = new ErrorQueuePersistence(spillFolder, nodeName, itemsPerFile, maxFileSize, getMessages, probeMessages);

                GlobalMaxBytes = globalMaxMb > 0 ? globalMaxMb * 1024L * 1024L : long.MaxValue;

                _log.DebugFormat("Persistent Error Queue Enabled for {0}:  itemsPerFile={1}, maxFileSize={2}, maxTotalBytes={3}",
                                 nodeName, itemsPerFile, maxFileSize, GlobalMaxBytes);

                return(peristence);
            }
            catch (Exception e)
            {
                _log.Error("Exception initializing " + nodeName, e);
                return(null);
            }
        }