-
Notifications
You must be signed in to change notification settings - Fork 2k
/
GrainServiceFactory.cs
35 lines (29 loc) · 1.4 KB
/
GrainServiceFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using Orleans.Services;
namespace Orleans.Runtime
{
public interface IGrainServiceFactory
{
/// <summary>
/// Creates a grain reference for a grain service instance on a given silo.
/// This is used by grain indexing.
/// </summary>
GrainReference MakeGrainServiceReference(int typeData, string systemGrainId, SiloAddress siloAddress);
/// <summary>
/// Casts a grain reference to a typed grain service reference.
/// Used by grain indexing.
/// </summary>
T CastToGrainServiceReference<T>(GrainReference grainReference) where T : IGrainService;
}
internal class GrainServiceFactory : IGrainServiceFactory
{
private readonly IRuntimeClient runtimeClient;
public GrainServiceFactory(IRuntimeClient runtimeClient)
{
this.runtimeClient = runtimeClient;
}
public GrainReference MakeGrainServiceReference(int typeData, string systemGrainId, SiloAddress siloAddress)
=> GrainReference.FromGrainId(GrainId.GetGrainServiceGrainId(typeData, systemGrainId), this.runtimeClient.GrainReferenceRuntime, systemTargetSilo: siloAddress);
public T CastToGrainServiceReference<T>(GrainReference grainReference) where T : IGrainService
=> this.runtimeClient.InternalGrainFactory.GetSystemTarget<T>(grainReference.GrainId, grainReference.SystemTargetSilo);
}
}