Example #1
0
        /// <summary>
        /// This will decorate a factory method and make it possible to directly create an actor.
        /// <remarks>NOTE! Only use this in tests</remarks>
        /// </summary>
        private static Actor CreateActorDirectly <T>(Func <T> createActor, out LocalActorRef localActorRef) where T : Actor
        {
            var testActorSystem = new TestActorSystem();

            localActorRef = new LocalActorRef(testActorSystem, A.Dummy <ActorInstantiator>(), new RootActorPath("fake"), testActorSystem.CreateDefaultMailbox(), A.Dummy <InternalActorRef>());
            LocalActorRefStack.PushActorRefToStack(localActorRef);
            var actor = createActor();

            LocalActorRefStack.PopActorAndMarkerFromStack();
            return(actor);
        }
Example #2
0
 /// <summary>
 /// This one is used for internal testing only
 /// </summary>
 internal Actor(LocalActorRef actorRef, ActorSystem system, LocalActorRefFactory localActorRefFactory)
 {
     if (actorRef == null)
     {
         if (!LocalActorRefStack.TryGetActorRefFromStack(out actorRef))
         {
             throw new InvalidOperationException(StringFormat.SafeFormat("Cannot create a new instance of type {0} directly using new(). An actor can only be created via the CreateActor methods.", GetType().FullName));
         }
         LocalActorRefStack.MarkActorRefConsumedInStack();
     }
     _system = system;
     _self   = actorRef;
     PrepareForConfiguringMessageHandler();
     _localActorRefFactory = localActorRefFactory;
 }
Example #3
0
        protected Actor()
        {
            LocalActorRef actorRef;

            if (!LocalActorRefStack.TryGetActorRefFromStack(out actorRef))
            {
                throw new InvalidOperationException(StringFormat.SafeFormat("Cannot create a new instance of type {0} directly using new(). An actor can only be created via the CreateActor methods.", GetType().FullName));
            }
            LocalActorRefStack.MarkActorRefConsumedInStack();
            _system = actorRef.System;
            _self   = actorRef;
            PrepareForConfiguringMessageHandler();
            _localActorRefFactory = _system.LocalActorRefFactory;
            _selfScheduler        = new SelfScheduler(_system.Scheduler, _self);
        }
Example #4
0
 public static ImmutableStack <LocalActorRef> GetActorRefStack()
 {
     return(LocalActorRefStack.GetActorRefStack_ForTestingONLY() ?? ImmutableStack <LocalActorRef> .Empty);
 }