示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageProcessor"/> class.
        /// </summary>
        /// <param name="msgID">ID of the message to process. Must be non-zero.</param>
        /// <param name="methodDelegate">Delegate to the processing method.</param>
        /// <exception cref="ArgumentNullException"><paramref name="methodDelegate" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="msgID"/> is zero.</exception>
        public MessageProcessor(MessageProcessorID msgID, MessageProcessorHandler methodDelegate)
        {
            if (methodDelegate == null)
                throw new ArgumentNullException("methodDelegate");

            if (msgID == 0)
                throw new ArgumentOutOfRangeException("msgID", "The message ID may not be zero.");

            _msgID = msgID;
            _call = methodDelegate;
        }
        /// <summary>
        /// Updates the statistics for an <see cref="IMessageProcessor"/>.
        /// </summary>
        /// <param name="processorID">The ID of the <see cref="IMessageProcessor"/>.</param>
        /// <param name="bits">The number of bits read or written. Does not include the message ID.</param>
        public void HandleProcessorInvoked(MessageProcessorID processorID, int bits)
        {
            var ubits = (ushort)bits;

            // Check the bitsRead range
            if (bits < 0)
            {
                const string errmsg = "Invalid bitsRead value `{0}`.";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, bits);
                return;
            }

            if (bits < 0)
            {
                const string errmsg =
                    "Invalid bitsRead value `{0}` - value was too large to handle. Will use the largest possible value instead ({1}).";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, bits, ushort.MaxValue);
                ubits = ushort.MaxValue;
            }

            // Grab the stats
            ProcStats stats;
            lock (_statsSync)
            {
                if (!_stats.TryGetValue(processorID, out stats))
                {
                    stats = new ProcStats(processorID);
                    _stats[processorID] = stats;
                }
            }

            // Update the stats
            stats.NotifyCalled(ubits);

            // Check to dump the output
            if (_outFilePath != null && _nextDumpTime <= TickCount.Now)
            {
                _nextDumpTime = (TickCount)(TickCount.Now + _outDumpRate);
                Write(_outFilePath);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProcStats"/> class.
 /// </summary>
 /// <param name="id">The <see cref="IMessageProcessor"/> ID.</param>
 public ProcStats(MessageProcessorID id)
 {
     _id = id;
 }
 /// <summary>
 /// Gets the <see cref="IMessageProcessorStats"/> for a <see cref="IMessageProcessor"/> identified by the ID.
 /// </summary>
 /// <param name="msgID">The ID of the <see cref="IMessageProcessor"/> to get the stats for.</param>
 /// <returns>The <see cref="IMessageProcessorStats"/> for the given <paramref name="msgID"/>, or null if no
 /// stats exist for the given <paramref name="msgID"/>.</returns>
 public IMessageProcessorStats GetStats(MessageProcessorID msgID)
 {
     return _stats[msgID];
 }
 /// <summary>
 /// Gets the <see cref="IMessageProcessor"/> for the corresponding message ID. Can be overridden by the derived class to allow
 /// for using a <see cref="IMessageProcessor"/> other than what is acquired by
 /// <see cref="MessageProcessorManager.GetInternalMessageProcessor"/>.
 /// </summary>
 /// <param name="msgID">The ID of the message.</param>
 /// <returns>The <see cref="IMessageProcessor"/> for the <paramref name="msgID"/>, or null if an invalid ID.</returns>
 protected virtual IMessageProcessor GetMessageProcessor(MessageProcessorID msgID)
 {
     return GetInternalMessageProcessor(msgID);
 }
 /// <summary>
 /// Gets the <see cref="IMessageProcessor"/> with the given ID. This will only ever return the <see cref="IMessageProcessor"/>
 /// for the method that was specified using a <see cref="MessageHandlerAttribute"/>. Is intended to only be used by
 /// <see cref="MessageProcessorManager.GetMessageProcessor"/> to allow for access of the <see cref="IMessageProcessor"/>s loaded
 /// through the attribute.
 /// </summary>
 /// <param name="msgID">The ID of the message.</param>
 /// <returns>The <see cref="IMessageProcessor"/> for the <paramref name="msgID"/>, or null if an invalid ID.</returns>
 protected IMessageProcessor GetInternalMessageProcessor(MessageProcessorID msgID)
 {
     return _processors[msgID];
 }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageHandlerAttribute"/> class.
 /// </summary>
 /// <param name="msgID">The ID of the message that the method this attribute is attached to will handle.</param>
 public MessageHandlerAttribute(MessageProcessorID msgID)
 {
     _msgID = msgID;
 }
 /// <summary>
 /// Gets the <see cref="IMessageProcessor"/> with the given ID. This will only ever return the <see cref="IMessageProcessor"/>
 /// for the method that was specified using a <see cref="MessageHandlerAttribute"/>. Is intended to only be used by
 /// <see cref="MessageProcessorManager.GetMessageProcessor"/> to allow for access of the <see cref="IMessageProcessor"/>s loaded
 /// through the attribute.
 /// </summary>
 /// <param name="msgID">The ID of the message.</param>
 /// <returns>The <see cref="IMessageProcessor"/> for the <paramref name="msgID"/>, or null if an invalid ID.</returns>
 protected IMessageProcessor GetInternalMessageProcessor(MessageProcessorID msgID)
 {
     return _processors[msgID.GetRawValue()];
 }