private static void Demo5Supervision() { Console.WriteLine("Get Actor System from singleton Instance"); Console.WriteLine("and creating SimpleActor"); var simple = ActorsSystem.Instance.ActorOf(SimpleActor.CreateProps(), "SimpleActor"); Console.WriteLine("Press enter to start sending message"); Console.ReadLine(); simple.Tell(new ActorMessage(10)); Console.WriteLine("Press enter to send message that cause resume (actor will not restart)"); Console.ReadLine(); simple.Tell(new RaiseExceptionMessage(new FormatException())); Console.ReadLine(); simple.Tell(new ActorMessage(10)); Console.WriteLine("Press enter to send message that cause restart (actor will restart)"); Console.ReadLine(); simple.Tell(new RaiseExceptionMessage(new NullReferenceException())); Console.ReadLine(); simple.Tell(new ActorMessage(10)); Console.WriteLine("Press enter to send message that cause Stop (actor will stop)"); Console.ReadLine(); simple.Tell(new RaiseExceptionMessage(new Exception())); //Console.ReadLine(); //simple.Tell(new ActorMessage(10)); }
private static void Demo6BackSupervision() { Console.WriteLine("Creating SimpleActor Props with BackOff Supervisor"); var childProps = SimpleActor.CreateProps(); var supervisor = BackoffSupervisor.Props( Backoff.OnFailure( childProps: childProps, childName: "SimpleActor", minBackoff: TimeSpan.FromSeconds(3), maxBackoff: TimeSpan.FromSeconds(60), randomFactor: 0.2) .WithAutoReset(TimeSpan.FromSeconds(160))); var simple = ActorsSystem.Instance.ActorOf(supervisor, "SimpleActor:Supervisor"); Console.WriteLine("Press enter to start raise exception"); Console.ReadLine(); simple.Tell(new ExceptionMessage()); Console.WriteLine("Exception Raised"); Console.ReadLine(); simple.Tell(new ExceptionMessage()); Console.WriteLine("Exception Raised"); Console.ReadLine(); simple.Tell(new ExceptionMessage()); Console.WriteLine("Exception Raised"); }
public void TestInternalState() { var actor = ActorOfAsTestActorRef <SimpleActor>(SimpleActor.CreateProps()); var underlyingActor = actor.UnderlyingActor; actor.Tell(new ChangeStateMessage(10)); Assert.AreEqual(10, underlyingActor.State); }
public void SimpleAndReceiveTest() { TestLauncherActor.Test(() => { List <string> list = new List <string>(); var bhv = new Behavior <IActor, string>((i, s1) => i.SendMessage(i, s1)); var simple = new SimpleActor(bhv); var bhv2 = new Behavior <IActor, string>((i, s2) => list.Add(s2)); var receiver = new SimpleActor(bhv2); simple.SendMessage(receiver, "Simple works"); Task.Delay(5000).Wait(); var s = list.FirstOrDefault(); Assert.AreEqual("Simple works", s); }); }
private static void Demo9Router() { Console.WriteLine("Creating SimpleActor with Router (RoundRobin policy)"); var props = SimpleActor.CreateProps().WithRouter(new RoundRobinPool(2)); var simple = ActorsSystem.Instance.ActorOf(props, "SimpleActor"); Console.WriteLine("Press enter to start"); Console.ReadLine(); simple.Tell(new ActorMessage(10)); Console.ReadLine(); simple.Tell(new ActorMessage(10)); Console.ReadLine(); simple.Tell(new ActorMessage(10)); Console.ReadLine(); simple.Tell(new ActorMessage(10)); Console.ReadLine(); }
private static void Demo4FullSystem() { Console.WriteLine("Get Actor System from singleton Instance"); var simple = ActorsSystem.Instance.ActorOf(SimpleActor.CreateProps(), "SimpleActor"); Console.WriteLine("Press enter to start sending messages"); Console.ReadLine(); simple.Tell(new ActorMessage(10)); Console.ReadLine(); simple.Tell(new ActorMessage(10)); Console.WriteLine("Now will send a message that raise and exception"); Console.ReadLine(); simple.Tell(new ExceptionMessage()); Console.WriteLine("Exception raised, the actor will restart"); Console.ReadLine(); simple.Tell(new ActorMessage(10)); }
// Use this for initialization void Start() { dungeonFloor = DungeonGenerator.CreateFloor(64, 64, new Dungeon()); RLBaseTile start = null; foreach (RLBaseTile t in dungeonFloor.Tiles) { if (t != null) { if (start == null && !t.GetTileType().BlocksMovement) { start = t; } TileRenderer.BindTile(t); } } _actor = new SimpleActor(StatBlock.CreateInstance(baseStats, 3, 7, 9)) { BasicMoveSkill = move, fieldOfView = new BresenhamFOV(), OnVisibilityChanged = (tile, visible) => { if (visible) { tile.SetCurrentlyVisibleToPlayer(true); tile.SetEverSeenByPlayer(true); } else { tile.SetCurrentlyVisibleToPlayer(false); } } }; StatBlockDisplay.BindStatBlock(_actor.GetStats()); start.SetActor(_actor); RLActorController actorController = Instantiate(ActorPrefab, transform); actorController.effectRenderer = effectRenderer; actorController.BindActor(_actor); InventoryDisplay.BindInventory(_actor); virtualCam.Follow = actorController.transform; }