Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the ResponseCallbackItem class.
        /// </summary>
        /// <param name="callback">the response callback.</param>
        /// <param name="filter">the filter for the responses.</param>
        /// <param name="expectResponseCount">the expected responses count that should returned through this callback.</param>
        /// <param name="callbackState">the callback state object.</param>
        /// <param name="needRemove">a value indicating whether need remove the fetched responses.</param>
        public ResponseCallbackItem(BrokerQueueCallback callback, MessageVersion messageVersion, ResponseActionFilter filter, long expectResponseCount, object callbackState)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            this.responsesCallbackField      = callback;
            this.messageVersionField         = messageVersion;
            this.responseFilterField         = filter;
            this.expectedResponsesCountField = expectResponseCount;
            this.callbackStateField          = callbackState;
        }
Ejemplo n.º 2
0
        public void GetRequestAsync(BrokerQueueCallback requestCallback, object state)
        {
            ParamCheckUtility.ThrowIfNull(requestCallback, "requestCallback");
            bool isCallbackHandled = false;

            if (this.requestCacheQueue.Count > 0)
            {
                BrokerQueueItem request = null;

                if (!this.requestCacheQueue.TryDequeue(out request))
                {
                    BrokerTracing.TraceInfo("[BrokerQueueDispatcher] .GetRequestAsync: All cached requests are dispatched.");
                }

                if (request != null)
                {
                    try
                    {
#if DEBUG
                        BrokerTracing.TraceVerbose("[BrokerQueueDispatcher] .GetRequestAsync: handle request callback from cache queue. request id={0}", GetMessageId(request));
#endif

                        this.RegisterReemit(request);

                        isCallbackHandled = true;
                        requestCallback(request, state);
                    }
                    catch (Exception e)
                    {
                        this.requestCacheQueue.Enqueue(request);

                        // request callback raise exception.
                        BrokerTracing.TraceWarning("[BrokerQueueDispatcher] .GetRequestAsync: The request callback raise exception. Exception: {0}", e);
                    }
                }
            }

            if (this.requestCacheQueue.Count <= this.watermarkerForTriggerPrefetch)
            {
                BrokerTracing.TraceVerbose("[BrokerQueueDispatcher] .GetRequestAsync (perf): Trigger prefetch because the count of cached items is below threshold. state={0}", (int)state);
                this.TriggerPrefetch();
            }

            if (!isCallbackHandled)
            {
                this.requestCallbackQueue.Enqueue(new BrokerQueueCallbackItem(requestCallback, state));

                // in case the last request come in the cache queue right before the request callback enqueue.
                this.HandlePendingRequestCallback();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// register a response call back to get the response message.
 /// </summary>
 /// <param name="responseCallback">the response callback, the async result should be the BrokerQueueItem</param>
 /// <param name="messageVersion">the message version for the response message. if failed to pull the response from the storage, will use this version to create a fault message.</param>
 /// <param name="filter">the filter for the responses that the response callback expected.</param>
 /// <param name="responseCount">the responses count this registered response callback want to get.</param>
 /// <param name="state">the state object for the callback</param>
 /// <returns>a value indicating whether the response callback is registered sucessfully.</returns>
 public abstract bool RegisterResponsesCallback(BrokerQueueCallback responseCallback, MessageVersion messageVersion, ResponseActionFilter filter, int responseCount, object state);
Ejemplo n.º 4
0
 /// <summary>
 /// Fetch the requests one by one from the storage but not remove the original message in the storage.
 /// if reach the end of the storage, empty exception raised.this is async call by BrokerQueueCallback.
 /// the async result will return the request message
 /// </summary>
 /// <param name="requestCallback">the call back to retrieve the request message</param>
 /// <param name="state">the async state object</param>
 public abstract void GetRequestAsync(BrokerQueueCallback requestCallback, object state);
Ejemplo n.º 5
0
 public BrokerQueueCallbackReferencedThreadHelper(BrokerQueueCallback callback, ReferenceObject refObj) : base(refObj)
 {
     this.brokerQueueCallback = callback;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the BrokerQueueCallbackItem class.
 /// </summary>
 /// <param name="brokerQueueCallback">the response/request callback.</param>
 /// <param name="state">the state object for the callback.</param>
 public BrokerQueueCallbackItem(BrokerQueueCallback brokerQueueCallback, object state)
 {
     ParamCheckUtility.ThrowIfNull(brokerQueueCallback, "brokerQueueCallback");
     this.brokerQueueCallbackField = brokerQueueCallback;
     this.callbackStateField       = state;
 }
Ejemplo n.º 7
0
 public override bool RegisterResponsesCallback(BrokerQueueCallback responseCallback, MessageVersion messageVersion, ResponseActionFilter filter, int responseCount, object state)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Fetch the requests one by one from the storage but not remove the original message in the storage.
 /// if reach the end of the storage, empty exception raised.this is async call by BrokerQueueCallback.
 /// the async result will return the request message
 /// </summary>
 /// <param name="requestCallback">the call back to retrieve the request message</param>
 /// <param name="state">the async state object</param>
 public override void GetRequestAsync(BrokerQueueCallback requestCallback, object state)
 {
     this.callbackQueue.Enqueue(new KeyValuePair <BrokerQueueCallback, object>(requestCallback, state));
 }