Exemplo n.º 1
0
        public static TActorInterface Create <TActorInterface>(ActorId actorId, string applicationName = null,
                                                               string serviceName = null) where TActorInterface : IActor
        {
            if (ActorModel.Runtime == null)
            {
                throw new InvalidOperationException("The P# runtime has not been initialized.");
            }

            MachineId mid = ActorModel.Runtime.GetCurrentMachineId();

            ActorModel.Runtime.Log($"<ActorModelLog> Machine '{mid.Name}' is " +
                                   $"waiting to get or construct proxy with id '{actorId.Id}'.");

            ActorModel.Runtime.SendEvent(ProxyFactory, new ActorFactory.CreateProxyEvent(
                                             mid, actorId, typeof(TActorInterface)));

            ActorFactory.ProxyConstructedEvent receivedEvent = ActorModel.Runtime.Receive(
                typeof(ActorFactory.ProxyConstructedEvent)) as ActorFactory.ProxyConstructedEvent;

            TActorInterface proxy = (TActorInterface)receivedEvent.Proxy;

            ActorModel.Runtime.Log($"<ActorModelLog> Machine '{mid.Name}' received " +
                                   $"proxy with id '{actorId.Id}'.");

            return(proxy);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets or creates a grain.
        /// </summary>
        /// <typeparam name="TGrainInterface">TGrainInterface</typeparam>
        /// <param name="primaryKey">PrimaryKey</param>
        /// <returns>TGrainInterface</returns>
        private TGrainInterface GetOrCreateGrain <TGrainInterface>(Guid primaryKey)
        {
            if (ActorModel.Runtime == null)
            {
                throw new InvalidOperationException("The P# runtime has not been initialized.");
            }

            MachineId mid = ActorModel.Runtime.GetCurrentMachineId();

            ActorModel.Runtime.Log($"<ActorModelLog> Machine '{mid.Name}' is " +
                                   $"waiting to get or construct proxy with id '{primaryKey}'.");

            ActorModel.Runtime.SendEvent(GrainClient.ProxyFactory, new ActorFactory.CreateProxyEvent(
                                             mid, primaryKey, typeof(TGrainInterface)));

            ActorFactory.ProxyConstructedEvent receivedEvent = ActorModel.Runtime.Receive(
                typeof(ActorFactory.ProxyConstructedEvent)) as ActorFactory.ProxyConstructedEvent;

            TGrainInterface proxy = (TGrainInterface)receivedEvent.Proxy;

            ActorModel.Runtime.Log($"<ActorModelLog> Machine '{mid.Name}' received " +
                                   $"proxy with id '{primaryKey}'.");

            return(proxy);
        }