Exemple #1
0
 /// <summary>
 /// Throw heartbeat exception if closed flag is true
 /// </summary>
 private void ThrowIfClosed()
 {
     if (this.closed)
     {
         throw SessionBase.GetHeartbeatException(false);
     }
 }
Exemple #2
0
 /// <summary>
 /// Throw heartbeat exception if the broker is closed
 /// </summary>
 private void ThrowIfClosed()
 {
     if (this.brokerEntry == null)
     {
         throw SessionBase.GetHeartbeatException(false);
     }
 }
        /// <summary>
        /// Callback called when broker is down
        /// </summary>
        public void SendBrokerDownSignal(bool isBrokerNodeDown)
        {
            lock (this.shutdownLock)
            {
                // If the handler is already shutting down, just return. We dont want user to get unecessary exception responses.
                if (this.shuttingDown)
                {
                    return;
                }

                try
                {
                    this.InvokeCallback(new BrokerResponse <TMessage>(SessionBase.GetHeartbeatException(isBrokerNodeDown), new UniqueId(Guid.Empty)));
                }
                catch (Exception e)
                {
                    // Log and eat unhandled user exceptions from their calback
                    Utility.LogError("Unhandled exception from user's response callback - {0}", e);
                }

                // close this instance
                this.Close();
            }
        }
Exemple #4
0
        /// <summary>
        ///   <para>Advances the enumerator to the next element of the collection.</para>
        /// </summary>
        /// <returns>
        ///   <para>
        ///     <see cref="System.Boolean" /> object that specifies whether the enumerator successfully advanced to the next element.
        /// True indicates that the enumerator successfully advanced to the next element.
        /// False indicates that the enumerator passed the end of the collection.</para>
        /// </returns>
        /// <exception cref="System.InvalidOperationException">
        ///   <para>The collection was modified after the enumerator was created. </para>
        /// </exception>
        /// <remarks>
        ///   <para>After you create the enumerator or call the
        ///
        /// <see cref="Reset" /> method, the enumerator is positioned before the first element of the collection, and the first call to the
        ///
        /// <see cref="MoveNext" /> method moves the enumerator over the first element of the collection.</para>
        ///   <para>If
        ///
        /// <see cref="MoveNext" /> passes the end of the collection, the enumerator is positioned after the last element in the collection, and
        /// <see cref="MoveNext" /> returns
        /// False. When the enumerator is at this position, subsequent calls to
        /// <see cref="MoveNext" /> also returns
        /// False until you call
        /// <see cref="Reset" />.</para>
        ///   <para>An enumerator remains valid as long as the collection remains unchanged. If you make changes to
        /// the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and the next call to
        /// <see cref="MoveNext" /> or
        /// <see cref="Reset" /> results in an
        /// <see cref="System.InvalidOperationException" />.</para>
        /// </remarks>
        /// <seealso cref="Reset" />
        /// <seealso cref="System.Collections.IEnumerator.MoveNext" />
        public bool MoveNext()
        {
            // If the corresponding BrokerClient is closed or disposed, return no more items
            if (this.close)
            {
                if (!this.session.IsBrokerAvailable)
                {
                    throw SessionBase.GetHeartbeatException(this.isBrokerNodeDown);
                }
                else
                {
                    return(false);
                }
            }

            ThrowIfNeed(this.endOfResponsesReason);

            bool flag1, flag2, flag3;

            lock (this.responsesLock)
            {
                flag1 = this.currentEnumWindow == null || this.currentEnumWindow.Count == 0;
                flag2 = this.responsesWindows.Count == 0;
                flag3 = this.totalResponseCount != this.currentResponseCount;
            }

            // If there is no current window for enumeration or the current one is empty
            if (flag1)
            {
                // If there are no other windows ready for enumeration
                if (flag2)
                {
                    // If all responses have not been returned
                    if (flag3)
                    {
                        // Wait for more response windows to be ready for enumeration
                        int ret = WaitHandle.WaitAny(new WaitHandle[] { this.newResponseWindowOrEOM, this.signalBrokerDown }, this.newResponsesTimeout, false);

                        // If the timeout expires,
                        if (ret == WaitHandle.WaitTimeout)
                        {
                            // Check to see if the receive window has messages
                            if (this.currentReceiveWindow.Count == 0)
                            {
                                // If not return that there are no more messages
                                // RICHCI: 6/7/9 : Changed from returning false to throwing timeout exception
                                //  so user can distinguish between timeout and no more responses
                                throw new TimeoutException(String.Format(SR.TimeoutGetResponse, this.newResponsesTimeout.TotalMilliseconds));
                            }
                            else
                            {
                                // If there are response messages, move the partially filled receive window to
                                // the "ready to read" response windows queue
                                lock (this.responsesLock)
                                {
                                    this.responsesWindows.Enqueue(this.currentReceiveWindow);
                                    this.currentReceiveWindow = new Queue <MessageWindowItem>();
                                }

                                // Fall through to pulling a new window for the current enum window
                            }
                        }

                        // If the broker down event is signaled, throw exception
                        if (ret == 1)
                        {
                            var faultException = this.exceptionCauseBrokerDown as FaultException <SessionFault>;

                            if (faultException != null)
                            {
                                throw Utility.TranslateFaultException(faultException);
                            }
                            else
                            {
                                throw SessionBase.GetHeartbeatException(this.isBrokerNodeDown);
                            }
                        }

                        ThrowIfNeed(this.endOfResponsesReason);

                        // If the BrokerClient is disposed or closed, return there are no more responses
                        if (this.close)
                        {
                            return(false);
                        }

                        // If all we were waiting for was EOM, return there are no more responses
                        if (this.responsesWindows.Count == 0)
                        {
                            return(false);
                        }

                        // Else fall through to pulling a new window for the current enum window
                    }
                    else
                    {
                        // If there are no responses pending, return that there are no more responses
                        return(false);
                    }
                }

                int responseWindowCount = 0;

                // Get a new current enum window
                lock (this.responsesLock)
                {
                    this.currentEnumWindow = this.responsesWindows.Dequeue();
                    responseWindowCount    = this.responsesWindows.Count;
                }

                // If this was the last window
                if (responseWindowCount == 0)
                {
                    // Reset the event so subsequent calls to Move wait
                    this.newResponseWindowOrEOM.Reset();

                    // Do not ask for more responses. The enumerator would ask for more
                    // responses only when outstanding responses is 0.
                }
            }

            // Dequeue the current message
            MessageWindowItem messageWindowItem = this.currentEnumWindow.Dequeue();

            // Bug #15946: handling client side exception thrown from WebResponseHandler(when talking to rest service)
            if (messageWindowItem.CarriedException != null)
            {
                throw messageWindowItem.CarriedException;
            }

            // Create a BrokerResponse object from Message
            this.currentResponse = this.CreateResponse(messageWindowItem.ActionFromResponse, messageWindowItem.ReplyAction, messageWindowItem.MessageBuffer, messageWindowItem.RelatesTo);

            // Return true since Current will have a new element
            return(true);
        }