Exemplo n.º 1
0
        public ActionResult RunAction(string receivedData)
        {
            MobileAppServerClient.RequestBody rb = JsonConvert.DeserializeObject <MobileAppServerClient.RequestBody>(receivedData);
            SubServer targetServer = GetAvailableSubServer();

            string cacheResultKey = BuildCacheResultKey(rb);

            if (targetServer == null)
            {
                CheckAllocateNewInstance();
                return(ResolveResultOnUreachableServer(cacheResultKey));
            }

            Client client = BuildClient(targetServer);

            client.SendRequest(rb);

            MobileAppServerClient.OperationResult result = client.GetResult();

            if (EnabledCachedResultsForUnreachableServers)
            {
                CacheRepository <MobileAppServerClient.OperationResult> .Set(cacheResultKey, result, 380);
            }

            if (targetServer.HasLifetime())
            {
                targetServer.RefreshLifetime();
            }
            return(ActionResult.Json(result));
        }
Exemplo n.º 2
0
        private bool IsServerUnavailable(SubServer server)
        {
            string       key    = $"unavailable-{server.Address}:{server.Port}";
            Cache <bool> cached = CacheRepository <bool> .Get(key);

            if (cached != null)
            {
                LogController.WriteLog($"The sub-server node '{server.Address}:{server.Port}' is unreachable. It is temporarily ignored but will be reconsidered in less than 120 seconds", ServerLogType.ALERT);
            }
            return(cached != null);
        }
Exemplo n.º 3
0
        private int GetCurrentThreadCountOnServer(SubServer server, Client client)
        {
            LogController.WriteLog($"Querying availability on '{server.Address}:{server.Port}'", ServerLogType.INFO);

            MobileAppServerClient.RequestBody rb = MobileAppServerClient
                                                   .RequestBody.Create("ServerInfoController", "GetCurrentThreadsCount");
            client.SendRequest(rb);

            int result = int.Parse(client.ReadResponse().Content.ToString());

            return(result);
        }
Exemplo n.º 4
0
 private Client BuildClient(SubServer server)
 {
     try
     {
         Client client = new Client(server.Address,
                                    server.Port, server.Encoding, server.BufferSize,
                                    server.MaxConnectionAttempts);
         return(client);
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 5
0
        public static void AddSubServer(string address, int port,
                                        Encoding encoding, int bufferSize, int maxConnectionAttempts,
                                        int acceptableProcesses)
        {
            if (SubServers == null)
            {
                SubServers = new List <SubServer>();
            }

            var server = new SubServer(address, port, encoding,
                                       bufferSize, maxConnectionAttempts, acceptableProcesses);

            AddSubServerInternal(server);
        }
Exemplo n.º 6
0
        private static void AddSubServerInternal(SubServer server, bool isDynamicInstance = false)
        {
            SubServers.Add(server);

            if (SubServers.Count > 1)
            {
                if (isDynamicInstance)
                {
                    if (NotifiableSubServerRequirement != null)
                    {
                        server.EnableLifetime(NotifiableSubServerRequirement, ServersLifetimeInMinutes);
                        server.OnLifeTimeEnded += SubServer_OnLifeTimeEnded;
                    }
                }
            }

            LogController.WriteLog($"Added sub-server node named as '{server.Address}:{server.Port}'", ServerLogType.INFO);
        }
Exemplo n.º 7
0
 private static void SubServer_OnLifeTimeEnded(SubServer subServer)
 {
     LogController.WriteLog($"Sub-server '{subServer.Address}:{subServer.Port}' is no longer needed and will be detached from the pool of sub-servers. A notification was issued for the target sub-server to be shut down", ServerLogType.ALERT);
     SubServers.Remove(subServer);
 }