/// <summary> /// Initializes client runtime from client configuration object. /// </summary> private static void DoInternalInitialize(IInternalClusterClient clusterClient) { if (IsInitialized) { return; } lock (initLock) { if (!IsInitialized) { try { // this is probably overkill, but this ensures isFullyInitialized false // before we make a call that makes RuntimeClient.Current not null isFullyInitialized = false; client = clusterClient; // Keep reference, to avoid GC problems client.Connect().GetAwaiter().GetResult(); // this needs to be the last successful step inside the lock so // IsInitialized doesn't return true until we're fully initialized isFullyInitialized = true; } catch (Exception exc) { // just make sure to fully Uninitialize what we managed to partially initialize, so we don't end up in inconsistent state and can later on re-initialize. Console.WriteLine("Initialization failed. {0}", exc); InternalUninitialize(); throw; } } } }
private static void RunCommand(string command, string[] args) { var clientBuilder = new ClientBuilder().LoadConfiguration(); using (client = (IInternalClusterClient)clientBuilder.Build()) { client.Connect().Wait(); systemManagement = client.GetGrain <IManagementGrain>(0); var options = args.Skip(1) .Where(s => s.StartsWith("-")) .Select(s => s.Substring(1).Split('=')) .ToDictionary(a => a[0].ToLowerInvariant(), a => a.Length > 1 ? a[1] : ""); var restWithoutOptions = args.Skip(1).Where(s => !s.StartsWith("-")).ToArray(); switch (command) { case "grainstats": PrintSimpleGrainStatistics(restWithoutOptions); break; case "fullgrainstats": PrintGrainStatistics(restWithoutOptions); break; case "collect": CollectActivations(options, restWithoutOptions); break; case "unregister": var unregisterArgs = args.Skip(1).ToArray(); UnregisterGrain(unregisterArgs); break; case "lookup": var lookupArgs = args.Skip(1).ToArray(); LookupGrain(lookupArgs); break; case "grainreport": var grainReportArgs = args.Skip(1).ToArray(); GrainReport(grainReportArgs); break; default: PrintUsage(); break; } client.Close().Wait(); } }