/// <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; }
/// <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; }
/// <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); }
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)); }
/// <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), "#")))); }
/// <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, "#"))); }
/// <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))); }
/// <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)))); }