Ejemplo n.º 1
0
        internal void OnRequestCompleted(Servers.RequestAgent agent)
        {
            this.Statistics.Add(agent.Code);
            EventRequestCompletedArgs e = new EventRequestCompletedArgs(agent.Request, agent.Response, agent.Code);

            Requested?.Invoke(this, e);
        }
Ejemplo n.º 2
0
        public async void Execute(HttpRequest request, HttpResponse response, UrlRouteServerGroup.UrlServerInfo serverInfo, Routes.UrlRoute urlRoute)
        {
            try
            {
                var clientAgent = await PopClient();

                if (clientAgent == null)
                {
                    string error = $"Unable to reach {Host}:{Port} request queue overflow!";
                    Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs(request, response,
                                                                                           Gateway, error, Gateway.SERVER_AGENT_QUEUE_OVERFLOW);
                    Gateway.OnResponseError(erea);
                    Gateway.ProcessError(Gateway.SERVER_AGENT_QUEUE_OVERFLOW, request);
                    Statistics.Add(Gateway.SERVER_AGENT_QUEUE_OVERFLOW, 0);
                    if (request.Server.EnableLog(LogType.Info))
                    {
                        request.Server.Log(LogType.Info, $"Gateway {request.ID} {request.RemoteIPAddress} {request.Method} {request.Url} route to {Uri} error  exceeding maximum number of connections");
                    }
                }
                else
                {
                    clientAgent.Status = TcpClientAgentStatus.None;
                    RequestAgent agent = new RequestAgent(clientAgent, this, request, response, serverInfo, urlRoute);
                    agent.Completed = OnCompleted;
                    agent.Execute();
                }
            }
            catch (Exception e_)
            {
                if (urlRoute.Gateway.HttpServer.EnableLog(LogType.Error))
                {
                    urlRoute.Gateway.HttpServer.Log(LogType.Error, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} route to {Uri} error {e_.Message}{e_.StackTrace}");
                }
            }
        }
Ejemplo n.º 3
0
        public async void Execute(HttpRequest request, HttpResponse response, UrlRouteServerGroup.UrlServerInfo serverInfo, Routes.UrlRoute urlRoute)
        {
            try
            {
                var clientAgent = await PopClient();

                if (clientAgent == null)
                {
                    string error = $"Unable to reach {Host}:{Port} HTTP request, exceeding maximum number of connections";
                    Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs(request, response,
                                                                                           Gateway, error, Gateway.SERVER_MAX_OF_CONNECTIONS);
                    Gateway.OnResponseError(erea);
                }
                else
                {
                    RequestAgent agent = new RequestAgent(clientAgent, this, request, response, serverInfo, urlRoute);
                    agent.Completed = OnCompleted;
                    Gateway.AddRequest(agent);
                    //agent.Execute();
                }
            }
            catch (Exception e_)
            {
                if (urlRoute.Gateway.HttpServer.EnableLog(LogType.Error))
                {
                    urlRoute.Gateway.HttpServer.Log(LogType.Error, $"gateway {request.Url} route to {Uri} error {e_.Message}{e_.StackTrace}");
                }
            }
        }
Ejemplo n.º 4
0
 internal void OnRequestCompleted(Servers.RequestAgent success)
 {
     IncrementRequestCompleted(success.Request, success.Code, success.Time, success.Server);
     if (Pluginer.RequestedEnabled)
     {
         Pluginer.Requested(success.GetEventRequestCompletedArgs());
     }
 }
Ejemplo n.º 5
0
 internal void OnRequestCompleted(Servers.RequestAgent success)
 {
     HttpServer.RequestExecuted();
     if (Requested != null)
     {
         EventRequestCompletedArgs e = new EventRequestCompletedArgs(success.UrlRoute, success.Request, success.Response, this, success.Code, success.Server, success.Time);
         Requested(this, e);
     }
 }
Ejemplo n.º 6
0
 private void OnCompleted(RequestAgent requestAgent)
 {
     try
     {
         if (requestAgent.Code == Gateway.SERVER_SOCKET_ERROR)
         {
             var count = System.Threading.Interlocked.Increment(ref mSocketErrors);
             OnSocketError(true);
         }
         else
         {
             OnSocketError(false);
         }
     }
     finally
     {
         Gateway.OnRequestCompleted(requestAgent);
     }
 }
Ejemplo n.º 7
0
 internal void OnRequestCompleted(Servers.RequestAgent success)
 {
     HttpServer.RequestExecuted();
     if ((success.Code >= 200 && success.Code < 300) || (success.Code >= 500 && success.Code < 600))
     {
         var stats = Routes.GetUrlStatistics(success.Request.BaseUrl);
         stats.Add(success.Code, success.Time, success.Server);
     }
     else
     {
         if (Routes.UrlStatisticsCount < this.MaxStatsUrls)
         {
             var stats = Routes.GetUrlStatistics(success.Request.BaseUrl);
             stats.Add(success.Code, success.Time, success.Server);
         }
     }
     Statistics.Add(success.Code, success.Time);
     Pluginer.Requested(success);
 }
Ejemplo n.º 8
0
 internal void OnRequestCompleted(Servers.RequestAgent success)
 {
     try
     {
         ServerHttpRequested.Invoke(this, success);
     }
     catch (Exception e_)
     {
         if (HttpServer.EnableLog(BeetleX.EventArgs.LogType.Warring))
         {
             HttpServer.Log(BeetleX.EventArgs.LogType.Warring,
                            $"Gateway {success.Request.ID} {success.Request.RemoteIPAddress} {success.Request.Method} {success.Request.Url} error {e_.Message}@{e_.StackTrace}");
         }
     }
     RequestIncrementCompleted(success.Request, success.Code, success.Time, success.Server);
     if (Pluginer.RequestedEnabled)
     {
         Pluginer.Requested(success.GetEventRequestCompletedArgs());
     }
 }
Ejemplo n.º 9
0
 public void Execute(HttpRequest request, HttpResponse response)
 {
     TcpClientAgent clientAgent = PopClient();
     if (clientAgent == null)
     {
         string error = $"Unable to reach {Host}:{Port} HTTP request, exceeding maximum number of connections";
         if (Gateway.HttpServer.EnableLog(LogType.Error))
         {
             Gateway.HttpServer.Log(LogType.Error, error);
         }
         BadGateway result = new BadGateway(error);
         Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs(request, response,
             result, BadGateway.SERVER_MAX_OF_CONNECTIONS);
         Gateway.OnResponseError(erea);
     }
     else
     {
         RequestAgent agent = new RequestAgent(clientAgent, this, request, response);
         agent.Completed = OnCompleted;
         agent.Execute();
     }
 }
Ejemplo n.º 10
0
        internal EventServerRequestingArgs OnServerHttpRequesting(Servers.RequestAgent requestAgent)
        {
            EventServerRequestingArgs e = null;

            try
            {
                if (ServerHttpRequesting != null)
                {
                    e = new EventServerRequestingArgs(requestAgent, requestAgent.Request, requestAgent.Response, this);
                    ServerHttpRequesting?.Invoke(this, e);
                }
            }
            catch (Exception e_)
            {
                if (HttpServer.EnableLog(LogType.Error))
                {
                    HttpServer.Log(LogType.Error,
                                   $"Gateway {requestAgent.Request.RemoteIPAddress} {requestAgent.Request.Method} {requestAgent.Request.Url} server http requesting event error {e_.Message}{e_.StackTrace}");
                }
            }
            return(e);
        }
Ejemplo n.º 11
0
 private void OnCompleted(RequestAgent requestAgent)
 {
     try
     {
         if (requestAgent.Code == Gateway.SERVER_SOCKET_ERROR)
         {
             var count = System.Threading.Interlocked.Increment(ref mSocketErrors);
             OnSocketError(true);
         }
         else
         {
             OnSocketError(false);
         }
         if (Gateway.HttpServer.EnableLog(LogType.Info))
         {
             Gateway.HttpServer.Log(LogType.Info,
                                    $"gateway {requestAgent.Request.RemoteIPAddress} {requestAgent.Request.Method} {requestAgent.Request.Url} request to {Host}:{Port} completed code {requestAgent.Code}");
         }
     }
     finally
     {
         Gateway.OnRequestCompleted(requestAgent);
     }
 }
Ejemplo n.º 12
0
 internal void OnRequestCompleted(Servers.RequestAgent success)
 {
     HttpServer.RequestExecuted();
     Pluginer.Requested(success);
 }
Ejemplo n.º 13
0
        public void Remove(RequestAgent requestAgent)
        {
            var table = GetTable(requestAgent);

            table.TryRemove(requestAgent.RequestID, out RequestAgent result);
        }
Ejemplo n.º 14
0
        public void Add(RequestAgent requestAgent)
        {
            var table = GetTable(requestAgent);

            table[requestAgent.RequestID] = requestAgent;
        }
Ejemplo n.º 15
0
 private ConcurrentDictionary <long, RequestAgent> GetTable(RequestAgent request)
 {
     return(mItems[(int)(request.RequestID % mItems.Count)]);
 }