/// <summary>
        /// Get current app's router state
        /// </summary>
        /// <returns></returns>
        public AppRouterState Get()
        {
            AppRouterState state;

            lock (mutex)
            {
                if (currentState != null)
                {
                    state = currentState;
                }
                var appId  = AVClient.CurrentConfiguration.ApplicationId;
                var region = AVClient.CurrentConfiguration.Region;
                state = AppRouterState.GetInitial(appId, region);
            }

            if (AVClient.CurrentConfiguration.Region != AVClient.Configuration.AVRegion.Public_US)
            {
                // don't refresh app router in US region.
                return(state);
            }

            if (state.isExpired())
            {
                lock (mutex)
                {
                    state.FetchedAt = DateTime.Now + TimeSpan.FromMinutes(10);
                }
                Task.Factory.StartNew(RefreshAsync);
            }
            return(state);
        }
 public Task RefreshAsync()
 {
     return(QueryAsync(CancellationToken.None).ContinueWith(t =>
     {
         if (!t.IsFaulted && !t.IsCanceled)
         {
             lock (mutex)
             {
                 currentState = t.Result;
             }
         }
     }));
 }
        private static AppRouterState ParseAppRouterState(IDictionary <string, object> jsonObj)
        {
            var state = new AppRouterState()
            {
                TTL                  = (int)jsonObj["ttl"],
                StatsServer          = jsonObj["stats_server"] as string,
                RealtimeRouterServer = jsonObj["rtm_router_server"] as string,
                PushServer           = jsonObj["push_server"] as string,
                EngineServer         = jsonObj["engine_server"] as string,
                ApiServer            = jsonObj["api_server"] as string,
                Source               = "network",
            };

            return(state);
        }