Exemplo n.º 1
0
        /// <summary>
        /// Provided only for unit-testing purposes
        /// </summary>
        protected ActorGrain(string id = null, IActorRuntime runtime = null)
        {
            var @interface = ActorGrainImplementation.InterfaceOf(GetType());

            Path    = ActorPath.For(@interface, id ?? Guid.NewGuid().ToString("N"));
            Runtime = runtime;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Provided only for unit-testing purposes
        /// </summary>
        protected ActorGrain(string id = null, IActorRuntime runtime = null)
        {
            var @interface = InterfaceOf(GetType());

            Path         = ActorPath.For(@interface, id ?? Guid.NewGuid().ToString("N"));
            System       = runtime?.System;
            this.runtime = runtime;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Run-once initialization routine invoked right after actor grain construction and just before activate
        /// TODO: this is not ideal since IActorRuntime cannot be created here. Still, need support for IActivationFilter from Orleans
        /// </summary>
        internal virtual void Initialize(IServiceProvider services, string id)
        {
            var clusterSystem = services.GetRequiredService <ClusterActorSystem>();

            System = clusterSystem;

            var implementation = clusterSystem.ImplementationOf(GetType());

            middleware = implementation.Middleware;

            Path = ActorPath.For(implementation.Interface, id);
        }
Exemplo n.º 4
0
        public override Task OnActivateAsync()
        {
            var system = ServiceProvider.GetRequiredService <ClusterActorSystem>();

            var implementation = system.ImplementationOf(GetType());

            middleware = implementation.Middleware;

            Path    = ActorPath.For(implementation.Interface, this.GetPrimaryKeyString());
            Runtime = new ActorRuntime(system, this);

            return(middleware.Receive(this, Activate.Message, Receive));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Acquires the typed actor reference for the given id and type of the worker actor.
 /// The type could be either an interface or implementation class.
 /// </summary>
 /// <typeparam name="TActor">The type of the actor</typeparam>
 /// <param name="system">The reference to actor system</param>
 public static ActorRef <TActor> TypedWorkerOf <TActor>(this IActorSystem system) where TActor : IActorGrain, IGrainWithStringKey
 {
     return(new ActorRef <TActor>(system.ActorOf(ActorPath.For(typeof(TActor), "#"))));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Acquires the actor reference for the given worker type.
 /// </summary>
 /// <param name="system">The reference to actor system</param>
 /// <param name="interface">The worker interface</param>
 /// <returns>An actor reference</returns>
 public static ActorRef WorkerOf(this IActorSystem system, Type @interface)
 {
     return(system.ActorOf(ActorPath.For(@interface, "#")));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Acquires the actor reference for the given actor type and id.
 /// </summary>
 /// <param name="system">The reference to actor system</param>
 /// <param name="interface">The actor interface</param>
 /// <param name="id">The actor id</param>
 /// <returns>An actor reference</returns>
 public static ActorRef ActorOf(this IActorSystem system, Type @interface, string id)
 {
     return(system.ActorOf(ActorPath.For(@interface, id)));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Acquires the typed actor reference for the given id and type of the actor.
 /// The type could be either an interface or implementation class.
 /// </summary>
 /// <typeparam name="TActor">The type of the actor</typeparam>
 /// <param name="system">The reference to actor system</param>
 /// <param name="id">The id</param>
 public static ActorRef <TActor> TypedActorOf <TActor>(this IActorSystem system, string id) where TActor : IActorGrain
 {
     return(new ActorRef <TActor>(system.ActorOf(ActorPath.For(typeof(TActor), id))));
 }