Exemple #1
0
 /// <summary>
 /// Create a new process by name.
 /// If this is called from within a process' message loop
 /// then the new process will be a child of the current process.  If it is called from
 /// outside of a process, then it will be made a child of the root 'user' process.
 /// </summary>
 /// <typeparam name="T">Type of messages that the child-process can accept</typeparam>
 /// <param name="Name">Name of the child-process</param>
 /// <param name="Setup">Startup and restart function</param>
 /// <param name="Inbox">Function that is the process</param>
 /// <param name="Flags">Process flags</param>
 /// <param name="Strategy">Failure supervision strategy</param>
 /// <param name="Terminated">Message function to call when a Process [that this Process
 /// watches] terminates</param>
 /// <returns>A ProcessId that identifies the child</returns>
 public static ProcessId spawn <S, T>(
     ProcessName Name,
     Func <S> Setup,
     Func <S, T, S> Inbox,
     ProcessFlags Flags = ProcessFlags.Default,
     State <StrategyContext, Unit> Strategy = null,
     int MaxMailboxSize = ProcessSetting.DefaultMailboxSize,
     Func <S, ProcessId, S> Terminated = null
     ) =>
 ActorContext.ActorCreate(ActorContext.SelfProcess, Name, Inbox, Setup, Terminated, Strategy, Flags, MaxMailboxSize, false);
Exemple #2
0
 /// <summary>
 /// Create N child processes.
 /// The name provided will be used as a basis to generate the child names.  Each child will
 /// be named "name-index" where index starts at zero.
 /// If this is called from within a process' message loop
 /// then the new processes will be a children of the current process.  If it is called from
 /// outside of a process, then they will be made a child of the root 'user' process.
 /// </summary>
 /// <typeparam name="S">State type</typeparam>
 /// <typeparam name="T">Type of messages that the child-process can accept</typeparam>
 /// <param name="Spec">Map of IDs and State for generating child workers</param>
 /// <param name="Name">Name of the child-process</param>
 /// <param name="Inbox">Function that is the process</param>
 /// <param name="Flags">Process flags</param>
 /// <param name="Strategy">Failure supervision strategy</param>
 /// <param name="Terminated">Message function to call when a Process [that this Process
 /// watches] terminates</param>
 /// <returns>ProcessId IEnumerable</returns>
 public static IEnumerable <ProcessId> spawnMany <S, T>(
     ProcessName Name,
     Map <int, Func <S> > Spec,
     Func <S, T, S> Inbox,
     ProcessFlags Flags = ProcessFlags.Default,
     State <StrategyContext, Unit> Strategy = null,
     int MaxMailboxSize = ProcessSetting.DefaultMailboxSize,
     Func <S, ProcessId, S> Terminated = null
     ) =>
 Map.map(Spec, (id, state) => ActorContext.ActorCreate(ActorContext.SelfProcess, $"{Name}-{id}", Inbox, state, Terminated, Strategy, Flags, MaxMailboxSize, false)).Values.ToList();
Exemple #3
0
 /// <summary>
 /// Create N child processes.
 /// The name provided will be used as a basis to generate the child names.  Each child will
 /// be named "name-index" where index starts at zero.
 /// If this is called from within a process' message loop
 /// then the new processes will be a children of the current process.  If it is called from
 /// outside of a process, then they will be made a child of the root 'user' process.
 /// </summary>
 /// <typeparam name="T">Type of messages that the child-process can accept</typeparam>
 /// <param name="Count">Number of processes to spawn</param>
 /// <param name="Setup">Startup and restart function</param>
 /// <param name="Name">Name of the child-process</param>
 /// <param name="Inbox">Function that is the process</param>
 /// <param name="Flags">Process flags</param>
 /// <param name="Strategy">Failure supervision strategy</param>
 /// <param name="Terminated">Message function to call when a Process [that this Process
 /// watches] terminates</param>
 /// <returns>ProcessId IEnumerable</returns>
 public static IEnumerable <ProcessId> spawnMany <S, T>(
     int Count,
     ProcessName Name,
     Func <S> Setup,
     Func <S, T, S> Inbox,
     ProcessFlags Flags = ProcessFlags.Default,
     State <StrategyContext, Unit> Strategy = null,
     int MaxMailboxSize = ProcessSetting.DefaultMailboxSize,
     Func <S, ProcessId, S> Terminated = null
     ) =>
 List.map(Range(0, Count), n => ActorContext.ActorCreate(ActorContext.SelfProcess, $"{Name}-{n}", Inbox, Setup, Terminated, Strategy, Flags, MaxMailboxSize, false)).ToList();
 /// <summary>
 /// Create N child processes.
 /// The name provided will be used as a basis to generate the child names.  Each child will
 /// be named "name-index" where index starts at zero.
 /// If this is called from within a process' message loop
 /// then the new processes will be a children of the current process.  If it is called from
 /// outside of a process, then they will be made a child of the root 'user' process.
 /// </summary>
 /// <typeparam name="T">Type of messages that the child-process can accept</typeparam>
 /// <param name="count">Number of processes to spawn</param>
 /// <param name="setup">Startup and restart function</param>
 /// <param name="name">Name of the child-process</param>
 /// <param name="messageHandler">Function that is the process</param>
 /// <param name="flags">Process flags</param>
 /// <returns>ProcessId IEnumerable</returns>
 public static IEnumerable <ProcessId> spawnN <S, T>(int count, ProcessName name, Func <S> setup, Func <S, T, S> messageHandler, ProcessFlags flags = ProcessFlags.Default) =>
 List.map(Range(0, count), n => ActorContext.ActorCreate(ActorContext.SelfProcess, name + "-" + n, messageHandler, setup, flags)).ToList();
 /// <summary>
 /// Create a new process by name.
 /// If this is called from within a process' message loop
 /// then the new process will be a child of the current process.  If it is called from
 /// outside of a process, then it will be made a child of the root 'user' process.
 /// </summary>
 /// <typeparam name="T">Type of messages that the child-process can accept</typeparam>
 /// <param name="name">Name of the child-process</param>
 /// <param name="setup">Startup and restart function</param>
 /// <param name="messageHandler">Function that is the process</param>
 /// <param name="flags">Process flags</param>
 /// <returns>A ProcessId that identifies the child</returns>
 public static ProcessId spawn <S, T>(ProcessName name, Func <S> setup, Func <S, T, S> messageHandler, ProcessFlags flags = ProcessFlags.Default) =>
 ActorContext.ActorCreate(ActorContext.SelfProcess, name, messageHandler, setup, flags);
 /// <summary>
 /// Spawns a new process with N worker processes, each message is sent to one worker
 /// process in a round robin fashion.
 /// </summary>
 /// <typeparam name="T">Message type</typeparam>
 /// <param name="name">Delegator process name</param>
 /// <param name="spec">Map of IDs and State for generating child workers</param>
 /// <param name="messageHandler">Worker message handler</param>
 /// <param name="flags">Process flags</param>
 /// <returns>Process ID of the delegator process</returns>
 public static ProcessId spawnRoundRobin <S, T>(ProcessName name, Map <int, Func <S> > spec, Func <S, T, S> messageHandler, ProcessFlags flags = ProcessFlags.Default) =>
 spawn <Unit, T>(name, () => ignore(Map.map(spec, (id, state) => ActorContext.ActorCreate(ActorContext.SelfProcess, "worker-" + id, messageHandler, state, flags))), (_, msg) => HandleNoChild(() => fwdNextChild(msg)), flags);
 /// <summary>
 /// Create N child processes.
 /// The name provided will be used as a basis to generate the child names.  Each child will
 /// be named "name-index" where index starts at zero.
 /// If this is called from within a process' message loop
 /// then the new processes will be a children of the current process.  If it is called from
 /// outside of a process, then they will be made a child of the root 'user' process.
 /// </summary>
 /// <typeparam name="S">State type</typeparam>
 /// <typeparam name="T">Type of messages that the child-process can accept</typeparam>
 /// <param name="spec">Map of IDs and State for generating child workers</param>
 /// <param name="name">Name of the child-process</param>
 /// <param name="messageHandler">Function that is the process</param>
 /// <param name="flags">Process flags</param>
 /// <returns>ProcessId IEnumerable</returns>
 public static IEnumerable <ProcessId> spawnN <S, T>(ProcessName name, Map <int, Func <S> > spec, Func <S, T, S> messageHandler, ProcessFlags flags = ProcessFlags.Default) =>
 Map.map(spec, (id, state) => ActorContext.ActorCreate(ActorContext.SelfProcess, name + "-" + id, messageHandler, state, flags)).Values.ToList();