示例#1
0
        protected override void OnMessageReceived(object sender, RedisMessageEventArgs e)
        {
            Trace.WriteLine("ENTER: Receiving message '{0}' on channel '{1}' ...".FormatInvariant(e.Message, e.Channel));

            switch (e.Channel)
            {
            case RedisTaskProcessorChannels.PerformanceMonitoringChannel:
                this.RaiseEventFromMessage <PerformanceMonitoringEventArgs, TimeSpan>(e, this.PerformanceMonitoringRequested, refreshInterval => new PerformanceMonitoringEventArgs(refreshInterval));
                break;

            case RedisTaskProcessorChannels.StopTaskProcessorChannel:
                this.RaiseEventFromMessage <TaskProcessorEventArgs, Guid>(e, this.StopRequested, taskProcessorId => new TaskProcessorEventArgs(taskProcessorId));
                break;

            case RedisTaskProcessorChannels.MasterModeChangeRequestChannel:
                this.RaiseEventFromMessage <MasterModeChangeEventArgs, Guid, bool>(e, this.MasterModeChangeRequested, (taskProcessorId, isMaster) => new MasterModeChangeEventArgs(taskProcessorId, isMaster, MasterModeChangeReason.Explicit));
                break;

            case RedisTaskProcessorChannels.MasterModeChangedChannel:
                this.RaiseEventFromMessage <MasterModeChangeEventArgs, Guid, bool, MasterModeChangeReason>(e, this.MasterModeChanged, (taskProcessorId, isMaster, reason) => new MasterModeChangeEventArgs(taskProcessorId, isMaster, reason));
                break;

            case RedisTaskProcessorChannels.ConfigurationChangedChannel:
                this.RaiseEventFromMessage <TaskProcessorEventArgs, Guid>(e, this.ConfigurationChanged, taskProcessorId => new TaskProcessorEventArgs(taskProcessorId));
                break;

            default:
                Trace.TraceWarning("EXIT: Message '{0}' received on unknown channel '{1}'.".FormatInvariant(e.Message, e.Channel));
                return;
            }

            Trace.WriteLine("EXIT: Message '{0}' received on channel '{1}'.".FormatInvariant(e.Message, e.Channel));
        }
示例#2
0
        protected override void OnMessageReceived(object sender, RedisMessageEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            switch (e.Channel)
            {
            case RedisMonitoringMessageBusChannels.TaskRequestedChannel:
                this.RaiseEventFromMessage <TaskEventArgs, Guid>(e, this.TaskSubmitted, taskId => new TaskEventArgs(taskId));
                break;

            case RedisMonitoringMessageBusChannels.TaskProgressChannel:
                this.RaiseEventFromMessage <TaskProgressEventArgs, Guid, double>(e, this.TaskProgress, (taskId, percentage) => new TaskProgressEventArgs(taskId, percentage));
                break;

            case RedisMonitoringMessageBusChannels.TaskCancelCompletedChannel:
                this.RaiseEventFromMessage <TaskEventEventArgs, Guid, DateTime>(e, this.TaskCancelCompleted, (taskId, timestampUtc) => new TaskEventEventArgs(taskId, timestampUtc));
                break;

            case RedisMonitoringMessageBusChannels.TaskFailedChannel:
                this.RaiseEventFromMessage <TaskEventEventArgs, Guid, DateTime>(e, this.TaskFailed, (taskId, timestampUtc) => new TaskEventEventArgs(taskId, timestampUtc));
                break;

            case RedisMonitoringMessageBusChannels.TaskCompletedChannel:
                this.RaiseEventFromMessage <TaskCompletedEventArgs, Guid, DateTime, TimeSpan>(e, this.TaskCompleted, (taskId, timestampUtc, totalCpuTime) => new TaskCompletedEventArgs(taskId, timestampUtc, totalCpuTime));
                break;
            }
        }
示例#3
0
        protected override void OnMessageReceived(object sender, RedisMessageEventArgs e)
        {
            Trace.WriteLine("ENTER: Receiving message '{0}' on channel '{1}' ...".FormatInvariant(e.Message, e.Channel));

            switch (e.Channel)
            {
            case RedisTaskProcessorChannels.TaskAssignedChannel:
                this.RaiseEventFromMessage <TaskAssignedEventArgs, Guid, Guid>(e, this.TaskAssigned, (taskProcessorId, taskId) => new TaskAssignedEventArgs(taskId, taskProcessorId));
                break;

            case RedisTaskProcessorChannels.TaskStartedChannel:
                this.RaiseEventFromMessage <TaskStartedEventArgs, Guid, Guid, DateTime>(e, this.TaskStarted, (taskId, taskProcessorId, timestampUtc) => new TaskStartedEventArgs(taskId, taskProcessorId, timestampUtc));
                break;

            case RedisTaskProcessorChannels.TaskCanceledChannel:
                this.RaiseEventFromMessage <TaskEventEventArgs, Guid, DateTime, object>(e, this.TaskCancelRequested, (taskId, timestampUtc, v3) => new TaskEventEventArgs(taskId, timestampUtc));
                break;

            default:
                Trace.TraceWarning("EXIT: Message '{0}' received on unknown channel '{1}'.".FormatInvariant(e.Message, e.Channel));
                return;
            }

            Trace.WriteLine("EXIT: Message '{0}' received on channel '{1}'.".FormatInvariant(e.Message, e.Channel));
        }
        private void OnMessageReceived(object sender, RedisMessageEventArgs e)
        {
            switch (e.Channel)
            {
            case RedisScheduledTaskRepository.Channel:
                string[] data = RedisConverter.ParseCollection <string>(e.Message).ToArray();

                if (data.Length != 2)
                {
                    Trace.TraceWarning("Message '{0}' received on channel '{1}' cannot be parsed.", e.Message, e.Channel);

                    return;
                }

                Guid scheduledTaskId;

                try
                {
                    scheduledTaskId = RedisConverter.ParseGuid(data[1]);
                }
                catch (ArgumentException ex)
                {
                    Trace.TraceWarning(ex.Message);

                    return;
                }

                EventHandler <ScheduledTaskEventArgs> handler = null;

                switch (data[0])
                {
                case "Add":
                    handler = this.Added;
                    break;

                case "Update":
                    handler = this.Updated;
                    break;

                case "Delete":
                    handler = this.Deleted;
                    break;

                default:
                    Trace.TraceWarning("Unknown command in message '{0}' received on channel '{1}'.", e.Message, e.Channel);
                    return;
                }

                if (handler != null)
                {
                    handler(this, new ScheduledTaskEventArgs(scheduledTaskId));
                }

                break;
            }
        }
示例#5
0
        public void ReceiveMessageForSubscribedChannel()
        {
            string channel1 = RedisSubscriptionUnitTests.GetUniqueTestChannel();

            this.Subscription.SubscribeToChannels(this.subscribeTimeout, channel1);

            Assert.AreEqual(1, this.Subscription.ActiveChannels.Count());

            Assert.IsTrue(this.Subscription.ActiveChannels.Contains(channel1));

            RedisMessageEventArgs args = Helpers.WaitForEvent <RedisMessageEventArgs>(
                TimeSpan.FromSeconds(1),
                handler => this.Subscription.MessageReceived += handler,
                () => this.PublishMessage(channel1, "Hello"));

            Assert.AreEqual(channel1, args.Channel);
            Assert.AreEqual("Hello", args.Message);
        }
示例#6
0
        protected override void OnMessageReceived(object sender, RedisMessageEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            switch (e.Channel)
            {
            case RedisMonitoringMessageBusChannels.TaskProcessorStateChannel:
                this.RaiseEventFromMessage <TaskProcessorStateEventArgs, Guid, TaskProcessorState>(e, this.StateChanged, (taskProcessorId, state) => new TaskProcessorStateEventArgs(taskProcessorId, state));
                break;

            case RedisMonitoringMessageBusChannels.PerformanceReportChannel:
                this.RaiseEventFromMessage <TaskProcessorPerformanceEventArgs, string>(e, this.PerformanceReportReceived, value => new TaskProcessorPerformanceEventArgs(RedisMessageBusReceiverBase.DeserializeTaskProcessorPerformanceInfo(value)));
                break;
            }
        }
示例#7
0
        /// <summary>
        /// Raises a <see cref="ITaskProcessorMessageBus"/> event from a message received on channel.
        /// </summary>
        /// <typeparam name="TEventArgs">The type of the event arguments for the event.</typeparam>
        /// <typeparam name="T1">The type of the first argument in the message.</typeparam>
        /// <typeparam name="T2">The type of the second argument in the message.</typeparam>
        /// <typeparam name="T3">The type of the third argument in the message.</typeparam>
        /// <typeparam name="T4">The type of the forth argument in the message.</typeparam>
        /// <param name="e">The event arguments for the received message.</param>
        /// <param name="handler">The <see cref="ITaskProcessorMessageBus"/> event to be raised.</param>
        /// <param name="converter">Callback method to convert the arguments in the message to event arguments.</param>
        protected void RaiseEventFromMessage <TEventArgs, T1, T2, T3, T4>(RedisMessageEventArgs e, EventHandler <TEventArgs> handler, Func <T1, T2, T3, T4, TEventArgs> converter)
            where TEventArgs : EventArgs
        {
            if (handler == null)
            {
                return;
            }

            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            string[] values = RedisConverter.ParseCollection <string>(e.Message).ToArray();

            T1 value1;
            T2 value2;
            T3 value3;
            T4 value4;

            if (values.Length > 0)
            {
                value1 = RedisConverter.ParseValue <T1>(values[0]);
            }
            else
            {
                value1 = default(T1);
            }

            if (values.Length > 1)
            {
                value2 = RedisConverter.ParseValue <T2>(values[1]);
            }
            else
            {
                value2 = default(T2);
            }

            if (values.Length > 2)
            {
                value3 = RedisConverter.ParseValue <T3>(values[2]);
            }
            else
            {
                value3 = default(T3);
            }

            if (values.Length > 3)
            {
                value4 = RedisConverter.ParseValue <T4>(values[3]);
            }
            else
            {
                value4 = default(T4);
            }

            TEventArgs args = converter(value1, value2, value3, value4);

            ThreadPool.QueueUserWorkItem(state => handler(this, args));
        }
示例#8
0
 /// <summary>
 /// Raises a <see cref="ITaskProcessorMessageBus"/> event from a message received on channel.
 /// </summary>
 /// <typeparam name="TEventArgs">The type of the event arguments for the event.</typeparam>
 /// <typeparam name="T1">The type of the first argument in the message.</typeparam>
 /// <typeparam name="T2">The type of the second argument in the message.</typeparam>
 /// <typeparam name="T3">The type of the third argument in the message.</typeparam>
 /// <param name="e">The event arguments for the received message.</param>
 /// <param name="handler">The <see cref="ITaskProcessorMessageBus"/> event to be raised.</param>
 /// <param name="converter">Callback method to convert the arguments in the message to event arguments.</param>
 protected void RaiseEventFromMessage <TEventArgs, T1, T2, T3>(RedisMessageEventArgs e, EventHandler <TEventArgs> handler, Func <T1, T2, T3, TEventArgs> converter)
     where TEventArgs : EventArgs
 {
     this.RaiseEventFromMessage <TEventArgs, T1, T2, T3, object>(e, handler, (v1, v2, v3, v4) => converter(v1, v2, v3));
 }
示例#9
0
 /// <summary>
 /// Handles a message received on a channel by the message bus.
 /// </summary>
 /// <param name="sender">The subscription raising the event.</param>
 /// <param name="e">The event arguments.</param>
 protected abstract void OnMessageReceived(object sender, RedisMessageEventArgs e);
示例#10
0
 private void OnMessageReceived(object sender, RedisMessageEventArgs e)
 {
     ThreadPool.QueueUserWorkItem(_ => this.RaiseMessageReceived());
 }