/// <summary> /// This is the lock free version of uninitilize so we can share /// it between the public method and error paths inside initialize. /// This should only be called inside a lock(initLock) block. /// </summary> private static void InternalUninitialize(bool cleanup = true) { // Update this first so IsInitialized immediately begins returning // false. Since this method should be protected externally by // a lock(initLock) we should be able to reset everything else // before the next init attempt. isFullyInitialized = false; try { if (cleanup) { client?.Close().GetAwaiter().GetResult(); } else { client?.Abort(); } } catch (Exception) { } finally { client?.Dispose(); client = null; } }
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(); } }