Exemple #1
0
        /// <summary>
        /// Pull responses for Java clients
        /// </summary>
        /// <param name="action">indicating the action</param>
        /// <param name="position">indicating the position</param>
        /// <param name="count">indicating the count</param>
        /// <returns>returns the responses messages</returns>
        /// <param name="version">indicating the message version</param>
        public BrokerResponseMessages PullResponses(string action, GetResponsePosition position, int count, MessageVersion version)
        {
            this.CheckDisconnected();

            this.timeoutManager.ResetTimeout();

            if (this.responsesClient is PullResponsesHandler)
            {
                PullResponsesHandler handler = this.responsesClient as PullResponsesHandler;
                if (handler.Match(action))
                {
                    return(handler.PullResponses(position, count));
                }
            }

            if (this.responsesClient != null)
            {
                this.responsesClient.Dispose();
            }

            this.responsesClient = new PullResponsesHandler(this.queue, action, this.timeoutManager, this.observer, this.sharedData, version);
            return((this.responsesClient as PullResponsesHandler).PullResponses(position, count));
        }
Exemple #2
0
        /// <summary>
        /// Get responses
        /// </summary>
        /// <param name="action">indicating the action</param>
        /// <param name="clientData">indicating the client data</param>
        /// <param name="resetToBegin">indicating the position</param>
        /// <param name="count">indicating the count</param>
        /// <param name="callbackInstance">indicating the callback instance</param>
        /// <param name="version">indicating the message version</param>
        public void GetResponses(string action, string clientData, GetResponsePosition resetToBegin, int count, IResponseServiceCallback callbackInstance, MessageVersion version)
        {
            this.CheckDisconnected();

            this.timeoutManager.ResetTimeout();

            if (this.responsesClient is GetResponsesHandler)
            {
                GetResponsesHandler handler = this.responsesClient as GetResponsesHandler;
                if (handler.Matches(action, clientData))
                {
                    handler.GetResponses(resetToBegin, count, callbackInstance);
                    return;
                }
            }

            if (this.responsesClient != null)
            {
                this.responsesClient.Dispose();
            }

            this.responsesClient = new GetResponsesHandler(this.queue, action, clientData, this.clientId, this.timeoutManager, this.observer, this.sharedData, version);
            (this.responsesClient as GetResponsesHandler).GetResponses(resetToBegin, count, callbackInstance);
        }
Exemple #3
0
        /// <summary>
        /// Dispose the broker client
        /// </summary>
        /// <param name="disposing">indicating whether it is disposing</param>
        private void Dispose(bool disposing)
        {
            this.disposing = disposing;
            try
            {
                // Set state
                this.state = BrokerClientState.Disconnected;

                // Copy all the connected instances out of lock
                List <object> connectedList = null;
                lock (this.connectedInstance)
                {
                    connectedList = new List <object>(this.connectedInstance.Keys);
                }

                foreach (object instance in connectedList)
                {
                    try
                    {
                        BrokerTracing.TraceInfo("[BrokerClient] Try to close the connected instance: {0} ({1})", instance.ToString(), instance.GetHashCode());
                        if (instance is IDisposable)
                        {
                            // BrokerController
                            ((IDisposable)instance).Dispose();
                        }
                        else if (instance is IChannel)
                        {
                            Utility.AsyncCloseICommunicationObject((ICommunicationObject)instance);
                        }
                        else
                        {
                            Debug.Fail("[BrokerClient] Connected instance must be IDisposable or IChannel.");
                        }
                    }
                    catch (Exception e)
                    {
                        BrokerTracing.TraceWarning("[BrokerClient] Failed to close the connected instance: {0}", e);
                    }
                }

                if (disposing)
                {
                    if (this.queue != null)
                    {
                        this.queue.OnEvent -= this.Queue_OnEvent;
                        this.queue.OnPutResponsesSuccessEvent -= this.Queue_OnPutResponsesSuccessEvent;
                        this.queue.OnFatalExceptionEvent      -= this.Queue_OnFatalExceptionEvent;

                        //for durable session, the queue is closed unless there were flushed requests, dispose if EOM was called.
                        if (this.sharedData.BrokerInfo.Durable)
                        {
                            if (this.queue.FlushedRequestsCount == 0)
                            {
                                BrokerTracing.TraceInfo("[BrokerClient] durable session broker client {0} close the queue.", this.clientId);
                                //if not ever flushed, reduce the count of all requests in the queue
                                this.observer.ReduceUncommittedCounter(this.queue.AllRequestsCount);
                                this.queue.Close();
                            }
                            else if (this.endOfMessageCalled)
                            {
                                // Only dispose the broker queue if it is a durable session. Non-durable broker queue for
                                // interactive session should be kept/reused and closed when closing the broker domain.
                                //
                                // Note (related bug #14224): logic in BrokerClient.SyncDisconnect() ensures that BrokerClient
                                // instance will not be disposed if EndRequests is called (this.state = BrokerClientState.EndRequests).
                                // So below code snippet could only be reached on broker entry exiting.
                                this.observer.ReduceUncommittedCounter(this.queue.AllRequestsCount - this.queue.FlushedRequestsCount);
                                this.queue.Dispose();
                            }
                        }
                        else //for interactive session, close the queue if EOM is not called.
                        {
                            if (!this.endOfMessageCalled)
                            {
                                BrokerTracing.TraceInfo("[BrokerClient] interactive session broker client {0} close the queue.", this.clientId);
                                if (!this.v2ProxyClient)
                                {
                                    //reduce the count of all unflushed requests in the queue
                                    this.observer.ReduceUncommittedCounter(this.queue.AllRequestsCount - this.queue.FlushedRequestsCount);
                                }
                                this.queue.Close();
                            }
                        }

                        this.queue = null;

                        this.batchMessageIds.Clear();
                    }
                }

                if (this.responsesClient != null)
                {
                    this.responsesClient.Dispose();
                    this.responsesClient = null;
                }

                if (this.timeoutManager != null)
                {
                    this.timeoutManager.Dispose();
                    this.timeoutManager = null;
                }

                // do not dispose this.lockForDiscardRequests for this may block the threads in the write queue, which may lead to the hang when broker entry exits.
                // do not dispose this.batchIdChangedEvent for any wait for the event would hang
            }
            catch (Exception e)
            {
                BrokerTracing.TraceWarning("[BrokerClient] Exception thrown while disposing: {0}", e);
            }
        }