static async Task Main(string[] args) { var client = new ClientBuilder() .UseLocalhostClustering() .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory().WithCodeGeneration()) .Configure <SerializationProviderOptions>(options => { options.SerializationProviders.Add(typeof(ProtobufNetSerializer)); }) .Build(); await client.Connect(); Console.WriteLine("Connected."); Console.CancelKeyPress += async(sender, eventArgs) => await client.Close(); AssemblyLoadContext.Default.Unloading += async context => await client.Close(); var grain = client.GetGrain <IHelloGrain>(0); var response = await grain.SayAsync(new HelloRequest { Guid = Guid.NewGuid().ToString(), Messages = { new Message { Type = Message.MessageType.None, MessageValue = "powerumc" } } }); Console.WriteLine($"{response.From}: {response.Message}"); }
public async Task LocalhostSiloTest() { using var portAllocator = new TestClusterPortAllocator(); var(siloPort, gatewayPort) = portAllocator.AllocateConsecutivePortPairs(1); var silo = new SiloHostBuilder() .AddMemoryGrainStorage("MemoryStore") .UseLocalhostClustering(siloPort, gatewayPort) .Build(); var client = new ClientBuilder() .UseLocalhostClustering(gatewayPort) .Build(); try { await silo.StartAsync(); await client.Connect(); var grain = client.GetGrain <IEchoGrain>(Guid.NewGuid()); var result = await grain.Echo("test"); Assert.Equal("test", result); } finally { await OrleansTaskExtentions.SafeExecute(() => silo.StopAsync()); await OrleansTaskExtentions.SafeExecute(() => client.Close()); Utils.SafeExecute(() => silo.Dispose()); Utils.SafeExecute(() => client.Close()); } }
static async Task Main(string[] args) { var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory().WithCodeGeneration()) .UseLocalhostClustering() .AddSimpleMessageStreamProvider(StreamNames.PubSubProviderName) .Build(); await client.Connect(); Console.WriteLine("Connected."); Console.WriteLine("Send a message."); AssemblyLoadContext.Default.Unloading += async context => await client.Close(); Console.CancelKeyPress += async(sender, eventArgs) => await client.Close(); var grain = client.GetGrain <IHelloGrain>(0); var streamId = await grain.JoinAsync(); var streamProvider = client.GetStreamProvider(StreamNames.PubSubProviderName); var stream = streamProvider.GetStream <string>(streamId, StreamNames.HelloGrainNamespace); await stream.SubscribeAsync(new HelloGrainStreamObserver()); while (true) { var message = Console.ReadLine(); await grain.SayStreamAsync(message); } }
public async Task LocalhostSiloTest() { var opts = TestSiloSpecificOptions.Create(new TestClusterOptions(), 1, true); var silo = new SiloHostBuilder() .AddMemoryGrainStorage("MemoryStore") .UseLocalhostClustering(opts.SiloPort, opts.GatewayPort) .Build(); var client = new ClientBuilder() .UseLocalhostClustering(opts.GatewayPort) .Build(); try { await silo.StartAsync(); await client.Connect(); var grain = client.GetGrain <IEchoGrain>(Guid.NewGuid()); var result = await grain.Echo("test"); Assert.Equal("test", result); } finally { await OrleansTaskExtentions.SafeExecute(() => silo.StopAsync()); await OrleansTaskExtentions.SafeExecute(() => client.Close()); Utils.SafeExecute(() => silo.Dispose()); Utils.SafeExecute(() => client.Close()); } }
static void Main(string[] args) { // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); var silo = new SiloHost("TestSilo", siloConfig); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); //--------------------------------------------------------------------------------------- // Obtain a grain, invoke message and get result //--------------------------------------------------------------------------------------- var hw = client.GetGrain <IGrainGS>(0); Console.WriteLine(hw.HellowWorld().Result); Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }
static void Main(string[] args) { // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); var silo = new SiloHost("TestSilo", siloConfig); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); //HERE // var friend = client.GetGrain <ISayHello>(0); Console.WriteLine("\n\n{0}\n\n", friend.SayHelloMessage().Result); Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }
static async Task Main(string[] args) { var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory()) .UseLocalhostClustering() .Build(); await client.Connect(); AssemblyLoadContext.Default.Unloading += async context => await client.Close(); Console.WriteLine("Connected."); var grain = client.GetGrain <IHelloNotifyGrain>(0); var observerRef = await client.CreateObjectReference <IHelloNotifyGrainObserver>(new HelloNotifyGrainObserver()); await grain.SubscribeAsync(observerRef); while (true) { Console.WriteLine("Type a message."); var message = Console.ReadLine(); if (string.IsNullOrWhiteSpace(message)) { continue; } await grain.SendMessageAsync(message); } }
private static void test(int id, string msg = null) { // Then configure and connect a client. //var clientConfig = ClientConfiguration.LoadFromFile("ClientConfiguration.xml"); var clientConfig = ClientConfiguration.LocalhostSilo(); IClusterClient client = new ClientBuilder() .UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); if (string.IsNullOrEmpty(msg)) { Console.WriteLine("Write some msg."); msg = Console.ReadLine(); } GrainClient.Initialize(clientConfig); var friend = GrainClient.GrainFactory.GetGrain <IHello>(id); var result = friend.SayHello(msg).Result; Console.WriteLine(result); Chat c = new Chat(); var obj = GrainClient.GrainFactory.CreateObjectReference <IChat>(c).Result; friend.Subscribe(obj); friend.SendUpdateMessage("456"); client.Close(); }
static void Main(string[] args) { //var clientConfig = ClientConfiguration.LocalhostSilo(30000); var client = new ClientBuilder().LoadConfiguration("ClientConfiguration.xml").Build();//.UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); //GrainClient.Initialize(clientConfig); GrainClient.Initialize(); var nomnioGrain = GrainClient.GrainFactory.GetGrain <ICacheGrain>("nomnio.com"); Console.WriteLine("\n\n{0}\n\n", nomnioGrain.AddEmail("*****@*****.**").Result); Console.WriteLine("\n\n{0}\n\n", nomnioGrain.GetEmail("*****@*****.**").Result); Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); client.Close(); }
static async Task Main(string[] args) { var codeGenLogger = LoggerFactory.Create(builder => builder.AddConsole()); var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddApplicationPart(Assembly.GetExecutingAssembly()).WithCodeGeneration(codeGenLogger)) .UseLocalhostClustering() .Build(); await client.Connect(); Console.WriteLine("# All grains"); foreach (var activeGrain in await client.GetGrain <IManagementGrain>(0).GetActiveGrainTypes()) { Console.WriteLine($" - {activeGrain}"); } Console.WriteLine("--------------"); var grain = client.GetGrain <IHelloGrain>(0); var response = await grain.SayAsync(new HelloGrainRequest { TraceId = Guid.NewGuid(), Message = "HelloWorld" }); Console.WriteLine($"TraceId: {response.TraceId}"); Console.WriteLine($"Response Message: {response.ResponseMessage}"); Console.WriteLine($"Created DateTime: {response.CreatedDateTime}"); await client.Close(); }
static void Main(string[] args) { // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); var silo = new SiloHost("TestSilo", siloConfig); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); // // This is the place for your test code. // Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }
static async Task Main() { var client = new ClientBuilder() .UseLocalhostClustering() .Configure <ClusterOptions>(options => options.ClusterId = options.ServiceId = ClusterConstants.ServiceId) .Build(); var stop = false; Console.CancelKeyPress += (sender, args) => stop = true; using (client) { await client.Connect(); var grain = client.GetGrain <ISampleGrain>(0); var list = Enumerable.Range(0, 1 << 16) .Select(x => (byte)x) .ToList(); while (!stop) { await grain.GetSum(list); } await client.Close(); } }
private static async Task Main() { var client = new ClientBuilder() .UseLocalhostClustering() .ConfigureLogging(logging => { logging.AddConsole(); }) .AddOutkeep() .Build(); var logger = client.ServiceProvider.GetService <ILogger <Program> >(); logger.LogInformation("Connecting..."); await client.Connect(async e => { await Task.Delay(1000); logger.LogInformation("Retrying..."); return(true); }); logger.LogInformation("Connected"); var grain = client.GetCacheGrain(Guid.NewGuid().ToString()); // cache a value var value = Guid.NewGuid().ToByteArray(); logger.LogInformation("Setting value {Value}", value); await grain.SetAsync(value.AsImmutable(), null, null); // read the cached value var pulse = await grain.GetAsync(); logger.LogInformation("Received pulse (Tag = {Tag}, Value = {Value})", pulse.Tag, pulse.Value); // wait for the next value var task = grain.PollAsync(pulse.Tag); logger.LogInformation("Waiting for next pulse..."); // set the next value value = Guid.NewGuid().ToByteArray(); logger.LogInformation("Setting next value {Value}", value); await grain.SetAsync(value.AsImmutable(), null, null); // verify the wait pulse = await task; logger.LogInformation("Received reactive pulse (Tag = {Tag}, Value = {Value})", pulse.Tag, pulse.Value); await client.Close(); logger.LogInformation("Disconnected"); }
public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); var silo = new SiloHost("TestSilo", siloConfig); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); // var saludo = client.GetGrain <MergeInterface.IMergeSort>(Guid.NewGuid()); var resultado = ReadFileYeah(@"C: \Users\Chino Guzman\source\repos\DistributedMergeSort\oraciones.txt").ToList(); /*var valores = decoder(resultado); * var resultadofinal = MergeSort(saludo, 0, valores, 1, valores.Count); * foreach(List<int> x in resultadofinal) * { * Console.WriteLine(x[0]); * } * var valoresfinales = encoder(resultadofinal); * foreach (char[] x in valoresfinales) { * foreach (char hola in x) { * Console.Write(hola); * } * Console.WriteLine(""); * }*/ var yeah = MergeSort(saludo, resultado, 1, resultado.Count); foreach (string x in yeah) { Console.WriteLine(x); } Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }
static void Main(string[] args) { Metric.Config .WithHttpEndpoint("http://localhost:1234/client/") .WithAllCounters(); var clientConfig = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); // SMH: Specifying a key seems to be unnatural here... //Task.Run(async () => //{ // var guaranteedGrain = client.GetGrain<IGuaranteedGrain>("guaranteed"); // var msg = new Message("cms"); // var jsonMsg = JsonConvert.SerializeObject(msg); // while (true) // { // using (Metric.Timer("Guaranteed Request", Unit.Requests).NewContext()) // { // // SMH: Problem is that it takes approx 1/3 of a second before this task is finished. // await guaranteedGrain.ReceiveData(jsonMsg); // //await Task.Delay(1); // } // } //}).Wait(); Task.Run(async() => { var nonGuaranteedGrain = client.GetGrain <INonGuaranteedGrain>(0); var msg = new Message("opc"); var jsonMsg = JsonConvert.SerializeObject(msg); while (true) { using (Metric.Timer("Non-Guaranteed Request", Unit.Requests).NewContext()) { await nonGuaranteedGrain.ReceiveData(jsonMsg); //await Task.Delay(1); } } }).Wait(); Console.WriteLine("Press Enter to terminate..."); Console.ReadLine(); client.Close(); }
private async static Task TaskTest() { var clientConfig = ClientConfiguration.LocalhostSilo(); IClusterClient client = new ClientBuilder() .UseConfiguration(clientConfig).Build(); await client.Connect(); Console.WriteLine("Client connected."); await client.GetGrain <ITaskGrain>(0).MyGrainMethod(); await client.Close(); }
static void Main(string[] args) { // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); siloConfig.AddSimpleMessageStreamProvider(Common.Constants.InboundTransmissionStreamProvider); siloConfig.AddSimpleMessageStreamProvider(Common.Constants.OutboundTransmissionStreamProvider); var silo = new SiloHost("TestSilo", siloConfig); silo.Config.AddMemoryStorageProvider("PubSubStore"); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); clientConfig.AddSimpleMessageStreamProvider(Common.Constants.InboundTransmissionStreamProvider); clientConfig.AddSimpleMessageStreamProvider(Common.Constants.OutboundTransmissionStreamProvider); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); // // This is the place for your test code. // var transport = new Transport(); var inboundSubscription = transport.Received .Subscribe(datagram => client.InboundTransmissionStream(datagram.IpAddress).OnNextAsync(datagram)); var outboundSubscription = client.OutboundTransmissionStream() .SubscribeAsync((datagram, token) => transport.Send(datagram)) .Result; var connection = transport.Connect(); Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); Console.WriteLine("\nTerminating..."); inboundSubscription.Dispose(); outboundSubscription.UnsubscribeAsync().Wait(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }
static async Task Main(string[] args) { var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory().WithCodeGeneration()) .UseLocalhostClustering() .Build(); await client.Connect(); AssemblyLoadContext.Default.Unloading += async context => await client.Close(); var grain = client.GetGrain <IHelloGrain>(0); await grain.SayAsync("powerumc"); }
static void Main(string[] args) { // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); siloConfig.UseStartupType <TestStartup>(); // inject our custom service var silo = new SiloHost("TestSilo", siloConfig); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); // // This is the place for your test code. // var hiGrain = client.GetGrain <IHello>(0); var hiGrain1 = client.GetGrain <IHello>(1); var hiGrain2 = client.GetGrain <IHello>(2); Console.WriteLine("0."); hiGrain.SayHello("ss"); Console.WriteLine("1."); hiGrain1.SayHello("ss1"); Console.WriteLine("2."); hiGrain2.SayHello("ss2"); Console.WriteLine("3."); var result = hiGrain.SayHello("pik pik").Result; Console.WriteLine(result); Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }
static async Task Main(string[] args) { var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory()) .UseLocalhostClustering() .Build(); await client.Connect(); AssemblyLoadContext.Default.Unloading += async context => await client.Close(); await InterleavingTest1(client); Console.WriteLine(); await InterleavingTest2(client); }
private static async Task Main(string[] args) { using (SentrySdk.Init("https://[email protected]/216217")) { IClusterClient client = new ClientBuilder() .UseEnvironment(EnvironmentName.Development) .UseDynamoDBClustering((Action <DynamoDBGatewayOptions>)null) .Configure <NetworkingOptions>( options => options.OpenConnectionTimeout = TimeSpan.FromSeconds(10)) .ConfigureAppConfiguration( (context, configure) => configure .AddJsonFile( "appsettings.json", false) .AddJsonFile( $"appsettings.{context.HostingEnvironment.EnvironmentName}.json", true) .AddEnvironmentVariables() .AddCommandLine(args)) .ConfigureServices(Configure) .Build(); try { await client.Connect(); var gate = new Gate(client); await gate.Run(); var closeEvent = new AutoResetEvent(false); Console.CancelKeyPress += (sender, e) => { closeEvent.Reset(); }; closeEvent.WaitOne(); client.ServiceProvider.GetService <ILogger <Gate> >().LogInformation("stopping"); gate.Server.Stop(); await client.Close(); } catch (SiloUnavailableException) { client.ServiceProvider.GetService <ILogger <Gate> >().LogCritical("Silo connecting fails"); } catch (OrleansConfigurationException configurationException) { client.ServiceProvider.GetService <ILogger <Gate> >() .LogCritical(configurationException, "Configuration missing"); } } }
static void Main(string[] args) { Console.Title = nameof(Client); var client = new ClientBuilder() .UseLocalhostClustering() .ConfigureLogging(_ => { _.AddDebug(); }) .Build(); var logger = client.ServiceProvider.GetService <ILoggerProvider>().CreateLogger(typeof(Program).FullName); Console.WriteLine("Connecting..."); var retries = 100; client.Connect(async error => { if (--retries < 0) { logger.LogError("Could not connect to the cluster: {@Message}", error.Message); return(false); } else { logger.LogWarning(error, "Error Connecting: {@Message}", error.Message); } await Task.Delay(1000); return(true); }).Wait(); Console.WriteLine("Connected."); Console.CancelKeyPress += (sender, e) => { e.Cancel = true; client.Close().Wait(); Environment.Exit(0); }; new Shell(client) .RunAsync(client) .Wait(); }
public async Task LocalhostClusterTest() { using var portAllocator = new TestClusterPortAllocator(); var(baseSiloPort, baseGatewayPort) = portAllocator.AllocateConsecutivePortPairs(2); var silo1 = new HostBuilder().UseOrleans(siloBuilder => { siloBuilder .AddMemoryGrainStorage("MemoryStore") .UseLocalhostClustering(baseSiloPort, baseGatewayPort); }).Build(); var silo2 = new HostBuilder().UseOrleans(siloBuilder => { siloBuilder .AddMemoryGrainStorage("MemoryStore") .UseLocalhostClustering(baseSiloPort + 1, baseGatewayPort + 1, new IPEndPoint(IPAddress.Loopback, baseSiloPort)); }).Build(); var client = new ClientBuilder() .UseLocalhostClustering(new[] { baseGatewayPort, baseGatewayPort + 1 }) .Build(); try { await Task.WhenAll(silo1.StartAsync(), silo2.StartAsync()); await client.Connect(); var grain = client.GetGrain <IEchoGrain>(Guid.NewGuid()); var result = await grain.Echo("test"); Assert.Equal("test", result); } finally { var cancelled = new CancellationTokenSource(); cancelled.Cancel(); Utils.SafeExecute(() => silo1.StopAsync(cancelled.Token)); Utils.SafeExecute(() => silo2.StopAsync(cancelled.Token)); Utils.SafeExecute(() => silo1.Dispose()); Utils.SafeExecute(() => silo2.Dispose()); Utils.SafeExecute(() => client.Close()); Utils.SafeExecute(() => client.Dispose()); } }
static void Main(string[] args) { // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); var silo = new SiloHost("TestSilo", siloConfig); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); GrainClient.Initialize(ClientConfiguration.LocalhostSilo()); var grain = GrainClient.GrainFactory.GetGrain <IGIFSGrain>(1); //Se define el objeto objRemoto para referenciar el grain de la interfaz IGIFSGrain del SILO //IGIFSGrain objRemoto = client.GetGrain<IGIFSGrain>(1); //Definimos el DataSet oDS y registramos en el mismo, el DataSet de noticias de la cache, que se //obtiene del método "LeerNoticias", declarado en el SILO grain.CargarGIFSALaCache().Wait(); DataSet oDS = grain.LeerGIFSDesdeLaCache().Result; Console.WriteLine(oDS.Tables.Count.ToString()); // // This is the place for your test code. // Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }
static void Main(string[] args) { // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); var silo = new SiloHost("TestSilo", siloConfig); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); clientConfig.SerializationProviders.Add(typeof(Orleans.Serialization.BondSerializer).GetTypeInfo()); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); // // This is the place for your test code. // //var xxxx = new ClientConfiguration(); //xxxx.GatewayProvider = ClientConfiguration.GatewayProviderType.None; //xxxx.Gateways.Add(new System.Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 40000)); //GrainClient.Initialize(xxxx); //var gw = GrainClient.GrainFactory.GetGrain<IGateway>("gw1"); //var succ = gw.Start().Result; //initThrift(gw); Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }
static void Main(string[] args) { // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); var silo = new SiloHost("TestSilo", siloConfig); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); // // This is the place for your test code. // Console.WriteLine("Step1"); var grain = client.GetGrain <IStockGrain>("MSFT"); Console.WriteLine("Step2"); var price = grain.GetPrice().Result; Console.WriteLine("Step3"); Console.WriteLine("P:" + price.ToString()); //输出结果:先输出 Step1 step2,过10s过后输出Step3 //因为StockGrain的OnActivateAsync是异步函数,所有GetGrain会快速返回。 //StockGrain只有处理完OnActivateAsync函数过后,才会处理GetPrice. Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }
static void Main(string[] args) { // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); var silo = new SiloHost("TestSilo", siloConfig); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); int numberOfGrains = 200; var tasks = new Task[numberOfGrains]; for (int i = 0; i < numberOfGrains; i++) { var friend = client.GetGrain <IGrain1>(i); Task <string> task = friend.SayHello(); var taskId = i; task.ContinueWith(helloTask => { Console.WriteLine($"{taskId}: {helloTask.Result}"); }); tasks[i] = task; } Task.WaitAll(tasks); Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }
static async Task Main(string[] args) { var client = new ClientBuilder() .ConfigureServices(services => { services.AddSingleton <IOutgoingGrainCallFilter, GrainLoggingOutgoingCallFilter>(); }) .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory().WithCodeGeneration()) .UseLocalhostClustering() .Build(); await client.Connect(); Console.WriteLine("Connected"); var grain = client.GetGrain <IHelloGrain>(0); var message = await grain.SayAsync("powerumc"); Console.WriteLine(message); await client.Close(); }
public async Task LocalhostClusterTest() { var silo1 = new SiloHostBuilder() .AddMemoryGrainStorage("MemoryStore") .UseLocalhostClustering(12111, 30001) .Build(); var silo2 = new SiloHostBuilder() .AddMemoryGrainStorage("MemoryStore") .UseLocalhostClustering(12112, 30002, new IPEndPoint(IPAddress.Loopback, 12111)) .Build(); var client = new ClientBuilder() .UseLocalhostClustering(new[] { 30001, 30002 }) .Build(); try { await Task.WhenAll(silo1.StartAsync(), silo2.StartAsync()); await client.Connect(); var grain = client.GetGrain <IEchoGrain>(Guid.NewGuid()); var result = await grain.Echo("test"); Assert.Equal("test", result); } finally { var cancelled = new CancellationTokenSource(); cancelled.Cancel(); Utils.SafeExecute(() => silo1.StopAsync(cancelled.Token)); Utils.SafeExecute(() => silo2.StopAsync(cancelled.Token)); Utils.SafeExecute(() => silo1.Dispose()); Utils.SafeExecute(() => silo2.Dispose()); Utils.SafeExecute(() => client.Close()); Utils.SafeExecute(() => client.Dispose()); } }
static void Main(string[] args) { var config = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder() .LoadConfiguration("../../ClientConfiguration.xml") .Build(); client.Connect().Wait(); Console.WriteLine("Press number or x [Enter] to terminate..."); string nextCommand = ""; while (!(nextCommand.ToUpperInvariant() == "X")) { nextCommand = Console.ReadLine(); var grain = client.GetGrain <ITalkativeGrain>("Grain-" + nextCommand); grain.Talk("Grain-" + nextCommand); } client.Close(); client.Dispose(); }