Example #1
0
 private bool BeginRead(HttpCommand command)
 {
     if (command.HttpReadState.HasStillMoreBytesToRead)
     {
         var stream = command.HttpReadState.Stream;
         return _readAsync.BeginAsync(stream, command);
     }
     else
     {
         return false;
     }
 }
Example #2
0
        private AsyncPatternResult<HttpWebRequest, HttpCommand> OnBeginGetResponseCompleted(IAsyncResult result, HttpCommand command)
        {
            HttpWebRequest request = command.HttpReadState.WebRequest;

            var response = request.EndGetResponse(result);
            var stream = response.GetResponseStream();
            command.OnGotResponse(response, stream);

            BeginRead(command);

            return _getResponseAsync.Stop();
        }
Example #3
0
        public bool TrySend(HttpCommand command)
        {
            lock (_gate)
            {
                if (_hasBeenDisposed == true)
                {
                    return false;
                }
                _pendingCommands.Add(command);
            }

            command.SetHost(this.HostName, this.Port);
            var request = (HttpWebRequest)HttpWebRequest.Create(command.UriBuilder.Uri);

            command.BeginRequest(request);

            return _getResponseAsync.BeginAsync(request, command);
        }
        private void OnViewRequestError(string hostName, HttpCommand command)
        {
            var cluster = _cluster;
            if (GetHasQuit())
            {
                command.NotifyComplete(ResponseStatus.DisconnectionOccuredBeforeResponseReceived);
                return;
            }

            TrySendViewRequestToFirstAvailableServer(cluster, command);
        }
        private void TrySendViewRequestToFirstAvailableServer(Cluster cluster, HttpCommand httpCommand)
        {
            for (int i = 0; i < cluster.Servers.Count; i++)
            {
                var serverToUseForQuery = GetNextServerToUseForQuery(cluster);
                if (serverToUseForQuery.TrySend(httpCommand))
                {
                    return;
                }
            }

            httpCommand.NotifyComplete(ResponseStatus.DisconnectionOccuredBeforeResponseReceived);
        }
        private void TrySendingViewRequestToFirstAvailableServer(Cluster cluster, HttpCommand httpCommand, string keyHintForSelectingServer)
        {
            //We are going to use the key hint to help destribute which server should be getting the requests.
            if (!string.IsNullOrEmpty(keyHintForSelectingServer))
            {
                int vBucketId;
                var server = cluster.GetServer(keyHintForSelectingServer, out vBucketId);
                if (server.TrySend(httpCommand))
                {
                    return;
                }
            }

            TrySendViewRequestToFirstAvailableServer(cluster, httpCommand);
        }
        public void ExecuteViewHttpQuery(UriBuilder uriBuilder, string keyHintForSelectingServer, Action<ResponseStatus, string, object> callback, object state)
        {
            Cluster cluster = _cluster;

            HttpCommand httpCommand = new HttpCommand(uriBuilder, state, callback);

            TrySendingViewRequestToFirstAvailableServer(cluster, httpCommand, keyHintForSelectingServer);
        }
        private void OnServerStreamingMapDisconnected(string serverId, HttpCommand command)
        {
            lock (_gate)
            {
                _activeServersToLastReportedClusterDefinition.Remove(serverId);
            }

            //Wait a bit and ensure that the retry is executed asynchronously.

            //TODO: AK maybe use a Timer instead of a wait? Probably better for the threadpool.
            ThreadPool.QueueUserWorkItem(_ =>
            {
                Thread.Sleep(1000);

                lock (_gate)
                {
                    Cluster cluster = _cluster;
                    var server = cluster.GetServerById(serverId);

                    if (!_hasQuit && server != null)
                    {
                        RequestServerStreamingMap(server);
                    }
                }
            });

        }
Example #9
0
 public bool TrySend(HttpCommand httpCommand)
 {
     return ViewHttpClient.TrySend(httpCommand);
 }
Example #10
0
        private AsyncPatternResult<Stream, HttpCommand> OnBeginReadCompleted(IAsyncResult result, HttpCommand command)
        {
            var stream = command.HttpReadState.Stream;
            var bytesRead = stream.EndRead(result);

            if (bytesRead > 0 &&
                command.OnRead(bytesRead) &&
                command.HttpReadState.HasStillMoreBytesToRead)
            {
                return _readAsync.Continue(command.HttpReadState.Stream, command);
            }

            command.EndReading();
            RemoveFromPendingCommands(command);

            command.NotifyComplete();

            return _readAsync.Stop();
        }
Example #11
0
 private AsyncPatternResult<HttpWebRequest, HttpCommand> OnBeginGetResponseFailed(IAsyncResult result, HttpCommand command, Exception e)
 {
     OnFailure(command);
     return _getResponseAsync.Stop();
 }
Example #12
0
 private void EndRead(HttpCommand command, IAsyncResult result)
 {
 }
Example #13
0
 private void RemoveFromPendingCommands(HttpCommand command)
 {
     lock (_gate)
     {
         _pendingCommands.Remove(command);
     }
 }
Example #14
0
        private void OnFailure(HttpCommand command)
        {
            command.EndReading();

            RemoveFromPendingCommands(command);

            _onFailure(this.ServerId, command);
        }
Example #15
0
 private AsyncPatternResult<Stream, HttpCommand> OnBeginReadFailed(IAsyncResult result, HttpCommand command, Exception e)
 {
     OnFailure(command);
     return _readAsync.Stop();
 }