Ejemplo n.º 1
0
        void ProcessSubscriber(IPendingRequestQueue pendingRequests)
        {
            while (true)
            {
                var nextRequest = pendingRequests.Dequeue();
                var faulted     = false;

                try
                {
                    stream.Send(nextRequest);
                }
                catch (IOException ex)
                {
                    if (nextRequest != null)
                    {
                        var response = ResponseMessage.FromException(nextRequest, ex);
                        pendingRequests.ApplyResponse(response);
                        faulted = true;
                    }
                }

                if (nextRequest != null && !faulted)
                {
                    var response = stream.Receive <ResponseMessage>();
                    pendingRequests.ApplyResponse(response);
                }

                if (!stream.ExpectNextOrEnd())
                {
                    break;
                }
                stream.SendProceed();
            }
        }
 static ResponseMessage InvokeAndWrapAnyExceptions(RequestMessage request, Func <RequestMessage, ResponseMessage> incomingRequestProcessor)
 {
     try
     {
         return(incomingRequestProcessor(request));
     }
     catch (Exception ex)
     {
         return(ResponseMessage.FromException(request, ex));
     }
 }
        async Task <bool> ProcessReceiverInternalAsync(IPendingRequestQueue pendingRequests, RequestMessage nextRequest)
        {
            try
            {
                stream.Send(nextRequest);
                if (nextRequest != null)
                {
                    var response = stream.Receive <ResponseMessage>();
                    pendingRequests.ApplyResponse(response);
                }
            }
            catch (Exception ex)
            {
                if (nextRequest != null)
                {
                    var response = ResponseMessage.FromException(nextRequest, ex);
                    pendingRequests.ApplyResponse(response);
                }
                return(false);
            }

            try
            {
                if (!await stream.ExpectNextOrEndAsync())
                {
                    return(false);
                }
            }
            catch (Exception ex) when(ex.IsSocketConnectionTimeout())
            {
                // We get socket timeout on the server when the network connection to a polling client drops
                // (in Octopus this is the server for a Polling Tentacle)
                // In normal operation a client will poll more often than the timeout so we shouldn't see this.
                log.Write(EventType.Error, "No messages received from client for timeout period. This may be due to network problems. Connection will be re-opened when required.");
                return(false);
            }
            await stream.SendProceedAsync();

            return(true);
        }