本文整理汇总了C#中ActorSystem类的典型用法代码示例。如果您正苦于以下问题:C# ActorSystem类的具体用法?C# ActorSystem怎么用?C# ActorSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActorSystem类属于命名空间,在下文中一共展示了ActorSystem类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:ymccready,项目名称:akka-bootcamp,代码行数:28,代码来源:Program.cs
示例2: Main
static void Main(string[] args)
{
var section = (AkkaConfigurationSection)ConfigurationManager.GetSection("akka");
_system = ActorSystem.Create("test", section.AkkaConfig);
_coordinator = _system.ActorOf(Props.Create(() => new IdentityActor())
.WithRouter(FromConfig.Instance), "fred");
//_coordinator =
// _system.ActorOf(Props.Create(() => new IdentityActor()).WithRouter(new ConsistentHashingPool(5000)),
// "fred2");
int routees = _coordinator.Ask<Routees>(new GetRoutees()).Result.Members.Count();
Console.WriteLine(routees);
// Lazy wait for the co-ordinator to deploy.
Thread.Sleep(5000);
for (int i = 1; i <= 5000; i++)
{
for (int x = 1; x <= 4; x++)
{
_coordinator.Tell(new EntityMessage<long>(i));
}
}
Thread.Sleep(500);
Console.ReadLine();
}
开发者ID:DevEnable,项目名称:AkkaHash,代码行数:30,代码来源:Program.cs
示例3: SnapshotedActor
private static void SnapshotedActor(ActorSystem system)
{
Console.WriteLine("\n--- SNAPSHOTED ACTOR EXAMPLE ---\n");
var pref = system.ActorOf(Props.Create<SnapshotedExampleActor>(), "snapshoted-actor");
// send two messages (a, b) and persist them
pref.Tell("a");
pref.Tell("b");
// make a snapshot: a, b will be stored in durable memory
pref.Tell("snap");
// send next two messages - those will be cleared, since MemoryJournal is not "persistent"
pref.Tell("c");
pref.Tell("d");
// print internal actor's state
pref.Tell("print");
// result after first run should be like:
// Current actor's state: d, c, b, a
// after second run:
// Offered state (from snapshot): b, a - taken from the snapshot
// Current actor's state: d, c, b, a, b, a - 2 last messages loaded from the snapshot, rest send in this run
// after third run:
// Offered state (from snapshot): b, a, b, a - taken from the snapshot
// Current actor's state: d, c, b, a, b, a, b, a - 4 last messages loaded from the snapshot, rest send in this run
// etc...
}
开发者ID:akkadotnet,项目名称:Akka.Persistence.CouchBase,代码行数:35,代码来源:Program.cs
示例4: ActorSelection
/// <summary>
/// Construct an <see cref="Akka.Actor.ActorSelection"/> from the given path, which is
/// parsed for wildcards (these are replaced by regular expressions
/// internally). No attempt is made to verify the existence of any part of
/// the supplied path, it is recommended to send a message and gather the
/// replies in order to resolve the matching set of actors.
/// </summary>
public static ActorSelection ActorSelection(string path, ActorSystem system, ActorRef lookupRoot)
{
var provider = ((ActorSystemImpl)system).Provider;
if(Uri.IsWellFormedUriString(path, UriKind.Absolute))
{
ActorPath actorPath;
if(!ActorPath.TryParse(path, out actorPath))
return new ActorSelection(provider.DeadLetters, "");
var actorRef = provider.RootGuardianAt(actorPath.Address);
return new ActorSelection(actorRef, actorPath.Elements);
}
//no path given
if(string.IsNullOrEmpty(path))
{
return new ActorSelection(system.DeadLetters, "");
}
//absolute path
var elements = path.Split('/');
if(elements[0] == "")
{
return new ActorSelection(provider.RootGuardian, elements.Skip(1));
}
return new ActorSelection(lookupRoot, path);
}
开发者ID:ClusterReply,项目名称:akka.net,代码行数:34,代码来源:ActorRefFactoryShared.cs
示例5: RunDistributedPubSubSeed
/// <summary>
/// Starts a job, which publishes <see cref="Echo"/> message to distributed cluster pub sub in 5 sec periods.
/// </summary>
static void RunDistributedPubSubSeed(ActorSystem system)
{
var mediator = DistributedPubSub.Get(system).Mediator;
system.Scheduler.ScheduleTellRepeatedly(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), mediator,
new Publish("echo", new Echo("hello world")), ActorRefs.NoSender);
}
开发者ID:,项目名称:,代码行数:10,代码来源:
示例6: Main
static void Main()
{
ChartActors = ActorSystem.Create("ChartActors");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main());
}
开发者ID:CActor,项目名称:akka-bootcamp,代码行数:7,代码来源:Program.cs
示例7: Remoting
public Remoting(ActorSystem system, RemoteActorRefProvider provider)
: base(system, provider)
{
log = Logging.GetLogger(system, "remoting");
_eventPublisher = new EventPublisher(system, log, Logging.LogLevelFor(provider.RemoteSettings.RemoteLifecycleEventsLogLevel));
_transportSupervisor = system.SystemActorOf(Props.Create<TransportSupervisor>(), "transports");
}
开发者ID:jweimann,项目名称:akka.net,代码行数:7,代码来源:Remoting.cs
示例8: ToSurrogate
/// <summary>
/// Creates a surrogate representation of the current <see cref="RandomGroup"/>.
/// </summary>
/// <param name="system">The actor system that owns this router.</param>
/// <returns>The surrogate representation of the current <see cref="RandomGroup"/>.</returns>
public override ISurrogate ToSurrogate(ActorSystem system)
{
return new RandomGroupSurrogate
{
Paths = Paths
};
}
开发者ID:rogeralsing,项目名称:akka.net,代码行数:12,代码来源:Random.cs
示例9: 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 :-)");
}
开发者ID:TimMurphy,项目名称:shop-with-akka.net,代码行数:29,代码来源:Program.cs
示例10: 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());
}
开发者ID:billyxing,项目名称:AkkaNetRemoteTest,代码行数:7,代码来源:MainWindow.xaml.cs
示例11: FixServer
public FixServer(int port)
{
_actorSystem = ActorSystem.Create("FIXServer");
// Some invented FX spot rates
var prices = new Dictionary<string, double>()
{
{ "USDGBP", 0.65575 },
{ "USDJPY", 119.75 }
};
var fixParser = new FixParser();
var tcpServerProps = Props.Create(() => new TcpServerActor(port,
FixParser.ExtractFixMessages));
Func<IActorRefFactory, IActorRef> tcpServerCreator =
(context) => context.ActorOf(tcpServerProps, "TcpServer");
var fixInterpreterProps = Props.Create(() => new FixInterpreterActor(fixParser));
Func<IActorRefFactory, IActorRef> fixInterpreterCreator =
(context) => context.ActorOf(fixInterpreterProps, "FixInterpreter");
var fixServerProps = Props.Create(() => new Actors.FixServerActor(tcpServerCreator,
fixInterpreterCreator, prices));
_fixServerActor = _actorSystem.ActorOf(fixServerProps, "FixServer");
}
开发者ID:gderham,项目名称:fixity,代码行数:26,代码来源:FixServer.cs
示例12: TestKitBase
private TestKitBase(TestKitAssertions assertions, ActorSystem system, Config config, string actorSystemName, string testActorName)
{
if(assertions == null) throw new ArgumentNullException("assertions");
if(system == null)
{
var configWithDefaultFallback = config.SafeWithFallback(_defaultConfig);
system = ActorSystem.Create(actorSystemName ?? "test", configWithDefaultFallback);
}
_assertions = assertions;
_system = system;
system.RegisterExtension(new TestKitExtension());
system.RegisterExtension(new TestKitAssertionsExtension(assertions));
_testKitSettings = TestKitExtension.For(_system);
_queue = new BlockingQueue<MessageEnvelope>();
_log = Logging.GetLogger(system, GetType());
_eventFilterFactory = new EventFilterFactory(this);
if (string.IsNullOrEmpty(testActorName))
testActorName = "testActor" + _testActorId.IncrementAndGet();
var testActor = CreateTestActor(system, testActorName);
//Wait for the testactor to start
AwaitCondition(() =>
{
var repRef = testActor as RepointableRef;
return repRef == null || repRef.IsStarted;
}, TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(10));
if(!(this is NoImplicitSender))
{
InternalCurrentActorCellKeeper.Current = (ActorCell)((ActorRefWithCell)testActor).Underlying;
}
_testActor = testActor;
}
开发者ID:rodrigovidal,项目名称:akka.net,代码行数:35,代码来源:TestKitBase.cs
示例13: RootGuardianActorRef
public RootGuardianActorRef(ActorSystem system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, //TODO: switch from Func<Mailbox> createMailbox to MailboxType mailboxType
InternalActorRef supervisor, ActorPath path, InternalActorRef deadLetters, IReadOnlyDictionary<string, InternalActorRef> extraNames)
: base(system,props,dispatcher,createMailbox,supervisor,path)
{
_deadLetters = deadLetters;
_extraNames = extraNames;
}
开发者ID:rmiller1971,项目名称:akka.net,代码行数:7,代码来源:RootGuardianActorRef.cs
示例14: 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();
}
开发者ID:BredStik,项目名称:akka-bootcamp,代码行数:25,代码来源:Program.cs
示例15: YakkaBootstrapper
public YakkaBootstrapper()
{
var hocon = string.Format(@"
akka {{
loglevel = DEBUG
loggers = [""Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog""]
actor {{
provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
}}
remote {{
helios.tcp {{
port = 0
hostname = {0}
}}
}}
}}", Dns.GetHostName());
var config = ConfigurationFactory.ParseString(hocon);
var clientName = $"{ClientId}";
_clientActorSystem = ActorSystem.Create(clientName, config);
//Create root level actors. This is the actual root of the actor system, the view model bridge actors exchange messages with these
var errorHandler = _clientActorSystem.ActorOf(Props.Create(() => new ErrorDialogActor()), ClientActorPaths.ErrorDialogActor.Name);
var settingsActor = _clientActorSystem.ActorOf(Props.Create(() => new SettingsActor(errorHandler)), ClientActorPaths.SettingsActor.Name);
var clientsActor = _clientActorSystem.ActorOf(Props.Create(() => new ClientsActor()), ClientActorPaths.ClientsActor.Name);
var messager = _clientActorSystem.ActorOf(Props.Create(() => new MessagingActor()), ClientActorPaths.ChatMessageRouter.Name);
var connectionActor = _clientActorSystem.ActorOf(Props.Create(() => new ConnectionActor()), ClientActorPaths.ConnectionActor.Name);
var lockMonitor = _clientActorSystem.ActorOf(Props.Create(() => new LockMonitorActor()), ClientActorPaths.LockMonitor.Name);
Initialize();
}
开发者ID:patchandthat,项目名称:Yakka,代码行数:31,代码来源:YakkaBootstrapper.cs
示例16: 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;
}
开发者ID:SaladLab,项目名称:Akka.Interfaced.SlimSocket,代码行数:29,代码来源:ChannelHelper.cs
示例17: Create
/// <summary>
/// Creates cluster publish/subscribe settings from the default configuration `akka.cluster.pub-sub`.
/// </summary>
public static DistributedPubSubSettings Create(ActorSystem system)
{
var config = system.Settings.Config.GetConfig("akka.cluster.pub-sub");
if (config == null) throw new ArgumentException("Actor system settings has no configuration for akka.cluster.pub-sub defined");
return Create(config);
}
开发者ID:juergenhoetzel,项目名称:akka.net,代码行数:10,代码来源:DistributedPubSubSettings.cs
示例18: Initialize
public void Initialize(ActorSystem system)
{
var context = new ClusterNodeContext { System = system };
context.ClusterActorDiscovery = system.ActorOf(
Props.Create(() => new ClusterActorDiscovery(null)));
context.UserTable = new DistributedActorTableRef<long>(system.ActorOf(
Props.Create(() => new DistributedActorTable<long>(
"User", context.ClusterActorDiscovery, null, null)),
"UserTable"));
var userTableContainer = system.ActorOf(
Props.Create(() => new DistributedActorTableContainer<long>(
"User", context.ClusterActorDiscovery, typeof(UserActorFactory), new object[] { context }, InterfacedPoisonPill.Instance)),
"UserTableContainer");
context.GameTable = new DistributedActorTableRef<long>(system.ActorOf(
Props.Create(() => new DistributedActorTable<long>(
"Game", context.ClusterActorDiscovery, typeof(IncrementalIntegerIdGenerator), null)),
"GameTable"));
var gameTableContainer = system.ActorOf(
Props.Create(() => new DistributedActorTableContainer<long>(
"Game", context.ClusterActorDiscovery, typeof(GameActorFactory), new object[] { context }, InterfacedPoisonPill.Instance)),
"GameTableContainer");
var gamePairMaker = system.ActorOf(Props.Create(() => new GamePairMakerActor(context)));
context.GamePairMaker = gamePairMaker.Cast<GamePairMakerRef>();
Context = context;
}
开发者ID:SaladLab,项目名称:TicTacToe,代码行数:32,代码来源:ClusterContextFixture.cs
示例19: 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();
}
开发者ID:DeonHeyns,项目名称:Exploring-Akka-Dot-NET,代码行数:30,代码来源:Program.cs
示例20: 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();
}
开发者ID:CActor,项目名称:akka-bootcamp,代码行数:28,代码来源:Program.cs
注:本文中的ActorSystem类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论