Beispiel #1
0
        /// <summary>
        /// Publishes the messages.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="deliverOption"></param>
        /// <param name="notifyDeliveryFailure"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void Publish(Message message, DeliveryOption deliverOption, bool notifyDeliveryFailure = false)
        {
            if (TopicSearchOptions.ByName != _searchOptions)
            {
                throw new OperationFailedException(ErrorCodes.PubSub.PATTERN_BASED_PUBLISHING_NOT_ALLOWED, ErrorMessages.GetErrorMessage(ErrorCodes.PubSub.PATTERN_BASED_PUBLISHING_NOT_ALLOWED));
            }
            try
            {
                _readerWriterLock.AcquireReaderLock(Timeout.Infinite);

                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }
                if (_isDisposed)
                {
                    throw new OperationFailedException(ErrorCodes.PubSub.TOPIC_DISPOSED, ErrorMessages.GetErrorMessage(ErrorCodes.PubSub.TOPIC_DISPOSED, Name));
                }

                UsageStats stats = new UsageStats();
                stats.BeginSample();
                BitSet flagMap = new BitSet();
                long   size    = 0;
                object value   = message.Payload;


                value = _cacheImpl.SafeSerialize(value, _cacheImpl.Name, ref flagMap, _cacheImpl, ref size, UserObjectType.CacheItem);


                if (_perfStatsCollector != null && value != null && value is byte[])
                {
                    _perfStatsCollector.IncrementAvgItemSize(((byte[])value).Length);
                }

                Hashtable metaInfo = new Hashtable();
                metaInfo.Add(TopicConstant.TopicName, TopicConstant.TopicTag + _topicName);
                metaInfo.Add(TopicConstant.DeliveryOption, ((int)deliverOption).ToString());
                metaInfo.Add(TopicConstant.NotifyOption, notifyDeliveryFailure.ToString());

                long expiration = GetExpirationTime(message);

                _cacheImpl.PublishMessage(message.MessageId, value, message.CreationTime.Ticks, expiration, metaInfo, flagMap);

                if (_perfStatsCollector != null)
                {
                    stats.EndSample();
                    _perfStatsCollector.IncrementMsecPerMessagePublish(stats.Current);
                    _perfStatsCollector.IncrementMessagePublishedPerSec();
                }
            }
            finally
            {
                _readerWriterLock.ReleaseReaderLock();
            }
        }