/// <summary> /// Constructs a new ActorContext. /// </summary> /// <param name="system">the ActorSystem within which the actor is created</param> /// <param name="actorType">the Type of the actor</param> /// <param name="actor">the Actor to create</param> /// <param name="name">the string name to give the Actor</param> /// <param name="props">the Props to pass individually as class arguments</param> /// <param name="parent">the ActorRef of the parent of the Actor being created</param> /// <param name="parentPath">the ActorPath of the Actor being created</param> /// <param name="suspended">the bool indicating whether the actor is being created as suspended</param> /// <param name="channel">the IChannel the actor will use</param> /// <param name="fiber">the IFiber the actor will use</param> internal ActorContext( ActorSystem system, Type actorType, Actor actor, string name, Props props, ActorRef parent, ActorPath parentPath, bool suspended, IChannel<Delivery> channel, IFiber fiber) { Actor = actor; Actor.InternalContext = this; Channel = channel; Fiber = fiber; Children = new List<ActorRef>(0); Parent = parent; Path = parentPath.WithName(name); Props = props; Receivers = new Stack<Receive>(1); Self = new ActorRef(this); Sender = ActorRef.NoSender; _Suspended = suspended; System = system; _Terminated = false; Type = actorType; Start(); }
/// <summary> /// Creates the Actor of type actorType by passing the /// individual props as class arguments. /// </summary> /// <param name="actorType">the Type of the Actor subclass being created</param> /// <param name="props">the Props to pass as class arguments</param> /// <returns></returns> internal static Actor CreateWith(Type actorType, Props props) { int argumentCount = props.Count; int argumentIndex = 0; Type[] types = new Type[argumentCount]; object[] arguments = new object[argumentCount]; foreach (object argument in props.Values) { types[argumentIndex] = argument.GetType(); arguments[argumentIndex] = argument; ++argumentIndex; } Actor actor = (Actor) Activator.CreateInstance( actorType, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance | BindingFlags.Instance, null, arguments, null); return actor; }
/// <summary> /// Creates a new Actor and returns its ActorRef. The new Actor /// is of type actorType and will be instantiated with the class /// arguments found in props. /// </summary> /// <param name="actorType">the Type of the Actor to create</param> /// <param name="props">the Props to pass as class arguments</param> /// <param name="name">the string name of the actor</param> /// <returns>ActorRef</returns> public ActorRef ActorOf(Type actorType, Props props, string name) { // TODO: Full creations should be asynchronous ValidateName(name); Actor actor = ActorCreator.CreateWith(actorType, props); ActorContext context = new ActorContext( System, actorType, actor, name, props, this.Self, this.Path); Children.Add(context.Self); context.System = System; return context.Self; }
/// <summary> /// Creates a new Actor and returns its ActorRef. The new Actor /// is of type actorType and will be instantiated with the class /// arguments found in props. /// </summary> /// <param name="actorType">the Type of the Actor to create</param> /// <param name="props">the Props to pass as class arguments</param> /// <param name="name">the string name of the actor</param> /// <param name="suspended"></param> /// <param name="channel"></param> /// <param name="fiber"></param> /// <returns>ActorRef</returns> private ActorRef ActorOf( Type actorType, Props props, string name, bool suspended, IChannel<Delivery> channel, IFiber fiber) { // TODO: Full creations should be asynchronous ValidateName(name); Actor actor = ActorCreator.CreateWith(actorType, props); ActorContext context = new ActorContext( System, actorType, actor, name, props, this.Self, this.Path, suspended, channel, fiber); Children.Add(context.Self); context.System = System; return context.Self; }
/// <summary> /// Creates a new Actor and returns its ActorRef. The new Actor /// is of type actorType and will be instantiated with the class /// arguments found in props. /// </summary> /// <param name="actorType">the Type of the Actor to create</param> /// <param name="props">the Props to pass as class arguments</param> /// <returns>ActorRef</returns> public ActorRef ActorOf(Type actorType, Props props) { return ActorOf(actorType, props, GenerateActorName()); }
/// <summary> /// Constructs a new ActorContext. /// </summary> /// <param name="system">the ActorSystem within which the actor is created</param> /// <param name="actor">the Actor to create</param> /// <param name="name">the string name to give the Actor</param> /// <param name="props">the Props to pass individually as class arguments</param> /// <param name="parent">the ActorRef of the parent of the Actor being created</param> /// <param name="parentPath">the ActorPath of the Actor being created</param> internal ActorContext( ActorSystem system, Type actorType, Actor actor, string name, Props props, ActorRef parent, ActorPath parentPath) : this(system, actorType, actor, name, props, parent, parentPath, false, new Channel<Delivery>(), new PoolFiber()) { }
/// <summary> /// Creates a new Actor of type actorType, with class /// arguments found in props, and named by the name. /// </summary> /// <param name="actorType">the Type of the Actor to create</param> /// <param name="props">the Props to pass as individual class arguments</param> /// <returns>ActorRef</returns> /// <param name="name">the string name of the actor to create</param> /// <returns>ActorRef</returns> public ActorRef ActorOf(Type actorType, Props props, string name) { return Context.ActorOf(actorType, props, name); }
/// <summary> /// Creates a new Actor of type actorType and with class /// arguments found in props. /// </summary> /// <param name="actorType">the Type of the Actor to create</param> /// <param name="props">the Props to pass as individual class arguments</param> /// <returns>ActorRef</returns> public ActorRef ActorOf(Type actorType, Props props) { return Context.ActorOf(actorType, props); }
/// <summary> /// Creates a new Actor and returns its ActorRef. The new Actor /// is of type actorType and will be instantiated with the class /// arguments found in props. /// </summary> /// <param name="actorType">the Type of the Actor to create</param> /// <param name="props">the Props to pass as class arguments</param> /// <returns>ActorRef</returns> public ActorRef ActorOf(Type actorType, Props props) { return(ActorOf(actorType, props, GenerateActorName())); }