本文整理汇总了C#中ActorSystem.ActorOf方法的典型用法代码示例。如果您正苦于以下问题:C# ActorSystem.ActorOf方法的具体用法?C# ActorSystem.ActorOf怎么用?C# ActorSystem.ActorOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActorSystem
的用法示例。
在下文中一共展示了ActorSystem.ActorOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// initialize MyActorSystem
MyActorSystem = ActorSystem.Create("MyActorSystem");
// time to make your first actors!
var consoleWriterActor = MyActorSystem.ActorOf(Props.Create<ConsoleWriterActor>(), "MyConsoleWriter"); // Generic syntax
// make tailCoordinatorActor
Props tailCoordinatorProps = Props.Create(() => new TailCoordinatorActor());
var tailCoordinatorActor = MyActorSystem.ActorOf(tailCoordinatorProps, "tailCoordinatorActor");
// pass tailCoordinatorActor to fileValidatorActorProps (just adding one extra arg)
Props fileValidatorActorProps = Props.Create(() => new FileValidatorActor(consoleWriterActor));
var validationActor = MyActorSystem.ActorOf(fileValidatorActorProps, "validationActor");
var consoleReaderActor = MyActorSystem.ActorOf(Props.Create(() => new ConsoleReaderActor()), "MyConsoleReader");
// tell console reader to begin
consoleReaderActor.Tell(ConsoleReaderActor.StartCommand);
// Fake start with
validationActor.Tell(@"c:\MyFile.txt");
// blocks the main thread from exiting until the actor system is shut down
MyActorSystem.AwaitTermination();
}
示例2: Main
private static void Main(string[] args)
{
_actorSystem = ActorSystem.Create("TestSystem");
// have a separate actor to write transition changes to the console
var consoleWriter = _actorSystem.ActorOf(Props.Create(() => new ConsoleWriter()), "consoleWriter");
var chopsticks = new List<IActorRef>();
// Create 5 chopsticks
for (int i = 0; i < 5; i++)
{
var chopstick = _actorSystem.ActorOf(Props.Create(() => new Chopstick(_actorSystem)), "chopstick" + i);
chopsticks.Add(chopstick);
}
// Create 5 philosophers and assign them their left and right chopstick
var philosophers = new List<IActorRef>();
var names = new List<string>() {"Aristotle", "Plato", "Locke", "Socrates", "Marx"};
for (int i = 0; i < names.Count; i++)
{
var leftChopstick = chopsticks[i];
var rightChopstick = i == 4 ? chopsticks[0] : chopsticks[i + 1];
var philosopher = _actorSystem.ActorOf(Props.Create(() => new Philosopher(names[i],leftChopstick,rightChopstick)), names[i]);
philosophers.Add(philosopher);
// subscribe the console writer to receive state change transitions
philosopher.Tell(new FSMBase.SubscribeTransitionCallBack(consoleWriter));
}
foreach (var philosopher in philosophers)
{
philosopher.Tell(new Think());
}
Console.ReadLine();
}
示例3: MainWindow_Loaded
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
system = ActorSystem.Create("MyClientSystem");
serverActor = system.ActorSelection("akka.tcp://[email protected]:8081/user/MyServerActor");
uiActor = system.ActorOf(Props.Create(() => new UIActor(this.textBox)), "MyClient");
clientActor = system.ActorOf(Props.Create(() => new ClientActor(serverActor, uiActor)), Guid.NewGuid().ToString());
}
示例4: Main
static void Main(string[] args)
{
// initialize MyActorSystem
// YOU NEED TO FILL IN HERE
MyActorSystem = ActorSystem.Create("MyActorSystem");
// time to make your first actors!
var consoleWriterProps = Props.Create(() => new ConsoleWriterActor());
var consoleWriterActor = MyActorSystem.ActorOf(consoleWriterProps, "consoleWriterActor");
var tailCoordinatorActor = MyActorSystem.ActorOf(Props.Create<TailCoordinatorActor>(), "tailCoordinatorActor");
var validationActorProps = Props.Create(() => new FileValidatorActor(consoleWriterActor));
var validationActor = MyActorSystem.ActorOf(validationActorProps, "validationActor");
var consoleReaderProps = Props.Create<ConsoleReaderActor>();
var readerActor = MyActorSystem.ActorOf(consoleReaderProps, "consoleReaderActor");
// tell console reader to begin
//YOU NEED TO FILL IN HERE
readerActor.Tell(ConsoleReaderActor.StartCommand);
// blocks the main thread from exiting until the actor system is shut down
MyActorSystem.AwaitTermination();
}
示例5: Main
static void Main(string[] args)
{
// make an actor system
MyActorSystem = ActorSystem.Create("MyActorSystem");
// this is here to show you what NOT to do
// this approach to props has no type safety
// it will compile, but can easily blow up in your face at runtime :(
// UNCOMMENT THE BELOW TWO LINES, BUILD THE SOLUTION, AND THEN TRY TO RUN IT TO SEE
//Props fakeActorProps = Props.Create(typeof(FakeActor));
//IActorRef fakeActor = MyActorSystem.ActorOf(fakeActorProps, "fakeActor");
// set up actors, using props (split props onto own line so easier to read)
Props consoleWriterProps = Props.Create<ConsoleWriterActor>();
IActorRef consoleWriterActor = MyActorSystem.ActorOf(consoleWriterProps, "consoleWriterActor");
Props validationActorProps = Props.Create(() => new ValidationActor(consoleWriterActor));
IActorRef validationActor = MyActorSystem.ActorOf(validationActorProps, "validationActor");
Props consoleReaderProps = Props.Create<ConsoleReaderActor>(validationActor);
IActorRef consoleReaderActor = MyActorSystem.ActorOf(consoleReaderProps, "consoleReaderActor");
// tell console reader to begin
consoleReaderActor.Tell(ConsoleReaderActor.StartCommand);
// blocks the main thread from exiting until the actor system is shut down
MyActorSystem.AwaitTermination();
}
示例6: CreateGateway
public static Server.GatewayRef CreateGateway(ActorSystem system, ChannelType type, string name, IPEndPoint endPoint,
XunitOutputLogger.Source outputSource,
Action<Server.GatewayInitiator> clientInitiatorSetup = null)
{
// initialize gateway initiator
var initiator = new Server.GatewayInitiator()
{
GatewayLogger = new XunitOutputLogger($"Gateway({name})", outputSource),
ListenEndPoint = endPoint,
ConnectEndPoint = endPoint,
TokenRequired = false,
CreateChannelLogger = (_, o) => new XunitOutputLogger($"ServerChannel({name})", outputSource),
CheckCreateChannel = (_, o) => true,
ConnectionSettings = new Server.TcpConnectionSettings { PacketSerializer = s_serverSerializer },
PacketSerializer = s_serverSerializer,
};
clientInitiatorSetup?.Invoke(initiator);
// create gateway and start it
var gateway = (type == ChannelType.Tcp)
? system.ActorOf(Props.Create(() => new Server.TcpGateway(initiator))).Cast<Server.GatewayRef>()
: system.ActorOf(Props.Create(() => new Server.UdpGateway(initiator))).Cast<Server.GatewayRef>();
gateway.Start().Wait();
return gateway;
}
示例7: StartGateway
private static GatewayRef StartGateway(ActorSystem system, ChannelType type, int port)
{
var serializer = PacketSerializer.CreatePacketSerializer();
var initiator = new GatewayInitiator
{
ListenEndPoint = new IPEndPoint(IPAddress.Any, port),
GatewayLogger = LogManager.GetLogger("Gateway"),
CreateChannelLogger = (ep, _) => LogManager.GetLogger($"Channel({ep}"),
ConnectionSettings = new TcpConnectionSettings { PacketSerializer = serializer },
PacketSerializer = serializer,
CreateInitialActors = (context, connection) => new[]
{
Tuple.Create(context.ActorOf(Props.Create(() => new EntryActor(context.Self.Cast<ActorBoundChannelRef>()))),
new TaggedType[] { typeof(IEntry) },
(ActorBindingFlags)0)
}
};
var gateway = (type == ChannelType.Tcp)
? system.ActorOf(Props.Create(() => new TcpGateway(initiator))).Cast<GatewayRef>()
: system.ActorOf(Props.Create(() => new UdpGateway(initiator))).Cast<GatewayRef>();
gateway.Start().Wait();
return gateway;
}
示例8: Main
static void Main(string[] args)
{
// initialize MyActorSystem
MyActorSystem = ActorSystem.Create("MyActorSystem");
// time to make your first actors!
Props consoleWriterProps = Props.Create<ConsoleWriterActor>();
IActorRef consoleWriterActor = MyActorSystem.ActorOf(consoleWriterProps, "consoleWriterActor");
Props tailCoordinatorProps = Props.Create(() => new TailCoordinatorActor());
IActorRef tailCoordinatorActor = MyActorSystem.ActorOf(tailCoordinatorProps, "tailCoordinatorActor");
Props fileValidatorActorProps = Props.Create(() => new FileValidatorActor(consoleWriterActor));
IActorRef validationActor = MyActorSystem.ActorOf(fileValidatorActorProps, "validationActor");
Props consoleReaderProps = Props.Create<ConsoleReaderActor>();
IActorRef consoleReaderActor = MyActorSystem.ActorOf(consoleReaderProps, "consoleReaderActor");
// tell console reader to begin
consoleReaderActor.Tell(ConsoleReaderActor.StartCommand);
// blocks the main thread from exiting until the actor system is shut down
MyActorSystem.AwaitTermination();
}
示例9: Main
static void Main(string[] args)
{
var config =
ConfigurationFactory.ParseString(
File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "akka.config")));
// make actor system
MyActorSystem = ActorSystem.Create("MyActorSystem", config);
// create top-level actors within the actor system
Props consoleWriterProps = Props.Create<ConsoleWriterActor>();
IActorRef consoleWriterActor = MyActorSystem.ActorOf(consoleWriterProps, "consoleWriterActor");
Props tailCoordinatorProps = Props.Create(() => new TailCoordinatorActor());
IActorRef tailCoordinatorActor = MyActorSystem.ActorOf(tailCoordinatorProps, "tailCoordinatorActor");
Props fileValidatorActorProps = Props.Create(() => new FileValidatorActor(consoleWriterActor));
IActorRef fileValidatorActor = MyActorSystem.ActorOf(fileValidatorActorProps, "validationActor");
Props consoleReaderProps = Props.Create<ConsoleReaderActor>();
IActorRef consoleReaderActor = MyActorSystem.ActorOf(consoleReaderProps, "consoleReaderActor");
// begin processing
consoleReaderActor.Tell(ConsoleReaderActor.StartCommand);
// blocks the main thread from exiting until the actor system is shut down
MyActorSystem.AwaitTermination();
}
示例10: AtLeastOnceDelivery
private static void AtLeastOnceDelivery(ActorSystem system)
{
Console.WriteLine("\n--- AT LEAST ONCE DELIVERY EXAMPLE ---\n");
var delivery = system.ActorOf(Props.Create(()=> new DeliveryActor()),"delivery");
var deliverer = system.ActorOf(Props.Create(() => new AtLeastOnceDeliveryExampleActor(delivery.Path)));
delivery.Tell("start");
deliverer.Tell(new Message("foo"));
System.Threading.Thread.Sleep(1000); //making sure delivery stops before send other commands
delivery.Tell("stop");
deliverer.Tell(new Message("bar"));
Console.WriteLine("\nSYSTEM: Throwing exception in Deliverer\n");
deliverer.Tell("boom");
System.Threading.Thread.Sleep(1000);
deliverer.Tell(new Message("bar1"));
Console.WriteLine("\nSYSTEM: Enabling confirmations in 3 seconds\n");
System.Threading.Thread.Sleep(3000);
Console.WriteLine("\nSYSTEM: Enabled confirmations\n");
delivery.Tell("start");
}
示例11: Main
static void Main(string[] args)
{
// initialize MyActorSystem
MyActorSystem = ActorSystem.Create("MyActorSystem");
// DEMO to show that typeof() is valid but dangerous
//Props fakeActorProps = Props.Create(typeof(FakeActor));
//IActorRef fakeActor = MyActorSystem.ActorOf(fakeActorProps, "fakeActor");
Props consoleWriterProps = Props.Create<ConsoleWriterActor>();
IActorRef consoleWriterActor = MyActorSystem.ActorOf(consoleWriterProps, "consoleWriterActor");
Props tailCoordinatorActorProps = Props.Create(() => new TailCoordinatorActor());
IActorRef tailCoordinatorActor = MyActorSystem.ActorOf(tailCoordinatorActorProps, "tailCoordinatorActor");
// pass tailCoordinatorActor to fileValidatorActorProps (just adding one extra arg)
Props fileValidatorActorProps = Props.Create(() => new FileValidatorActor(consoleWriterActor));
IActorRef validationActor = MyActorSystem.ActorOf(fileValidatorActorProps, "validationActor");
Props consoleReaderProps = Props.Create<ConsoleReaderActor>();
IActorRef consoleReaderActor = MyActorSystem.ActorOf(consoleReaderProps, "consoleReaderActor");
// tell console reader to begin
consoleReaderActor.Tell(ConsoleReaderActor.StartCommand);
// blocks the main thread from exiting until the actor system is shut down
MyActorSystem.AwaitTermination();
Console.ReadKey();
}
示例12: Main
static void Main(string[] args)
{
// initialize MyActorSystem
MyActorSystem = ActorSystem.Create("MyActorSystem");
// make consoleWriterActor
var consoleWriterProps = Props.Create(() => new ConsoleWriterActor());
var consoleWriterActor = MyActorSystem.ActorOf(consoleWriterProps, "consoleWriterActor");
// make tailCoordinatorActor
var tailCoordinatorProps = Props.Create(() => new TailCoordinatorActor());
var tailCoordinatorActor = MyActorSystem.ActorOf(tailCoordinatorProps, "tailCoordinatorActor");
// make fileValidatorActor, pass consoleWriterActor and tailCoordinatorActor to fileValidatorActorProps
var validationActorProps = Props.Create(() => new FileValidationActor(consoleWriterActor));
var validationActor = MyActorSystem.ActorOf(validationActorProps, "validationActor");
// make consoleReaderActor, pass validationActor to consoleReaderProps
var consoleReaderProps = Props.Create(() => new ConsoleReaderActor());
var consoleReaderActor = MyActorSystem.ActorOf(consoleReaderProps, "consoleReaderActor");
// tell console reader to begin
consoleReaderActor.Tell(ConsoleReaderActor.StartCommand);
// blocks the main thread from exiting until the actor system is shut down
MyActorSystem.AwaitTermination();
}
示例13: Start
public bool Start(HostControl hostControl)
{
ClusterSystem = ActorSystem.Create("webcrawler");
ApiMaster = ClusterSystem.ActorOf(Props.Create(() => new ApiMaster()), "api");
DownloadMaster = ClusterSystem.ActorOf(Props.Create(() => new DownloadsMaster()), "downloads");
//ApiMaster.Tell(new StartJob(new CrawlJob(new Uri("http://www.rottentomatoes.com/", UriKind.Absolute), true), ghettoConsoleActor));
return true;
}
示例14: ViewExample
private static void ViewExample(ActorSystem system)
{
Console.WriteLine("\n--- PERSISTENT VIEW EXAMPLE ---\n");
var pref = system.ActorOf(Props.Create<ViewExampleActor>());
var view = system.ActorOf(Props.Create<ExampleView>());
system.Scheduler.ScheduleTellRepeatedly(TimeSpan.Zero, TimeSpan.FromSeconds(2), pref, "scheduled", ActorRefs.NoSender);
system.Scheduler.ScheduleTellRepeatedly(TimeSpan.Zero, TimeSpan.FromSeconds(5), view, "snap", ActorRefs.NoSender);
}
示例15: _init
private void _init()
{
actorSystem = ActorSystem.Create("strategiesServer");
strategyActor = actorSystem.ActorOf(Props.Create<StrategyManagerActor>(), ConstantsHelper.AKKA_PATH_STRATEGY_MANAGER);
persistenceActor = actorSystem.ActorOf(Props.Create<PersistenceActor>(), ConstantsHelper.AKKA_PATH_PERSISTENCE);
marketActor = actorSystem.ActorOf(Props.Create<SecuritiesMarketManagerActor>(), ConstantsHelper.AKKA_PATH_MARKET_MANAGER);
}