static void Main(string[] args) { try { ColoredConsole.WriteTitle("MoviePlaybackSystem.Remote.PlaybackStatisticsActor: Running Akka.NET demo..."); // Start ActorSystem MoviePlaybackSystemHelper.StartActorSystem(false); ActorPaths.LogAllActorPaths(); // Wait for user input to terminate the application ColoredConsole.WriteUserPrompt($" Press ENTER key to terminate '{MoviePlaybackSystemHelper.ActorSystemName}' ActorSystem..."); Console.ReadLine(); // Terminate ActorSystem // MoviePlaybackSystemHelper.TerminateActorSystem(); ColoredConsole.WriteTitle("MoviePlaybackSystem.Remote.PlaybackStatisticsActor: Quitting Akka.NET demo."); } catch (Exception ex) { ColoredConsole.WriteError($"MoviePlaybackSystem.Remote.PlaybackStatisticsActor: Exception occurred (type: '{ex.GetType().Name}')"); ColoredConsole.WriteError(ex.Message); ColoredConsole.WriteError(ex.StackTrace); } finally { // Terminate ActorSystem MoviePlaybackSystemHelper.TerminateActorSystem(); } }
private AgentMoc(ActorPaths actorPaths, long time, bool debug, IActorRef principal, IBehaviour behaviour, GuardianType guardianType) : base(actorPaths: actorPaths, time: time, debug: debug, principal: principal) { _actorPaths = actorPaths; _guardianType = guardianType; this.InitializeAgent(behaviour: behaviour); }
// public Constructor public static Props Props(ActorPaths actorPaths , long time , bool debug , IActorRef principal) { return(Akka.Actor.Props.Create(factory: () => new Supervisor(actorPaths, time, debug, principal))); }
public Supervisor(ActorPaths actorPaths , long time , bool debug , ProductionDomainContext productionDomainContext , IMessageHub messageHub , Configuration configuration , List <FSetEstimatedThroughputTime> estimatedThroughputTimes , IActorRef principal ) : base(actorPaths: actorPaths, time: time, debug: debug, principal: principal) { _productionDomainContext = productionDomainContext; _dataBaseConnection = _productionDomainContext.Database.GetDbConnection(); _articleCache = new ArticleCache(connectionString: _dataBaseConnection.ConnectionString); _messageHub = messageHub; _orderGenerator = new OrderGenerator(simConfig: configuration, productionDomainContext: _productionDomainContext , productIds: estimatedThroughputTimes.Select(x => x.ArticleId).ToList()); _orderCounter = new OrderCounter(maxQuantity: configuration.GetOption <OrderQuantity>().Value); _configID = configuration.GetOption <SimulationId>().Value; _simulationType = configuration.GetOption <SimulationKind>().Value; _transitionFactor = configuration.GetOption <TransitionFactor>().Value; estimatedThroughputTimes.ForEach(SetEstimatedThroughputTime); Send(instruction: Instruction.PopOrder.Create(message: "Pop", target: Self), waitFor: 1); Send(instruction: Instruction.EndSimulation.Create(message: true, target: Self), waitFor: configuration.GetOption <SimulationEnd>().Value); Send(instruction: Instruction.SystemCheck.Create(message: "CheckForOrders", target: Self), waitFor: 1); DebugMessage(msg: "Agent-System ready for Work"); }
private void CreateGuard(GuardianType guardianType, GuardianBehaviour guardianBehaviour) { var guard = _simulation.ActorSystem.ActorOf(props: Guardian.Props(actorPaths: ActorPaths, time: 0, debug: _debugAgents), name: guardianType.ToString() + "Guard"); _simulation.SimulationContext.Tell(message: BasicInstruction.Initialize.Create(target: guard, message: guardianBehaviour)); ActorPaths.AddGuardian(guardianType: guardianType, actorRef: guard); }
static void Main(string[] args) { try { ColoredConsole.WriteTitle("MoviePlaybackSystem: Running Akka.NET demo..."); // Start ActorSystem MoviePlaybackSystemHelper.StartActorSystem(true); ActorPaths.LogAllActorPaths(); // Run interactive session with user inputting commands RunUserInteractiveSession(); // Terminate ActorSystem // MoviePlaybackSystemHelper.TerminateActorSystem(); ColoredConsole.WriteTitle("MoviePlaybackSystem: Quitting Akka.NET demo."); } catch (Exception ex) { ColoredConsole.WriteError($"MoviePlaybackSystem: Exception occurred (type: '{ex.GetType().Name}')"); ColoredConsole.WriteError(ex.Message); ColoredConsole.WriteError(ex.StackTrace); } finally { // Terminate ActorSystem MoviePlaybackSystemHelper.TerminateActorSystem(); } }
/// <summary> /// Instantiates /// </summary> /// <param name="dbService"></param> /// <param name="actorSystem"></param> /// <param name="actorPaths"></param> /// <param name="logger"></param> public ProjectorPipeline(IDbService dbService, ActorSystem actorSystem, ActorPaths actorPaths, ILogger <ProjectorPipeline> logger) { _dbService = dbService; _actorSystem = actorSystem; _actorPaths = actorPaths; _logger = logger; }
private void CreateDirectoryAgents() { ActorPaths.SetHubDirectoryAgent(hubAgent: _simulation.ActorSystem.ActorOf(props: Directory.Props(actorPaths: ActorPaths, time: 0, debug: _debugAgents), name: "HubDirectory")); _simulation.SimulationContext.Tell(message: BasicInstruction.Initialize.Create(target: ActorPaths.HubDirectory.Ref, message: Agents.DirectoryAgent.Behaviour.Factory.Get(simType: _simulationType))); ActorPaths.SetStorageDirectory(storageAgent: _simulation.ActorSystem.ActorOf(props: Directory.Props(actorPaths: ActorPaths, time: 0, debug: _debugAgents), name: "StorageDirectory")); _simulation.SimulationContext.Tell(message: BasicInstruction.Initialize.Create(target: ActorPaths.StorageDirectory.Ref, message: Agents.DirectoryAgent.Behaviour.Factory.Get(simType: _simulationType))); }
public Supervisor(ActorPaths actorPaths , long time , bool debug , IActorRef principal ) : base(actorPaths: actorPaths, time: time, debug: debug, principal: principal) { }
public static AgentMoc CreateAgent(ActorPaths actorPaths, IActorRef principal, IBehaviour behaviour, GuardianType guardianType) { return(new AgentMoc(actorPaths: actorPaths, time: 0, debug: false, principal: principal, behaviour: behaviour, guardianType: guardianType)); }
public Task <Simulation> InitializeSimulation(Configuration configuration) { return(Task.Run(function: () => { _messageHub.SendToAllClients(msg: "Initializing Simulation..."); // Init Simulation SimulationConfig = configuration.GetContextConfiguration(); _debugAgents = configuration.GetOption <DebugAgents>().Value; _simulationType = configuration.GetOption <SimulationKind>().Value; _simulation = new Simulation(simConfig: SimulationConfig); ActorPaths = new ActorPaths(simulationContext: _simulation.SimulationContext , systemMailBox: SimulationConfig.Inbox.Receiver); foreach (var worker in _ganttContext.GptblWorker) { var workergroup = _ganttContext.GptblWorkergroupWorker.Single(x => x.WorkerId.Equals(worker.Id)); _resourceDictionary.Add(int.Parse(worker.Id), new ResourceDefinition(worker.Name, int.Parse(worker.Id), ActorRefs.Nobody, workergroup.WorkergroupId, resourceType: ResourceType.Worker)); } _ganttContext.GptblPrt.Where(x => !x.CapacityType.Equals(1)).Select(x => new { x.Id, x.Name }).ForEach(x => _resourceDictionary.Add(int.Parse(x.Id), new ResourceDefinition(x.Name, int.Parse(x.Id), ActorRefs.Nobody, "1", resourceType: ResourceType.Tool))); _ganttContext.GptblWorkcenter.Select(x => new { x.Id, x.Name }).ForEach(x => _resourceDictionary.Add(int.Parse(x.Id), new ResourceDefinition(x.Name, int.Parse(x.Id), ActorRefs.Nobody, string.Empty, resourceType: ResourceType.Workcenter))); // Create DataCollectors CreateCollectorAgents(configuration: configuration); //if (_debugAgents) AddDeadLetterMonitor(); AddTimeMonitor(); // Create Guardians and Inject Childcreators GenerateGuardians(); // Create Supervisor Agent CreateSupervisor(configuration: configuration); // Create DirectoryAgents CreateDirectoryAgents(configuration: configuration); // Create Resources CreateResourceAgents(configuration: configuration); // Create Storages CreateStorageAgents(); // Finally Initialize StateManger StateManager = new GanttStateManager(new List <IActorRef> { this.StorageCollector , this.JobCollector , this.ContractCollector , this.ResourceCollector } , _messageHub , SimulationConfig.Inbox); return _simulation; })); }
/// <summary> /// Basic Agent /// </summary> /// <param name="actorPaths"></param> /// <param name="time">Current time span</param> /// <param name="debug">Parameter to activate Debug Messages on Agent level</param> /// <param name="principal">If not set, put IActorRefs.Nobody</param> protected Agent(ActorPaths actorPaths, long time, bool debug, IActorRef principal) : base(simulationContext: actorPaths.SimulationContext.Ref, time: time) { DebugThis = debug; Name = Self.Path.Name; ActorPaths = actorPaths; VirtualParent = principal; VirtualChildren = new HashSet <IActorRef>(); DebugMessage(msg: "I'm alive: " + Self.Path.ToStringWithAddress()); }
// public Constructor public static Props Props(ActorPaths actorPaths , long time , bool debug , ProductionDomainContext productionDomainContext , IMessageHub messageHub , Configuration configuration , List <FSetEstimatedThroughputTime> estimatedThroughputTimes , IActorRef principal) { return(Akka.Actor.Props.Create(factory: () => new Supervisor(actorPaths, time, debug, productionDomainContext, messageHub, configuration, estimatedThroughputTimes, principal))); }
public static Props Props(ActorPaths actorPaths , ICollectorBehaviour collectorBehaviour , IMessageHub msgHub , Configuration configuration , long time , bool debug , List <Type> streamTypes) { return(Akka.Actor.Props.Create( factory: () => new Collector(actorPaths, collectorBehaviour, msgHub, configuration, time, streamTypes))); }
public static ActorPaths CreateActorPaths(TestKit testKit, IActorRef simContext) { var simSystem = testKit.CreateTestProbe(); var inbox = Inbox.Create(system: testKit.Sys); var agentPaths = new ActorPaths(simulationContext: simContext, systemMailBox: inbox.Receiver); agentPaths.SetSupervisorAgent(systemAgent: simSystem); agentPaths.Guardians.Add(GuardianType.Contract, testKit.CreateTestProbe()); agentPaths.Guardians.Add(GuardianType.Dispo, testKit.CreateTestProbe()); agentPaths.Guardians.Add(GuardianType.Production, testKit.CreateTestProbe()); return(agentPaths); }
public Task <Simulation> InitializeSimulation(Configuration configuration) { return(Task.Run(function: () => { _messageHub.SendToAllClients(msg: "Initializing Simulation..."); // Init Simulation SimulationConfig = configuration.GetContextConfiguration(); _debugAgents = configuration.GetOption <DebugAgents>().Value; _simulationType = configuration.GetOption <SimulationKind>().Value; _simulation = new Simulation(simConfig: SimulationConfig); ActorPaths = new ActorPaths(simulationContext: _simulation.SimulationContext, systemMailBox: SimulationConfig.Inbox.Receiver); // Create DataCollectors CreateCollectorAgents(configuration: configuration); //if (_debugAgents) AddDeadLetterMonitor(); AddTimeMonitor(); // Create Guardians and Inject Childcreators GenerateGuardians(); // Create Supervisor Agent CreateSupervisor(configuration: configuration); // Create DirectoryAgents CreateDirectoryAgents(configuration: configuration); // Create Resources CreateResourceAgents(configuration: configuration); // Create Storages CreateStorageAgents(); // Finally Initialize StateManger StateManager = new AgentStateManager(new List <IActorRef> { this.StorageCollector , this.JobCollector , this.ContractCollector , this.ResourceCollector } , SimulationConfig.Inbox); return _simulation; })); }
/// <summary> /// Collector Agent for Life data Aquesition /// </summary> /// <param name="actorPaths"></param> /// <param name="time">Current time span</param> /// <param name="debug">Parameter to activate Debug Messages on Agent level</param> public Collector(ActorPaths paths , ICollectorBehaviour collectorBehaviour , IMessageHub msgHub , Configuration configuration , long time , List <Type> streamTypes) : base(time: time, channels: streamTypes) { Console.WriteLine(value: "I'm alive: " + Self.Path.ToStringWithAddress()); collectorBehaviour.Collector = this; Behaviour = collectorBehaviour; messageHub = msgHub; Config = configuration; actorPaths = paths; simulationId = Config.GetOption <SimulationId>(); simulationNumber = Config.GetOption <SimulationNumber>(); simulationKind = Config.GetOption <SimulationKind>(); saveToDB = Config.GetOption <SaveToDB>(); }
private void CreateSupervisor(Configuration configuration) { var products = _dBContext.GetProducts(); var initialTime = configuration.GetOption <EstimatedThroughPut>().Value; var estimatedThroughputs = products.Select(a => new FSetEstimatedThroughputTime(a.Id, initialTime, a.Name)) .ToList(); ActorPaths.SetSupervisorAgent(systemAgent: _simulation.ActorSystem .ActorOf(props: Supervisor.Props(actorPaths: ActorPaths, time: 0, debug: _debugAgents, productionDomainContext: _dBContext, messageHub: _messageHub, configuration: configuration, estimatedThroughputTimes: estimatedThroughputs, principal: ActorRefs.Nobody), name: "Supervisor")); }
/// <summary> /// Collector Agent for Life data Aquesition /// </summary> /// <param name="actorPaths"></param> /// <param name="time">Current time span</param> /// <param name="debug">Parameter to activate Debug Messages on Agent level</param> public Collector(ActorPaths paths , ICollectorBehaviour collectorBehaviour , IMessageHub msgHub , Configuration configuration , long time , List <Type> streamTypes) : base(time: time, channels: streamTypes) { collectorBehaviour.Collector = this; Behaviour = collectorBehaviour; messageHub = msgHub; Config = configuration; actorPaths = paths; simulationId = Config.GetOption <SimulationId>(); simulationNumber = Config.GetOption <SimulationNumber>(); simulationKind = Config.GetOption <SimulationKind>(); saveToDB = Config.GetOption <SaveToDB>(); maxTime = Config.GetOption <SimulationEnd>().Value; messageHub.SendToAllClients(msg: "Collector initialized: " + Self.Path.ToStringWithAddress()); }
public Task <Simulation> InitializeSimulation(Configuration configuration) { return(Task.Run(function: () => { _messageHub.SendToAllClients(msg: "Initializing Simulation..."); // Init Simulation SimulationConfig = configuration.GetContextConfiguration(); _debugAgents = configuration.GetOption <DebugAgents>().Value; Logger = new LogWriter(writeToFile: _debugAgents); _simulationType = configuration.GetOption <SimulationKind>().Value; _simulation = new Simulation(simConfig: SimulationConfig); ActorPaths = new ActorPaths(simulationContext: _simulation.SimulationContext, systemMailBox: SimulationConfig.Inbox.Receiver); // Create DataCollectors CreateCollectorAgents(configuration: configuration); if (_debugAgents) { AddDeadLetterMonitor(); } AddTimeMonitor(); // Create Guardians and Inject Childcreators GenerateGuardians(); // Create Supervisor Agent CreateSupervisor(configuration: configuration); // Create DirectoryAgents CreateDirectoryAgents(); // Create Resources CreateResourceAgents(configuration: configuration); // Create Storages CreateStorageAgents(); return _simulation; })); }
private void CreateSupervisor(Configuration configuration) { var products = _dBContext.GetProducts(); var initialTime = configuration.GetOption <EstimatedThroughPut>().Value; var estimatedThroughPuts = products.Select(a => new FSetEstimatedThroughputTime(a.Id, initialTime, a.Name)) .ToList(); var behave = Agents.SupervisorAgent.Behaviour.Factory.Default( productionDomainContext: _dBContext, messageHub: _messageHub, configuration: configuration, estimatedThroughputTimes: estimatedThroughPuts); ActorPaths.SetSupervisorAgent(systemAgent: _simulation.ActorSystem .ActorOf(props: Supervisor.Props(actorPaths: ActorPaths, time: 0, debug: _debugAgents, principal: ActorRefs.Nobody), name: "Supervisor")); _simulation.SimulationContext.Tell(message: BasicInstruction.Initialize.Create(target: ActorPaths.SystemAgent.Ref, message: behave)); }
public Job(ActorPaths actorPaths, IConfirmation jobConfirmation, long time, bool debug, IActorRef principal) : base(actorPaths: actorPaths, time: time, debug: debug, principal: principal) { DebugMessage(msg: "I'm Alive: " + Context.Self.Path); this.Do(BasicInstruction.Initialize.Create(Self, JobAgent.Behaviour.Factory.Get(SimulationType.None, jobConfirmation))); }
public Dispo(ActorPaths actorPaths, long time, bool debug, IActorRef principal) : base(actorPaths: actorPaths, time: time, debug: debug, principal: principal) { DebugMessage(msg: "I'm Alive: " + Context.Self.Path); //this.Do(BasicInstruction.Initialize.Create(Self, DispoBehaviour.Get())); }
public static Props Props(ActorPaths actorPaths, IConfirmation jobConfirmation, long time, bool debug, IActorRef principal) { return(Akka.Actor.Props.Create(factory: () => new Job(actorPaths, jobConfirmation, time, debug, principal))); }
// public Constructor public static Props Props(ActorPaths actorPaths, M_Resource resource, long time, bool debug, IActorRef principal) { return(Akka.Actor.Props.Create(factory: () => new Resource(actorPaths, resource, time, debug, principal))); }
public Hub(ActorPaths actorPaths, long time, SimulationType simtype, bool debug, IActorRef principal) : base(actorPaths: actorPaths, time: time, debug: debug, principal: principal) { DebugMessage(msg: "I'm Alive:" + Context.Self.Path); this.Do(o: BasicInstruction.Initialize.Create(target: Self, message: HubAgent.Behaviour.Factory.Get(simType: simtype))); }
public static Props Props(ActorPaths actorPaths, long time, bool debug) { return(Akka.Actor.Props.Create(factory: () => new Guardian(actorPaths, time, debug))); }
/// <summary> /// Basic Agent /// </summary> /// <param name="actorPaths"></param> /// <param name="time">Current time span</param> /// <param name="debug">Parameter to activate Debug Messages on Agent level</param> public Guardian(ActorPaths actorPaths, long time, bool debug) : base(actorPaths: actorPaths, time: time, debug: false, principal: null) { DebugMessage(msg: "I'm alive: " + Self.Path.ToStringWithAddress()); }
public Resource(ActorPaths actorPaths, long time, bool debug, IActorRef principal) : base(actorPaths: actorPaths, time: time, debug: debug, principal: principal) { }
// public Constructor public static Props Props(ActorPaths actorPaths, long time, SimulationType simtype, bool debug, IActorRef principal) { return(Akka.Actor.Props.Create(factory: () => new Hub(actorPaths, time, simtype, debug, principal))); }