本文整理汇总了C#中ActorSystem.Shutdown方法的典型用法代码示例。如果您正苦于以下问题:C# ActorSystem.Shutdown方法的具体用法?C# ActorSystem.Shutdown怎么用?C# ActorSystem.Shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActorSystem
的用法示例。
在下文中一共展示了ActorSystem.Shutdown方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Akka prefers creation of objects via factories
// this is due to the fact that internally Akka does a lot of system internally
UntypedActorSystem = ActorSystem.Create("UntypedActorSystem");
Console.WriteLine("Actor system created");
// Akka uses the movie industry to name a few items
// To create an Actor you use the Props class
Props whatsMyTypeAgainProps = Props.Create<WhatsMyTypeAgainActor>();
// ActorOf will create the Actor
// You can get a reference to the Actor using the ActorOf which returns an IActorRef
UntypedActorSystem.ActorOf(whatsMyTypeAgainProps, "WhatsMyTypeAgain");
// Alternatively you can use ActorSelection and a path to the Actor
ActorSelection whatsMyTypeAgainActor = UntypedActorSystem.ActorSelection("/user/WhatsMyTypeAgain");
// Tell is void
whatsMyTypeAgainActor.Tell("I'm 30");
// Ask with return a value (request response)
var askTask = whatsMyTypeAgainActor.Ask<int>("Hey what's my age again?");
Task.WaitAll(askTask);
Console.WriteLine(askTask.Result);
Console.ReadKey();
UntypedActorSystem.Shutdown();
UntypedActorSystem.AwaitTermination();
}
示例2: Main
static void Main(string[] args)
{
// Akka prefers creation of objects via factories
// this is due to the fact that internally Akka does a lot of system internally
ReceiveActorSystem = ActorSystem.Create("ReceiveActorSystem");
Console.WriteLine("Actor system created");
// Akka uses the movie industry to name a few items
// To create an Actor you use the Props class
Props whatsMyTypeAgainProps = Props.Create<WhatsMyTypeAgainActor>();
// ActorOf will create the Actor
// You can get a reference to the Actor using the ActorOf which returns an IActorRef
ReceiveActorSystem.ActorOf(whatsMyTypeAgainProps, "WhatsMyTypeAgain");
// Alternatively you can use ActorSelection and a path to the Actor
ActorSelection whatsMyTypeAgainActor = ReceiveActorSystem.ActorSelection("/user/WhatsMyTypeAgain");
// Tell is void
whatsMyTypeAgainActor.Tell("I'm 30");
whatsMyTypeAgainActor.Tell("I'm 31"); // This message is ignored since the Actor's behavior has changed
whatsMyTypeAgainActor.Tell(30);
Console.ReadKey();
ReceiveActorSystem.Shutdown();
ReceiveActorSystem.AwaitTermination();
Console.ReadKey();
}
示例3: Main
private static void Main()
{
ConfigureLogging();
LogTo.Debug($"Creating ActorSystem '{ActorSystemName}'.");
_actorSystem = ActorSystem.Create(ActorSystemName);
LogTo.Debug($"Creating Props '{nameof(ProductsActor)}'.");
var props = Props.Create<ProductsActor>();
LogTo.Debug($"Creating ActorOf '{nameof(ProductsActor)}'.");
var products = _actorSystem.ActorOf(props);
LogTo.Information("Adding products.");
products.Tell(new AddProduct("Product 1"));
products.Tell(new AddProduct("Product 2"));
LogTo.Debug("Stopping products actor.");
products.GracefulStop(TimeSpan.FromMinutes(1)).Wait();
LogTo.Debug("Stopped products actor.");
LogTo.Debug("Shutting down ActorSystem");
_actorSystem.Shutdown();
LogTo.Debug("Waiting for ActorSystem to complete shutdown.");
_actorSystem.AwaitTermination();
LogTo.Information("Finished shopping :-)");
}
示例4: Main
private static void Main(string[] args)
{
_actorSystem = ActorSystem.Create("OrderSystem");
var prop = Props.Create<PlaceOrderHandlerActor>();
var aref = _actorSystem.ActorOf(prop, "OrderHandlerActor");
aref.Tell(
new PlaceOrderMessage(
"Shuhel",
"Sylhet",
new List<string>
{
"Chicken Tickka",
"Chicken Chowmeen",
"Pepsi"
}));
Console.ReadLine();
Console.WriteLine("The system shutting down..");
_actorSystem.Shutdown();
_actorSystem.AwaitTermination();
Console.WriteLine("The system is dead");
Console.ReadLine();
}
示例5: Main
static void Main(string[] args)
{
MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem2");
Console.WriteLine("Actor system created.");
Props props = Props.Create<PlaybackActor>();
IActorRef actorRef = MovieStreamingActorSystem.ActorOf(props, "PlaybackActor");
actorRef.Tell(new PlayMovieMessage("Akka.NET: The Movie", 42));
actorRef.Tell(new PlayMovieMessage("Partial Recall", 99));
actorRef.Tell(new PlayMovieMessage("Boolean Lies", 77));
actorRef.Tell(new PlayMovieMessage("Codenan the Destroyer", 1));
actorRef.Tell(PoisonPill.Instance);
//Console.WriteLine("Press any key to start the shutdown of the system");
Console.ReadKey();
// Tell actor system (and all child actors) to shutdown
MovieStreamingActorSystem.Shutdown();
// Wait for actor system to finish shutting down
MovieStreamingActorSystem.AwaitTermination();
Console.WriteLine("Actor system has shutdown");
Console.ReadKey();
}
示例6: Main
private static void Main(string[] args)
{
_movieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem");
Console.WriteLine(string.Format("{0} started...", _movieStreamingActorSystem.Name));
var playbackActorProps = Props.Create<PlaybackActor>();
var playbackActorRef = _movieStreamingActorSystem.ActorOf(playbackActorProps, "Playback");
do
{
ShortPause();
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkGray;
ColorConsole.WriteLineGray("Enter a command and hit enter");
var command = Console.ReadLine();
if (command.StartsWith("play"))
{
var userId = int.Parse(command.Split(',')[1]);
var movieTitle = command.Split(',')[2];
var message = new PlayMovieMessage(movieTitle, userId);
_movieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
}
if (command.StartsWith("stop"))
{
var userId = int.Parse(command.Split(',')[1]);
var message = new StopMovieMessage(userId);
_movieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
}
if (command == "exit")
{
_movieStreamingActorSystem.Shutdown();
_movieStreamingActorSystem.AwaitTermination();
ColorConsole.WriteLineGray("Actor system shutdown");
Console.ReadKey();
Environment.Exit(1);
}
} while (true);
}
示例7: Benchmark
private static bool Benchmark(int numberOfClients)
{
var repeatFactor = 500;
var repeat = 30000L * repeatFactor;
var repeatsPerClient = repeat / numberOfClients;
var system = new ActorSystem("PingPong");
var clients = new List<ActorRef>();
var tasks = new List<Task>();
for (int i = 0; i < numberOfClients; i++)
{
var destination = system.ActorOf<Destination>();
var ts = new TaskCompletionSource<bool>();
tasks.Add(ts.Task);
var client = system.ActorOf(Props.Create(() => new Client(destination,repeatsPerClient,ts)));
clients.Add(client);
}
clients.ForEach(c => c.Tell(Run));
var sw = Stopwatch.StartNew();
Task.WaitAll(tasks.ToArray());
sw.Stop();
var totalMessagesReceived = repeat * 2; //times 2 since the client and the destination both send messages
system.Shutdown();
long throughput = totalMessagesReceived / sw.ElapsedMilliseconds * 1000;
if (throughput > bestThroughput)
{
Console.ForegroundColor = ConsoleColor.Green;
bestThroughput = throughput;
redCount = 0;
}
else
{
redCount++;
Console.ForegroundColor = ConsoleColor.Red;
}
Console.WriteLine("{0}, {1} messages/s", numberOfClients * 2, throughput);
if (redCount > 3)
return false;
return true;
}
示例8: Main
static void Main(string[] args)
{
ColorConsole.WriteLineGray("Creating MovieStreamingActorSystem");
MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem");
Console.WriteLine("Actor system created.");
ColorConsole.WriteLineGray("Creating actor supervisory hierarchy");
MovieStreamingActorSystem.ActorOf(Props.Create<PlaybackActor>(), "Playback");
do
{
ShortPause();
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkGray;
ColorConsole.WriteLineGray("Enter a command and hit enter");
var command = Console.ReadLine();
if (command.StartsWith("play"))
{
int userId = int.Parse(command.Split(',')[1]);
string movieTitle = command.Split(',')[2];
var message = new PlayMovieMessage(movieTitle, userId);
MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
}
if (command.StartsWith("stop"))
{
int userId = int.Parse(command.Split(',')[1]);
var message = new StopMovieMessage(userId);
MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
}
if (command.StartsWith("exit"))
{
MovieStreamingActorSystem.Shutdown();
MovieStreamingActorSystem.AwaitTermination();
ColorConsole.WriteLineGray("Actor system shutdown");
Console.ReadKey();
Environment.Exit(1);
}
} while (true);
}
示例9: Main
static void Main(string[] args)
{
using (system = ActorSystem.Create("akka-performance-demo"))
{
var registeredMonitor = ActorMonitoringExtension.RegisterMonitor(system, new Monitor());
IWindsorContainer container = new WindsorContainer();
container.Register( Component.For<IInterceptor>().
ImplementedBy<MonitorInterceptor>().
Named("monitorInterceptor"),
Component.For<HelloActor>().
LifestyleTransient().
Interceptors(InterceptorReference.ForKey("monitorInterceptor")).
Anywhere);
WindsorDependencyResolver propsResolver =
new WindsorDependencyResolver(container, system);
var hello = system.ActorOf(propsResolver.Create<HelloActor>(), "Worker1");
hello.Tell("What's Up");
hello.Tell("Goodbye");
var count = 20;
while (count >= 0)
{
ActorMonitoringExtension.Monitors(system).IncrementDebugsLogged();
Console.WriteLine("Logging debug...");
Thread.Sleep(100);
count--;
}
while (ManualResetEvent.WaitOne())
{
Console.WriteLine("Shutting down...");
system.Shutdown();
Console.WriteLine("Shutdown complete");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
return;
}
}
}
示例10: Shutdown
/// <summary>
/// Shuts down the specified system.
/// On failure debug output will be logged about the remaining actors in the system.
/// If verifySystemShutdown is true, then an exception will be thrown on failure.
/// </summary>
/// <param name="system">The system to shutdown.</param>
/// <param name="duration">The duration to wait for shutdown. Default is 5 seconds multiplied with the config value "akka.test.timefactor"</param>
/// <param name="verifySystemShutdown">if set to <c>true</c> an exception will be thrown on failure.</param>
protected virtual void Shutdown(ActorSystem system, TimeSpan? duration = null, bool verifySystemShutdown = false)
{
if(system == null) system = _system;
var durationValue = duration.GetValueOrDefault(Dilated(TimeSpan.FromSeconds(5)).Min(TimeSpan.FromSeconds(10)));
system.Shutdown();
var wasShutdownDuringWait = system.AwaitTermination(durationValue);
if(!wasShutdownDuringWait)
{
const string msg = "Failed to stop [{0}] within [{1}] \n{2}";
if(verifySystemShutdown)
throw new Exception(string.Format(msg, system.Name, durationValue, ""));
//TODO: replace "" with system.PrintTree()
system.Log.Warning(msg, system.Name, durationValue, ""); //TODO: replace "" with system.PrintTree()
}
}
示例11: Main
static void Main (string [] args)
{
var system = new ActorSystem ();
Test2 (system);
Console.ReadKey ();
system.Shutdown ();
Console.ReadKey ();
}
示例12: Main
static void Main(string[] args)
{
ResizerActors = ActorSystem.Create("ResizerActors");
var commanderActor = ResizerActors.ActorOf(Props.Create(() => new CommanderActor()));
var imagePath = args[0];
var profileDictionary = new Dictionary<string, int>
{
{ "Icon-40.png", 40 },
{ "Icon-40-2x.png", 80 },
{ "Icon-60.png", 60 },
{ "Icon-60-2x.png", 60 },
{"Icon-72.png",72},
{"Icon-72-2x.png",144},
{"Icon-76.png",76},
{"Icon-76-2x.png", 152},
{"Icon-Small-50.png", 50},
{ "Icon-Small-50-2x.png", 100},
{ "Icon-Small.png", 29},
{ "Icon-Small-2x.png", 58},
{ "Icon.png", 57},
{ "Icon-2x.png", 114},
{ "iTunesArtwork.png", 512},
{ "iTunesArtwork-2x.png", 1024},
{ "Icon-16.png", 16},
{ "Icon-24.png", 24},
{ "Icon-32.png", 32},
{ "Icon-64.png", 64},
{ "Icon-120.png", 120},
{ "Icon-152.png", 152},
{ "Icon-Small-40.png", 40},
{ "Icon-Small-40-2x.png", 80},
{ "Icon-60-3x.png", 180},
{ "Icon-Small-3x.png", 87},
{ "Icon-Small-40-3x.png", 120}
};
//var allTasks = profileDictionary.Keys.Select(key =>
//{
// return Task<Tuple<string, Stream>>.Factory.StartNew(() => Save(new Bitmap(imagePath), profileDictionary[key], profileDictionary[key], 1, key));
//});
//Task.WaitAll(allTasks.ToArray());
//var results = allTasks.Select(x => x.Result).ToArray();
//CreateToMemoryStream(results, "test.zip");
byte[] originalImage;
using (var fs = File.OpenRead(imagePath))
{
originalImage = new byte[fs.Length];
fs.Read(originalImage, 0, (int)fs.Length);
}
//coordinatorActor.Tell(new CoordinatorActor.ResizeImage(originalImage, profileDictionary, "test.zip"));
var command = Console.ReadLine();
while(command == "")
{
//Task.Run(() => {
// Parallel.For(0, 10, index => {
// //var coordinatorActor = ResizerActors.ActorOf(Props.Create(() => new CoordinatorActor()));
// commanderActor.Tell(new CoordinatorActor.ResizeImage(originalImage, profileDictionary, string.Format("{0}.zip", Guid.NewGuid())));
// });
//});
commanderActor.Tell(new CoordinatorActor.ResizeImage(originalImage, profileDictionary, string.Format("{0}.zip", Guid.NewGuid())));
command = Console.ReadLine();
}
ResizerActors.Shutdown();
ResizerActors.Dispose();
}
示例13: Main
static void Main(string[] args)
{
//making a change to trigger GitHub
//desktop app.
AkkaStreamingActorSystem = ActorSystem.Create("AkkaStreamingActorSystem");
Console.WriteLine("Actor System was Created named AkkaStreamingActorSystem.");
//need props
//use the factory generic
//props control env and other details.
//Props playbackActorProps = Props.Create<PlaybackActor>();
//common ref
//the second param is optional (you'll get a name if you don't give it one).
//so far what we have is a glorified new - the details are under the covers, lot of arch hiding there
//IActorRef playbackActorRef = AkkaStreamingActorSystem.ActorOf(playbackActorProps, "PlaybackActor");
//update to program
Props userActorProps = Props.Create<UserActor>();
IActorRef userActorRef = AkkaStreamingActorSystem.ActorOf(userActorProps, "UserActor");
//SEND SOME MESSAGES
//playbackActorRef.Tell("Scott the Movie");
//playbackActorRef.Tell(1234);
//playbackActorRef.Tell('C'); //unhandled
Console.ReadKey();
Console.WriteLine("Sending a Playmoviemessage (Scooter's Big Big Movie)");
userActorRef.Tell(new PlayMovieMessage("Scooter's Big Big Movie", 1234));
Console.ReadKey();
Console.WriteLine("Sending a Playmoviemessage (Scooter's Big Big Movie II)");
userActorRef.Tell(new PlayMovieMessage("Scooter's Big Big Movie II", 25));
Console.ReadKey();
Console.WriteLine("Sending a StopMovieMessage");
userActorRef.Tell(new StopMovieMessage());
Console.ReadKey();
Console.WriteLine("Sending another StopMovieMessage");
userActorRef.Tell(new StopMovieMessage());
/* playbackActorRef.Tell(new PlayMovieMessage("Scooter's Big Big Movie", 1234));
playbackActorRef.Tell(new PlayMovieMessage("Scooter's Big Big Movie II", 25)); //shouldn't catch this one because of the predicate
playbackActorRef.Tell(new PlayMovieMessage("Scooter's Big Big Movie III", 68));
playbackActorRef.Tell(new PlayMovieMessage("Scooter's Not So Big Movie", 15)); */
//poison pill
//after, so it will finish the four messages
//triggers playbackactors's poststop
//playbackActorRef.Tell(PoisonPill.Instance);
Console.ReadKey();
AkkaStreamingActorSystem.Shutdown();
AkkaStreamingActorSystem.AwaitTermination(); //pauses main thread until actor system shut down complete
Console.WriteLine("Actor System Shutdown");
Console.ReadKey();
}