Ejemplo n.º 1
0
 private bool BeginRead(HttpCommand command)
 {
     if (command.HttpReadState.HasStillMoreBytesToRead)
     {
         var stream = command.HttpReadState.Stream;
         return _readAsync.BeginAsync(stream, command);
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        private void OnViewRequestError(string hostName, HttpCommand command)
        {
            var cluster = _cluster;
            if (GetHasQuit())
            {
                command.NotifyComplete(ResponseStatus.DisconnectionOccuredBeforeResponseReceived);
                return;
            }

            TrySendViewRequestToFirstAvailableServer(cluster, command);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
                    }
                }
            });

        }
Ejemplo n.º 9
0
 public bool TrySend(HttpCommand httpCommand)
 {
     return ViewHttpClient.TrySend(httpCommand);
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 11
0
 private AsyncPatternResult<HttpWebRequest, HttpCommand> OnBeginGetResponseFailed(IAsyncResult result, HttpCommand command, Exception e)
 {
     OnFailure(command);
     return _getResponseAsync.Stop();
 }
Ejemplo n.º 12
0
 private void EndRead(HttpCommand command, IAsyncResult result)
 {
 }
Ejemplo n.º 13
0
 private void RemoveFromPendingCommands(HttpCommand command)
 {
     lock (_gate)
     {
         _pendingCommands.Remove(command);
     }
 }
Ejemplo n.º 14
0
        private void OnFailure(HttpCommand command)
        {
            command.EndReading();

            RemoveFromPendingCommands(command);

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