static void Main(string[] args) { Console.CancelKeyPress += (s, e) => _exitEvent.Set(); Configuration = LoadConfiguration(); Startup(); _exitEvent.WaitOne(); _clusterClient?.Dispose(); }
public async Task StopAsync(CancellationToken cancellationToken) { Console.WriteLine("Cluster client service stopping."); await client?.Close(); client?.Dispose(); }
public override void Dispose() { _clusterClient?.Dispose(); Host.Stop(); // don't use host.dispose, host.stop should do all the work var siloStopTimeout = TimeSpan.FromSeconds(60); var completed = SiloStopped.Wait(siloStopTimeout); if (!completed) { throw new TimeoutException($"ServiceTester: The service failed to shutdown within the {siloStopTimeout.TotalSeconds} seconds limit."); } var waitStopped = Host.WaitForServiceGracefullyStoppedAsync(); // We aren't actually waiting? if (waitStopped.IsCompleted && waitStopped.Result == StopResult.Force) { throw new TimeoutException("ServiceTester: The service failed to shutdown gracefully."); } base.Dispose(); }
static async Task InitializeOrleans() { var config = new ClientConfiguration(); config.DeploymentId = "Orleans-Docker"; config.PropagateActivityId = true; var hostEntry = await Dns.GetHostEntryAsync("orleans-silo"); var ip = hostEntry.AddressList[0]; config.Gateways.Add(new IPEndPoint(ip, 10400)); Console.WriteLine("Initializing..."); client = new ClientBuilder().UseConfiguration(config).Build(); await client.Connect(); running = true; Console.WriteLine("Initialized!"); var grain = client.GetGrain <IGreetingGrain>(Guid.NewGuid()); while (running) { var response = await grain.SayHello("Gutemberg"); Console.WriteLine($"[{DateTime.UtcNow}] - {response}"); await Task.Delay(1000); } client.Dispose(); }
private static async Task StartOrleansClient(string[] args) { _log.Information("Starting orleans client"); var attempts = 0; while (true) { try { _orleansClient = BuildOrleansClient(args); attempts++; _log.Information($"Trying to connect to the host, attempt #{attempts}"); await _orleansClient.Connect(); break; } catch (Exception ex) { _log.Warning(ex, $"Failed to connect to the host, after {attempts} attempt(s)"); _orleansClient?.Dispose(); if (attempts == 5) { throw ex; } await Task.Delay(TimeSpan.FromSeconds(5)); } } _log.Information("Orleans client started"); }
private static async Task <IClusterClient> TryConnect(HostBuilderContext context) { IClusterClient client = null; try { var builder = new ClientBuilder(); // TODO get from context.config builder.UseLocalhostClustering(); // TODO needs config delegates to customize parts builder.ConfigureApplicationParts(parts => { parts.AddApplicationPart(typeof(IArrayGrain <>).Assembly).WithReferences(); }); client = builder.Build(); // causes host builder to run hosted services??? Console.WriteLine("Awaiting connect request."); await client.Connect(); } catch { Console.WriteLine("Exception caught."); client?.Dispose(); throw; } return(client); }
private static async Task <IClusterClient> TryConnect(IConfiguration config) { IClusterClient client = null; try { var builder = new ClientBuilder(); //builder.ConfigureLogging(logging => { // logging // .AddFilter("Microsoft", LogLevel.Warning) // .AddFilter("Orleans", LogLevel.Warning) // .AddFilter("Runtime", LogLevel.Warning) // .AddConsole(); //}) // TODO read configuration builder.UseLocalhostClustering(); // cluster and service IDs default to "dev" builder.AddJobFacServicesParts(); client = builder.Build(); // causes host builder to run hosted services??? await client.Connect().ConfigureAwait(false); } catch { client?.Dispose(); throw; } return(client); }
public void Dispose() { Database.ExecuteAsync("FLUSHALL").Wait(); Client.Dispose(); Cluster.StopAllSilos(); _redis?.Dispose(); }
public void Dispose() { _clusterClient?.Close(); _clusterClient?.Dispose(); _siloHost?.StopAsync().Wait(); _siloHost?.Dispose(); _siloScope?.Dispose(); }
static async Task InitializeOrleans() { //var config = new ClusterConfiguration(); //config.Globals.DataConnectionString = "Server=tnwli-pc.dmtnprod.lan;Database=ApprovalSystem;User Id=QTIP;Password=QTIP; "; //config.Globals.ClusterId = "AprovalSiloID"; //config.Globals.LivenessType = GlobalConfiguration.LivenessProviderType.SqlServer; //config.Globals.ReminderServiceType = GlobalConfiguration.ReminderServiceProviderType.SqlServer; //config.Defaults.PropagateActivityId = true; //config.Defaults.ProxyGatewayEndpoint = new System.Net.IPEndPoint(IPAddress.Any, 18000); var config = new ClientConfiguration(); config.ClusterId = "AprovalSiloID"; config.PropagateActivityId = true; config.AdoInvariant = "System.Data.SqlClient"; config.DataConnectionString = "Server=tnwli-pc.dmtnprod.lan;Database=ApprovalSystem;User Id=QTIP;Password=QTIP; "; config.GatewayProvider = ClientConfiguration.GatewayProviderType.SqlServer; Console.WriteLine("Initializing ... "); client = new ClientBuilder() .ConfigureApplicationParts(p => p.AddFromAppDomain().AddFromApplicationBaseDirectory()) .UseConfiguration(config).Build(); var builder = ClientBuilder.CreateDefault() .UseConfiguration(config) .ConfigureApplicationParts(parts => parts.AddFromAppDomain().AddFromApplicationBaseDirectory()); client = builder.Build(); try { await client.Connect(); running = true; Console.WriteLine("Initialized."); var grain = client.GetGrain <IUser>(Guid.Empty); while (running) { string proposal = "ACED Proposal"; //int num = 15; var response = await grain.Approve(proposal); Console.WriteLine($"{proposal} was Approved : { response}"); await Task.Delay(1000); } client.Dispose(); } catch (Exception ex) { throw ex; } }
/// <summary> /// Connects the cluster client to the cluster. /// </summary> /// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns> private async Task ConnectOrleansClient() { this.logger.Information("Connecting to Orleans cluster."); await Policy.Handle <Exception>().WaitAndRetryForeverAsync( i => TimeSpan.FromSeconds(3), (ex, ts) => { if (ex.GetType() == typeof(SiloUnavailableException)) { this.logger.Error("Silo is not available..."); } else { this.logger.Error(ex, "Connection to Orleans cluster failed!"); clusterClient?.Dispose(); } }).ExecuteAsync( async() => { // TODO: check if db connection is needed here or static clustering is the better approach to connect to silo host clusterClient = new ClientBuilder().Configure <ClusterOptions>( options => { var clusterOptions = this.clusterConfiguration.OrleansConfiguration.ClusterOptions; options.ClusterId = clusterOptions.ClusterId; options.ServiceId = clusterOptions.ServiceId; }).UseAdoNetClustering( options => { options.Invariant = "Npgsql"; options.ConnectionString = this.clusterConfiguration.DatabaseSettings.ToConnectionString(); }).AddSimpleMessageStreamProvider("SMSProvider").ConfigureLogging( logging => { logging.AddSerilog(); }).Build(); await clusterClient.Connect( async ex => { await Task.Delay(500); return(true); }); this.logger.Information("Connection to Orleans cluster successful!"); }); while (!clusterClient.IsInitialized) { await Task.Delay(500); } }
private static async Task <IClusterClient> InitialiseClient() { int tryTimes = 10; while (tryTimes > 0) { try { client = new ClientBuilder() .UseAdoNetClustering(options => { options.Invariant = "MySql.Data.MySqlClient"; options.ConnectionString = "server=localhost;port=3306;database=orleans;user id=root;password=;SslMode=none;"; }) .Configure <ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "OrleansTest"; }) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IPersonGrain).Assembly)) .ConfigureLogging(log => log.SetMinimumLevel(LogLevel.Warning).AddConsole()) .Build(); await client.Connect(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { await Task.Delay(TimeSpan.FromSeconds(5)); if (client != null && !client.IsInitialized) { client.Dispose(); client = null; } } tryTimes--; } return(client); }
public void Dispose() { try { if (Interlocked.CompareExchange(ref _connecting, 1, 0) == 1) { _client.Close(); _client.Abort(); _client.Dispose(); } } catch (Exception ex) { _logger.LogCritical(ex.ToString()); } finally { _connecting = 0; _client = null; } }
public IClusterClient Create() { if (!_client.IsInitialized || needReBuild) { lock (connectLock) { if (!_client.IsInitialized || needReBuild) { if (needReBuild) { _client.Close(); _client.Dispose(); } _client = _builderFunc().Build(); _client.Connect().GetAwaiter().GetResult(); needReBuild = false; } } } return(_client); }
private static async Task <IClusterClient> InitialiseClient() { int tryTimes = 10; while (tryTimes > 0) { try { client = new ClientBuilder() .UseLocalhostClustering() .Configure <ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "OrleansTest"; }) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ITestGrain).Assembly)) .ConfigureLogging(log => log.SetMinimumLevel(LogLevel.Warning).AddConsole()) .Build(); await client.Connect(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { await Task.Delay(TimeSpan.FromSeconds(5)); if (client != null && !client.IsInitialized) { client.Dispose(); client = null; } } tryTimes--; } return(client); }
/// <summary> /// Disconnect and dispose connected client /// </summary> /// <returns></returns> public int Disconnect() { if (_clusterClient == null) { throw new OrleansException("There is no cluster client to disconnect"); } try { _clusterClient.Close(); _clusterClient.Dispose(); Console.WriteLine("Cluster client successfully disconnected"); } catch (Exception ex) { Console.Error.WriteLine(ex); return(1); } return(0); }
public static void CloseClient(this PSCmdlet cmdlet, IClusterClient client) { try { if (client == null) { return; } try { client.Close().GetAwaiter().GetResult(); } catch (Exception exception) { cmdlet.WriteError( new ErrorRecord( exception, $"{nameof(IClusterClient)}{nameof(IClusterClient.Close)}Failed", ErrorCategory.CloseError, client)); } client.Dispose(); } finally { var sessionClient = cmdlet.GetClient(); // If this client is the client associated with the current session, clear the current session's client. if (ReferenceEquals(sessionClient, client)) { cmdlet.SetClient(null); } } }
public async Task Shutdown() { if (clientHost is { } client) { await client.StopAsync(); if (client is IAsyncDisposable asyncDisposable) { await asyncDisposable.DisposeAsync(); } else { client.Dispose(); } } this.hosts.Reverse(); foreach (var host in this.hosts) { await host.StopAsync(); host.Dispose(); } }
private void OnStopping(object state) { IClusterClient clusterClient = state as IClusterClient; clusterClient?.Dispose(); }
private static void StopOrleansClient() { _log.Information("Stopping orleans client"); _orleansClient.Dispose(); _log.Warning("Orleans client stopped"); }
public async Task StopAsync(CancellationToken cancellationToken) { await client?.Close(); client?.Dispose(); }
public void Dispose() { siloV2?.Dispose(); siloV1?.Dispose(); client?.Dispose(); }
public void Dispose() => _client?.Dispose();
public async ValueTask DisposeAsync() { await clusterClient.Close().ConfigureAwait(false); clusterClient.Dispose(); }
public async Task StopAsync(CancellationToken cancellationToken) { await Client.Close(); Client.Dispose(); }
public void Dispose() { _clusterClient?.Dispose(); }