示例#1
0
        /// <summary>
        /// Constructs a new ActorSystem with a name.
        /// </summary>
        /// <param name="name">the string name of the system</param>
        private ActorSystem(string name)
        {
            // top level
            Actor system = new _System();
            var systemContext =
                new ActorContext(
                    this,
                    typeof(_System),
                    system,
                    ActorPath.RootName,
                    new Props(),
                    ActorRef.None,
                    new ActorPath(ActorPath.SystemName));

            // user guardian
            Actor userGuardian = new _UserGuardian();
            var userGuardianContext =
                new ActorContext(
                    this,
                    typeof(_UserGuardian),
                    userGuardian,
                    "user",
                    new Props(),
                    systemContext.Self,
                    systemContext.Path);

            // system guardian
            Actor systemGuardian = new _System();
            var systemGuardianContext =
                new ActorContext(
                    this,
                    typeof(_System),
                    systemGuardian,
                    "sys",
                    new Props(),
                    systemContext.Self,
                    systemContext.Path);

            Context = userGuardianContext;

            SystemContext = systemGuardianContext;

            DeadLetters =
                SystemContext.ActorOf(
                    typeof(DeadLetters),
                    Props.None,
                    "deadLetters");

            Name = name;

            Scheduler = new Scheduler();

            StartTime = DateTime.Now;
        }
示例#2
0
        /// <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);
        }
示例#3
0
        /// <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;
        }
示例#4
0
        /// <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;
        }
示例#5
0
 /// <summary>
 /// Forwards the message and references the ActorContext's
 /// Sender as the sender.
 /// </summary>
 /// <param name="message">the object message</param>
 /// <param name="context">the ActorContext holding the Sender</param>
 public void Forward(object message, ActorContext context)
 {
     this.Tell(message, context.Sender);
 }
示例#6
0
 /// <summary>
 /// Constructs my default state with a context.
 /// </summary>
 /// <param name="context">the ActorContext</param>
 internal ActorRef(ActorContext context)
 {
     Context = context;
 }
示例#7
0
 /// <summary>
 /// Forwards the message and references the ActorContext's
 /// Sender as the sender.
 /// </summary>
 /// <param name="message">the object message</param>
 /// <param name="context">the ActorContext holding the Sender</param>
 public void Forward(object message, ActorContext context)
 {
     this.Tell(message, context.Sender);
 }
示例#8
0
 /// <summary>
 /// Constructs my default state with a context.
 /// </summary>
 /// <param name="context">the ActorContext</param>
 internal ActorRef(ActorContext context)
 {
     Context = context;
 }