Beispiel #1
0
        public bool TryGet(GrainType grainType, out IGrainContextActivator activator)
        {
            if (!_grainClassMap.TryGetGrainClass(grainType, out var grainClass) ||
                !typeof(Grain).IsAssignableFrom(grainClass))
            {
                activator = null;
                return(false);
            }

            var             sharedComponents  = _sharedComponentsResolver.GetComponents(grainType);
            IGrainActivator instanceActivator = sharedComponents.GetComponent <IGrainActivator>();

            if (instanceActivator is null)
            {
                throw new InvalidOperationException($"Could not find a suitable {nameof(IGrainActivator)} implementation for grain type {grainType}");
            }

            var(activationCollector, collectionAgeLimit) = GetCollectionAgeLimit(grainType, grainClass);

            activator = new ActivationDataActivator(
                instanceActivator,
                _placementStrategyResolver.GetPlacementStrategy(grainType),
                activationCollector,
                collectionAgeLimit,
                _messagingOptions,
                _maxWarningRequestProcessingTime,
                _maxRequestProcessingTime,
                _loggerFactory,
                _serviceProvider,
                _grainRuntime ??= _serviceProvider.GetRequiredService <IGrainRuntime>(),
                _grainReferenceActivator,
                sharedComponents,
                _activationMessageScheduler ??= _serviceProvider.GetRequiredService <ActivationMessageScheduler>());
            return(true);
        }
 public ActivationDataActivator(
     IGrainActivator grainActivator,
     IServiceProvider serviceProvider,
     GrainTypeSharedContext sharedComponents,
     ILogger <WorkItemGroup> workItemGroupLogger,
     ILogger <ActivationTaskScheduler> activationTaskSchedulerLogger,
     SchedulerStatisticsGroup schedulerStatisticsGroup,
     IOptions <SchedulingOptions> schedulingOptions,
     IOptions <StatisticsOptions> statisticsOptions)
 {
     _workItemGroupLogger           = workItemGroupLogger;
     _activationTaskSchedulerLogger = activationTaskSchedulerLogger;
     _schedulerStatisticsGroup      = schedulerStatisticsGroup;
     _schedulingOptions             = schedulingOptions;
     _statisticsOptions             = statisticsOptions;
     _grainActivator      = grainActivator;
     _serviceProvider     = serviceProvider;
     _sharedComponents    = sharedComponents;
     _createWorkItemGroup = context => new WorkItemGroup(
         context,
         _workItemGroupLogger,
         _activationTaskSchedulerLogger,
         _schedulerStatisticsGroup,
         _statisticsOptions,
         _schedulingOptions);
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrainCreator"/> class.
 /// </summary>
 /// <param name="grainActivator">The activator used to used to create new grains</param>
 /// <param name="getGrainRuntime">The delegate used to get the grain runtime.</param>
 /// <param name="protocolServicesFactory"></param>
 public GrainCreator(
     IGrainActivator grainActivator,
     Factory <IGrainRuntime> getGrainRuntime)
 {
     this.grainActivator = grainActivator;
     this.grainRuntime   = new Lazy <IGrainRuntime>(() => getGrainRuntime());
 }
Beispiel #4
0
 public TestGrainCreator(IGrainRuntime runtime, IServiceProvider serviceProvider)
 {
     _runtime         = runtime;
     _activator       = new DefaultGrainActivator(serviceProvider);
     _runtimeProperty = typeof(Grain).GetProperty("Runtime", BindingFlags.Instance | BindingFlags.NonPublic);
     _identityField   = typeof(Grain).GetField("Identity", BindingFlags.Instance | BindingFlags.NonPublic);
 }
Beispiel #5
0
 public TestGrainCreator(IGrainRuntime runtime, IServiceProvider serviceProvider)
 {
     _runtime         = runtime ?? throw new ArgumentNullException(nameof(runtime));
     _activator       = new DefaultGrainActivator(serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)));
     _identityField   = typeof(Grain).GetField("Identity", BindingFlags.Instance | BindingFlags.NonPublic);
     _runtimeProperty = typeof(Grain).GetProperty("Runtime", BindingFlags.Instance | BindingFlags.NonPublic);
 }
Beispiel #6
0
 public TestGrainCreator(IGrainRuntime runtime)
 {
     _runtime          = runtime;
     _activator        = new DefaultGrainActivator();
     _runtimeProperty  = typeof(Grain).GetProperty("Runtime", BindingFlags.Instance | BindingFlags.NonPublic);
     _identityField    = typeof(Grain).GetField("Identity", BindingFlags.Instance | BindingFlags.NonPublic);
     _setStorageMethod = typeof(Grain <>).GetInterfaces().First(i => i.Name == "IStatefulGrain").GetMethod("SetStorage");
 }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrainCreator"/> class.
 /// </summary>
 /// <param name="grainActivator">The activator used to used to create new grains</param>
 /// <param name="getGrainRuntime">The delegate used to get the grain runtime.</param>
 /// <param name="protocolServicesFactory"></param>
 public GrainCreator(
     IGrainActivator grainActivator,
     Factory <IGrainRuntime> getGrainRuntime,
     Factory <Grain, IMultiClusterRegistrationStrategy, ProtocolServices> protocolServicesFactory)
 {
     this.grainActivator          = grainActivator;
     this.protocolServicesFactory = protocolServicesFactory;
     this.grainRuntime            = new Lazy <IGrainRuntime>(() => getGrainRuntime());
 }
Beispiel #8
0
        public TestGrainCreator(IGrainRuntime runtime, IServiceProvider serviceProvider)
        {
            _runtime         = runtime;
            _identityField   = typeof(Grain).GetField("Identity", BindingFlags.Instance | BindingFlags.NonPublic);
            _runtimeProperty = typeof(Grain).GetProperty("Runtime", BindingFlags.Instance | BindingFlags.NonPublic);

            _grainReferenceFromGrainMethod = typeof(GrainReference).GetMethod("FromGrainId", BindingFlags.Static | BindingFlags.NonPublic);
            _activationDataField           = typeof(Grain).GetField("Data", BindingFlags.Instance | BindingFlags.NonPublic);

            var grainIdType = Type.GetType("Orleans.Runtime.GrainId, Orleans.Core.Abstractions");

            if (grainIdType == null)
            {
                throw new InvalidOperationException();
            }

            var getGrainIdMethods = grainIdType.GetMethods(BindingFlags.Static | BindingFlags.NonPublic).Where(p => p.Name == "GetGrainId").ToArray();

            foreach (var method in getGrainIdMethods)
            {
                var parameters = method.GetParameters();
                if (parameters.Length == 2 && parameters[1].ParameterType == typeof(string))
                {
                    _createGrainIdString = (Func <long, string, object>)method.CreateDelegate(typeof(Func <long, string, object>));
                }
                else if (parameters.Length == 3 && parameters[1].ParameterType == typeof(Guid))
                {
                    _createGrainIdGuid = (Func <long, Guid, string, object>)method.CreateDelegate(typeof(Func <long, Guid, string, object>));
                }
                else if (parameters.Length == 3 && parameters[1].ParameterType == typeof(long))
                {
                    _createGrainIdLong = (Func <long, long, string, object>)method.CreateDelegate(typeof(Func <long, long, string, object>));
                }
            }

            _activationDataType = Type.GetType("Orleans.Runtime.ActivationData, Orleans.Runtime");
            if (_activationDataType == null)
            {
                throw new InvalidOperationException();
            }

            _grainReferenceField = _activationDataType.GetField("GrainReference", BindingFlags.NonPublic | BindingFlags.Instance);
            if (_grainReferenceField == null)
            {
                throw new InvalidOperationException();
            }

            _addressField = _activationDataType.GetField("<Address>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic);
            if (_addressField == null)
            {
                throw new InvalidOperationException();
            }

            _itemsField = _activationDataType.GetField("<Items>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic);
            if (_itemsField == null)
            {
                throw new InvalidOperationException();
            }

            var activationAddressType = Type.GetType("Orleans.Runtime.ActivationAddress, Orleans.Core.Abstractions");

            if (activationAddressType == null)
            {
                throw new InvalidOperationException();
            }

            _newActivationAddressMethod = activationAddressType.GetMethod("NewActivationAddress");
            if (_newActivationAddressMethod == null)
            {
                throw new InvalidOperationException();
            }

            _activator = new DefaultGrainActivator(serviceProvider);
        }
Beispiel #9
0
 public ActorGrainActivator(IGrainActivator registeredActivator) =>
 this.registeredActivator = registeredActivator;
Beispiel #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrainCreator"/> class.
 /// </summary>
 /// <param name="grainActivator">The activator used to used to create new grains</param>
 /// <param name="getGrainRuntime">
 /// The delegate used to get the grain runtime.
 /// </param>
 public GrainCreator(IGrainActivator grainActivator, Func <IGrainRuntime> getGrainRuntime)
 {
     this.grainActivator = grainActivator;
     this.grainRuntime   = new Lazy <IGrainRuntime>(getGrainRuntime);
 }