public ActorRequestContext SetProcessFlags(ProcessFlags flags) => new ActorRequestContext( Self, Sender, Parent, CurrentMsg, CurrentRequest, flags );
public ActorItem( IActor actor, IActorInbox inbox, ProcessFlags flags ) { Actor = actor; Inbox = inbox; Flags = flags; }
public ActorRequestContext( ActorItem self, ProcessId sender, ActorItem parent, object currentMsg, ActorRequest currentRequest, ProcessFlags processFlags ) { Self = self; Sender = sender; Parent = parent; CurrentMsg = currentMsg; CurrentRequest = currentRequest; ProcessFlags = processFlags; }
public ActorRequestContext( ActorSystem system, ActorItem self, ProcessId sender, ActorItem parent, object currentMsg, ActorRequest currentRequest, ProcessFlags processFlags, ProcessOpTransaction ops, SessionVector session ) { Self = self; Sender = sender; Parent = parent; CurrentMsg = currentMsg; CurrentRequest = currentRequest; ProcessFlags = processFlags; Ops = ops; System = system; Session = session; }
/// <summary> /// Register the name with the process /// </summary> /// <typeparam name="T">The message type of the actor to register</typeparam> /// <param name="name">Name to register under</param> /// <param name="process">Process to be registered</param> public static ProcessId register <T>(ProcessName name, ProcessId process, ProcessFlags flags = ProcessFlags.Default) => ActorContext.Register <T>(name, process, flags);
/// <summary> /// Register self as a named process /// </summary> /// <remarks> /// This should be used from within a process' message loop only /// </remarks> /// <typeparam name="T">The message type of the actor to register</typeparam> /// <param name="name">Name to register under</param> public static ProcessId register <T>(ProcessName name, ProcessFlags flags = ProcessFlags.Default) => InMessageLoop ? ActorContext.Register <T>(name, Self, flags) : raiseUseInMsgLoopOnlyException <ProcessId>(nameof(name));
public static extern IntPtr OpenProcess(ProcessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId);
public ActorItem ActorCreate <S, T>(ActorItem parent, ProcessName name, Func <S, T, S> actorFn, Func <S> setupFn, ProcessFlags flags) { if (ProcessDoesNotExist(nameof(ActorCreate), parent.Actor.Id)) { return(null); } var actor = new Actor <S, T>(Cluster, parent, name, actorFn, setupFn, flags); IActorInbox inbox = null; if ((flags & ProcessFlags.ListenRemoteAndLocal) == ProcessFlags.ListenRemoteAndLocal && Cluster.IsSome) { inbox = new ActorInboxDual <S, T>(); } else if ((flags & ProcessFlags.PersistInbox) == ProcessFlags.PersistInbox && Cluster.IsSome) { inbox = new ActorInboxRemote <S, T>(); } else { inbox = new ActorInboxLocal <S, T>(); } var item = new ActorItem(actor, inbox, flags); try { parent.Actor.LinkChild(item); actor.Startup(); inbox.Startup(actor, actor.Parent, Cluster, 0); } catch (Exception e) { ShutdownProcess(item.Actor.Id); logSysErr(new ProcessException("Process failed starting up: " + e.Message, actor.Id.Path, actor.Parent.Actor.Id.Path, e)); } return(item); }
public ActorItem ActorCreate <T>(ActorItem parent, ProcessName name, Action <T> actorFn, Func <Unit, ProcessId, Unit> termFn, ProcessFlags flags, int maxMailboxSize = -1) { return(ActorCreate <Unit, T>(parent, name, (s, t) => { actorFn(t); return unit; }, () => unit, termFn, flags, maxMailboxSize)); }
public Actor(Option <ICluster> cluster, ActorItem parent, ProcessName name, Func <S, T, S> actor, Func <S> setup, ProcessFlags flags) : this(cluster, parent, name, actor, _ => setup(), flags) { }
/// <summary> /// Register as a named process /// </summary> public static ProcessId Register <T>(this ProcessId self, ProcessName name, ProcessFlags flags = ProcessFlags.Default) => ActorContext.Register <T>(name, self, flags);
/// <summary> /// Write a single override setting /// </summary> internal Unit WriteSettingOverride(string key, object value, string name, string prop, ProcessFlags flags) { if (value == null) { failwith <Unit>("Settings can't be null"); } var propKey = $"{name}@{prop}"; if (flags != ProcessFlags.Default) { ActorContext.Cluster.Iter(c => c.HashFieldAddOrUpdate(key, propKey, value)); } settingOverrides = settingOverrides.AddOrUpdate(key, propKey, value); return(unit); }
internal T GetSettingGeneral <T>(IEnumerable <Map <string, ValueToken> > settingsMaps, string key, string name, string prop, T defaultValue, ProcessFlags flags) { var res = GetSettingGeneral <T>(settingsMaps, key, name, prop, flags); if (res.IsNone) { // No config, no override; so cache the default value so we don't // go through all of this again. var propKey = $"{name}@{prop}"; AddOrUpdateProcessOverride(key, propKey, Optional(defaultValue)); } return(res.IfNone(defaultValue)); }
/// <summary> /// Spawns a new process with N worker processes, each message is mapped /// from T to IEnumerable U before each resulting U is passed to the worker /// processes in a round robin fashion. /// </summary> /// <typeparam name="T">Message type</typeparam> /// <typeparam name="U">Mapped message type</typeparam> /// <param name="Name">Delegator process name</param> /// <param name="Count">Number of worker processes</param> /// <param name="map">Maps the message from T to IEnumerable U before each one is passed to the workers</param> /// <param name="Inbox">Worker message handler</param> /// <param name="Flags">Process flags</param> /// <param name="Strategy">Failure supervision strategy</param> /// <returns>Process ID of the delegator process</returns> public static ProcessId roundRobinMapMany <S, T, U>( ProcessName Name, int Count, Func <S> Setup, Func <S, U, S> Inbox, Func <T, IEnumerable <U> > MapMany, ProcessFlags Flags = ProcessFlags.Default, State <StrategyContext, Unit> Strategy = null, int MaxMailboxSize = ProcessSetting.DefaultMailboxSize, string WorkerName = "worker" ) { if (Inbox == null) { throw new ArgumentNullException(nameof(Inbox)); } if (WorkerName == null) { throw new ArgumentNullException(nameof(WorkerName)); } if (Count < 1) { throw new ArgumentException($"{nameof(Count)} should be greater than 0"); } return(spawn <int, T>( Name, () => { spawnMany(Count, WorkerName, Setup, Inbox, Flags); return 0; }, (index, msg) => { var us = MapMany(msg); index = index % Children.Count; var kids = Children.Skip(index); foreach (var u in us) { index = index % Children.Count; var child = kids.Take(1).ToArray(); if (child.Length == 0) { kids = Children; child = kids.Take(1).ToArray(); if (child.Length == 0) { throw new NoRouterWorkersException(); } } fwd(child[0].Value, u); kids = kids.Skip(1); index++; } return index; }, Flags, Strategy, MaxMailboxSize )); }
internal static ActorSystemMessage AddToStore(IActor process, IActorInbox inbox, ProcessFlags flags) => new AddToStoreMessage(process, inbox, flags);
public static ProcessId ActorCreate <S, T>(ActorItem parent, ProcessName name, Func <S, T, S> actorFn, Func <S> setupFn, ProcessFlags flags) { var actor = new Actor <S, T>(cluster, parent, name, actorFn, setupFn, flags); IActorInbox inbox = null; if ((flags & ProcessFlags.ListenRemoteAndLocal) == ProcessFlags.ListenRemoteAndLocal && cluster.IsSome) { inbox = new ActorInboxDual <S, T>(); } else if ((flags & ProcessFlags.PersistInbox) == ProcessFlags.PersistInbox && cluster.IsSome) { inbox = new ActorInboxRemote <S, T>(); } else { inbox = new ActorInboxLocal <S, T>(); } var item = new ActorItem(actor, inbox, flags); parent.Actor.LinkChild(item); try { if (!started) { actor.Startup(); } inbox.Startup(actor, parent, cluster, 0); } catch { ShutdownProcess(item); throw; } return(item.Actor.Id); }
public static ProcessId ActorCreate <S, T>(ActorItem parent, ProcessName name, Action <T> actorFn, ProcessFlags flags) => ActorCreate <S, T>(parent, name, (s, t) => { actorFn(t); return(default(S)); }, () => default(S), flags);
internal static extern IntPtr OpenProcess( ProcessFlags dwDesiredAccess, bool bInheritHandle, int dwProcessId);
/// <summary> /// Get a named process setting /// </summary> /// <param name="pid">Process</param> /// <param name="name">Name of setting</param> /// <param name="prop">Name of property within the setting (for complex /// types, not value types)</param> /// <returns></returns> internal T GetProcessSetting <T>(ProcessId pid, string name, string prop, T defaultValue, ProcessFlags flags) { var empty = HashMap <string, ValueToken>(); var settingsMaps = Seq( processSettings.Find(pid).Map(token => token.Settings).IfNone(empty), processSettings.Find(RolePid(pid)).Map(token => token.Settings).IfNone(empty), roleSettings, Cluster.Map(c => c.Settings).IfNone(empty)); return(GetSettingGeneral(settingsMaps, ActorInboxCommon.ClusterSettingsKey(pid), name, prop, defaultValue, flags)); }
/// <summary> /// Get a named process setting /// </summary> /// <param name="pid">Process</param> /// <param name="name">Name of setting</param> /// <param name="prop">Name of property within the setting (for complex /// types, not value types)</param> /// <returns></returns> internal Option <T> GetProcessSetting <T>(ProcessId pid, string name, string prop, ProcessFlags flags) { var empty = Map.empty <string, ValueToken>(); var settingsMaps = new[] { processSettings.Find(pid).Map(token => token.Settings).IfNone(empty), processSettings.Find(RolePid(pid)).Map(token => token.Settings).IfNone(empty), roleSettings, cluster.Settings }; return(GetSettingGeneral <T>(settingsMaps, ActorInboxCommon.ClusterSettingsKey(pid), name, prop, flags)); }
/// <summary> /// This function creates the process flags /// </summary> /// <returns> the created process flags ore null if an error occurred</returns> private ProcessFlags?CreateProcessFlags() { ProcessFlags temp = new ProcessFlags(); temp.program = (SimulatorProgram)lst_Programs.SelectedItem; if (temp.program == null) { MessageBox.Show("Please select a program before trying to create a process"); return(null); } temp.programName = temp.program.Name; temp.processName = txtProcessName.Text; //ComboBoxItem priority = (ComboBoxItem)cmb_Priority.SelectedItem; temp.processPriority = (int)cmb_Priority.SelectedItem; // ComboBoxItem memory = (ComboBoxItem) cmb_Pages.SelectedItem; temp.processMemory = (int)cmb_Pages.SelectedItem; if (Int32.Parse(txt_ProcessLifetime.Text) == 0) // if the lifetime was 0 { temp.processLifetime = Int32.MaxValue; // make it INT.MAXVALUE seconds temp.processLifetimeTimeUnit = EnumTimeUnit.SECONDS; } else // if the lifetime was non 0 { temp.processLifetime = Int32.Parse(txt_ProcessLifetime.Text); // set the lifetime to the in-putted value if (rdb_LifetimeSecs.IsChecked != null && rdb_LifetimeSecs.IsChecked.Value) // if the seconds unit was selected { temp.processLifetimeTimeUnit = EnumTimeUnit.SECONDS; } else if (rdb_LifetimeTicks.IsChecked != null && rdb_LifetimeTicks.IsChecked.Value) //if the ticks time unit was selected { temp.processLifetimeTimeUnit = EnumTimeUnit.TICKS; } else { MessageBox.Show("Please Select a Process Lifetime Time Unit"); // if no time unit is selected return(null); } } temp.processID = processes.Count; temp.CPUid = 0; temp.burstTime = 0; if (chk_Display_Profile.IsChecked != null && chk_Display_Profile.IsChecked.Value) // if we are displaying a performance profile { temp.displayProfile = true; } else { temp.displayProfile = false; } if (chk_Children_Die.IsChecked != null && chk_Children_Die.IsChecked.Value) // should the processes children die when it dies { temp.parentDiesChildrenDie = true; } else { temp.parentDiesChildrenDie = false; } if (chk_Use_Default_Scheduler_Process.IsChecked != null && chk_Use_Default_Scheduler_Process.IsChecked.Value) // should this process use the default scheduler { temp.defaultScheduler = true; } else { temp.defaultScheduler = false; } if (chk_DelayedProcess.IsChecked != null && chk_DelayedProcess.IsChecked.Value) // does this process have a delayed start { temp.delayedProcess = true; temp.delayedProcessTime = (int)cmb_Arrival_Delay.SelectedValue; if (rdb_DelaySecs.IsChecked != null && rdb_DelaySecs.IsChecked.Value) // if the seconds time unit was selected { temp.delayTimeUnit = EnumTimeUnit.SECONDS; } else if (rdb_DelayTicks.IsChecked != null && rdb_DelayTicks.IsChecked.Value) // if the ticks time unit was selected { temp.delayTimeUnit = EnumTimeUnit.TICKS; } else { MessageBox.Show("Please Select a delay time unit"); // if no time unit was selected return(null); } } temp.parentProcess = null; if (temp.parentProcess == null) { temp.parentProcessID = -1; } else { temp.parentProcessID = temp.parentProcess.ProcessID; } temp.childProcesses = new List <SimulatorProcess>(); temp.processSwapped = false; temp.processState = EnumProcessState.READY; temp.previousState = EnumProcessState.READY; temp.resourceStarved = false; temp.allocatedResources = new List <SimulatorResource>(); temp.requestedResources = new List <SimulatorResource>(); temp.terminated = false; temp.processControlBlock = null; temp.OSid = 0; temp.unit = null; temp.clockSpeed = (int)sld_ClockSpeed.Value; temp.lotteryTickets = new List <LotteryTicket>(); temp.waitingForSemaphore = false; temp.ownsSemaphore = false; return(temp); #region OLD //temp.burstTime = 0; //temp.childProcesses = new List<SimulatorProcess>(); //if (chk_Use_Default_Scheduler_Process.IsChecked != null // && chk_Use_Default_Scheduler_Process.IsChecked.Value) // are we using the default scheduler //{ // temp.defaultScheduler = true; //} //else //{ // temp.defaultScheduler = false; //} //if (chk_DelayedProcess.IsChecked != null && chk_DelayedProcess.IsChecked.Value) // does this process have a delayed start //{ // temp.delayedProcess = true; // temp.delayedProcessTime = (int)cmb_Arrival_Delay.SelectedValue; // if (rdb_DelaySecs.IsChecked != null && rdb_DelaySecs.IsChecked.Value) // if the seconds time unit was selected // { // temp.delayTimeUnit = EnumTimeUnit.SECONDS; // } // else if (rdb_DelayTicks.IsChecked != null && rdb_DelayTicks.IsChecked.Value) // if the ticks time unit was selected // { // temp.delayTimeUnit = EnumTimeUnit.TICKS; // } // else // { // MessageBox.Show("Please Select a delay time unit"); // if no time unit was selected // return null; // } //} //if (chk_Display_Profile.IsChecked != null && chk_Display_Profile.IsChecked.Value) // if we are displaying a performance profile //{ // temp.displayProfile = true; //} //else //{ // temp.displayProfile = false; //} //if (chk_Children_Die.IsChecked != null && chk_Children_Die.IsChecked.Value) // should the processes children die when it dies //{ // temp.parentDiesChildrenDie = true; //} //else //{ // temp.parentDiesChildrenDie = false; //} //temp.parentProcess = null; //if (Int32.Parse(txt_ProcessLifetime.Text) == 0) // if the lifetime was 0 //{ // temp.processLifetime = Int32.MaxValue; // make it INT.MAXVALUE seconds // temp.processLifetimeTimeUnit = EnumTimeUnit.SECONDS; //} //else // if the lifetime was non 0 //{ // temp.processLifetime = Int32.Parse(txt_ProcessLifetime.Text); // set the lifetime to the in-putted value // if (rdb_LifetimeSecs.IsChecked != null && rdb_LifetimeSecs.IsChecked.Value) // if the seconds unit was selected // { // temp.processLifetimeTimeUnit = EnumTimeUnit.SECONDS; // } // else if (rdb_LifetimeTicks.IsChecked != null && rdb_LifetimeTicks.IsChecked.Value) //if the ticks time unit was selected // { // temp.processLifetimeTimeUnit = EnumTimeUnit.TICKS; // } // else // { // MessageBox.Show("Please Select a Process Lifetime Time Unit"); // if no time unit is selected // return null; // } //} //temp.processMemory = (int)cmb_Pages.SelectedValue; //temp.processName = txtProcessName.Text; //temp.processPriority = (int)cmb_Priority.SelectedValue; //temp.processState = EnumProcessState.READY; //temp.processSwapped = false; //temp.processID = processes.Count; //if (chk_Use_Default_Scheduler_Process.IsChecked != null // && chk_Use_Default_Scheduler_Process.IsChecked.Value) // should this process use the default scheduler //{ // temp.defaultScheduler = true; //} //else //{ // temp.defaultScheduler = false; //} //return temp; // return the created flags #endregion }
internal Option <T> GetSettingGeneral <T>(IEnumerable <Map <string, ValueToken> > settingsMaps, string key, string name, string prop, ProcessFlags flags) { var propKey = $"{name}@{prop}"; // First see if we have the value cached var over = settingOverrides.Find(key, propKey); if (over.IsSome) { return(over.Map(x => (T)x)); } // Next check the custer data store (Redis usually) Option <T> tover = None; if (flags != ProcessFlags.Default) { tover = from x in ActorContext.Cluster.Map(c => c.GetHashField <T>(key, propKey)) from y in x select y; if (tover.IsSome) { // It's in the data-store, so cache it locally and return AddOrUpdateProcessOverride(key, propKey, tover); return(tover); } } foreach (var settings in settingsMaps) { tover = from opt1 in prop == "value" ? from tok in settings.Find(name) from map in MapTokenType <T>(tok).Map(v => (T)v.Value) select map : settings.Find(name).Map(v => v.GetItem <T>(prop)) from opt2 in opt1 select opt2; if (tover.IsSome) { // There is a config setting, so cache it and return AddOrUpdateProcessOverride(key, propKey, tover); return(tover.IfNoneUnsafe(default(T))); } } return(None); }
public AddToStoreMessage(IProcess process, IActorInbox inbox, ProcessFlags flags) { Process = process; Inbox = inbox; Flags = flags; }
public ProcessId ActorCreate <S, T>( ActorItem parent, ProcessName name, Func <S, T, S> actorFn, Func <IActor, S> setupFn, Func <S, ProcessId, S> termFn, State <StrategyContext, Unit> strategy, ProcessFlags flags, int maxMailboxSize, bool lazy) { var actor = new Actor <S, T>(cluster, parent, name, actorFn, setupFn, termFn, strategy, flags, ActorContext.System(parent.Actor.Id).Settings, this); IActorInbox inbox = null; if ((actor.Flags & ProcessFlags.ListenRemoteAndLocal) == ProcessFlags.ListenRemoteAndLocal && cluster.IsSome) { inbox = new ActorInboxDual <S, T>(); } else if ((actor.Flags & ProcessFlags.PersistInbox) == ProcessFlags.PersistInbox && cluster.IsSome) { inbox = new ActorInboxRemote <S, T>(); } else { inbox = new ActorInboxLocal <S, T>(); } var item = new ActorItem(actor, inbox, actor.Flags); parent.Actor.LinkChild(item); // Auto register if there are config settings and we // have the variable name it was assigned to. ActorContext.System(actor.Id).Settings.GetProcessRegisteredName(actor.Id).Iter(regName => { // Also check if 'dispatch' is specified in the config, if so we will // register the Process as a role dispatcher PID instead of just its // PID. ActorContext.System(actor.Id).Settings.GetProcessDispatch(actor.Id) .Match( Some: disp => Process.register(regName, Disp[$"role-{disp}"][Role.Current].Append(actor.Id.Skip(1))), None: () => Process.register(regName, actor.Id) ); }); try { inbox.Startup(actor, parent, cluster, maxMailboxSize); if (!lazy) { TellSystem(actor.Id, SystemMessage.StartupProcess); } } catch { item?.Actor?.ShutdownProcess(false); throw; } return(item.Actor.Id); }
public static ActorSystemMessage AddToStore(IProcess process, IActorInbox inbox, ProcessFlags flags) => new AddToStoreMessage(process, inbox, flags);
internal Actor(Option <ICluster> cluster, ActorItem parent, ProcessName name, Func <S, T, S> actor, Func <IActor, S> setup, ProcessFlags flags) { if (setup == null) { throw new ArgumentNullException(nameof(setup)); } if (actor == null) { throw new ArgumentNullException(nameof(actor)); } this.cluster = cluster; this.flags = flags; actorFn = actor; setupFn = setup; Parent = parent; Name = name; Id = parent.Actor.Id[name]; SetupClusterStatePersist(cluster, flags); }
public ClearConfigOp(string name, string prop, ProcessFlags flags) { Name = name; Prop = prop; Flags = flags; }
public Actor(Option <ICluster> cluster, ActorItem parent, ProcessName name, Action <T> actor, ProcessFlags flags) : this(cluster, parent, name, (s, t) => { actor(t); return(default(S)); }, () => default(S), flags) { }
public ClearAllOp(ProcessFlags flags) { Flags = flags; }
public ActorItem ActorCreate <S, T>(ActorItem parent, ProcessName name, Func <S, T, S> actorFn, Func <S> setupFn, Func <S, ProcessId, S> termFn, ProcessFlags flags, int maxMailboxSize = -1) { if (ProcessDoesNotExist(nameof(ActorCreate), parent.Actor.Id)) { return(null); } var actor = new Actor <S, T>(Cluster, parent, name, actorFn, _ => setupFn(), termFn, Process.DefaultStrategy, flags, Settings, System); IActorInbox inbox = null; if ((actor.Flags & ProcessFlags.ListenRemoteAndLocal) == ProcessFlags.ListenRemoteAndLocal && Cluster.IsSome) { inbox = new ActorInboxDual <S, T>(); } else if ((actor.Flags & ProcessFlags.PersistInbox) == ProcessFlags.PersistInbox && Cluster.IsSome) { inbox = new ActorInboxRemote <S, T>(); } else { inbox = new ActorInboxLocal <S, T>(); } var item = new ActorItem(actor, inbox, actor.Flags); try { parent.Actor.LinkChild(item); inbox.Startup(actor, actor.Parent, Cluster, maxMailboxSize == -1 ? Settings.GetProcessMailboxSize(actor.Id) : maxMailboxSize ); } catch (Exception e) { item.Actor.ShutdownProcess(false); logSysErr(new ProcessException($"Process failed starting up: {e.Message}", actor.Id.Path, actor.Parent.Actor.Id.Path, e)); } return(item); }
public ActorItem ActorCreate <T>(ActorItem parent, ProcessName name, Action <T> actorFn, ProcessFlags flags) { return(ActorCreate <Unit, T>(parent, name, (s, t) => { actorFn(t); return unit; }, () => unit, flags)); }