Esempio n. 1
0
#pragma warning disable 612,618
        internal static PlacementStrategy GetPlacementStrategy(Type grainClass)
        {
            PlacementStrategy placement;

            if (GetPlacementStrategy <StatelessWorkerAttribute>(
                    grainClass,
                    (StatelessWorkerAttribute attr) =>
            {
                return(new StatelessWorkerPlacement(attr.MaxLocalWorkers));
            },
                    out placement))
            {
                return(placement);
            }

            if (GetPlacementStrategy <PlacementAttribute>(
                    grainClass,
                    a => a.PlacementStrategy,
                    out placement))
            {
                return(placement);
            }

            return(PlacementStrategy.GetDefault());
        }
Esempio n. 2
0
        public ActivationData(ActivationAddress addr, string genericArguments, PlacementStrategy placedUsing, IActivationCollector collector, TimeSpan ageLimit)
        {
            if (null == addr)
            {
                throw new ArgumentNullException("addr");
            }
            if (null == placedUsing)
            {
                throw new ArgumentNullException("placedUsing");
            }
            if (null == collector)
            {
                throw new ArgumentNullException("collector");
            }

            logger = TraceLogger.GetLogger("ActivationData", TraceLogger.LoggerType.Runtime);
            ResetKeepAliveRequest();
            Address     = addr;
            State       = ActivationState.Create;
            PlacedUsing = placedUsing;

            if (!Grain.IsSystemTarget && !Constants.IsSystemGrain(Grain))
            {
                this.collector = collector;
            }
            CollectionAgeLimit = ageLimit;

            GrainReference = GrainReference.FromGrainId(addr.Grain, genericArguments,
                                                        Grain.IsSystemTarget ? addr.Silo : null);
        }
Esempio n. 3
0
        public GrainTypeManager(
            ILocalSiloDetails siloDetails,
            ApplicationPartManager applicationPartManager,
            DefaultPlacementStrategy defaultPlacementStrategy,
            SerializationManager serializationManager,
            MultiClusterRegistrationStrategyManager multiClusterRegistrationStrategyManager,
            LoggerWrapper <GrainTypeManager> logger,
            IOptions <GrainClassOptions> grainClassOptions)
        {
            var localTestMode = siloDetails.SiloAddress.Endpoint.Address.Equals(IPAddress.Loopback);

            this.logger = logger;
            this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
            this.serializationManager     = serializationManager;
            this.multiClusterRegistrationStrategyManager = multiClusterRegistrationStrategyManager;
            grainInterfaceMap        = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
            ClusterGrainInterfaceMap = grainInterfaceMap;
            grainInterfaceMapsBySilo = new Dictionary <SiloAddress, GrainInterfaceMap>();

            var grainClassFeature = applicationPartManager.CreateAndPopulateFeature <GrainClassFeature>();

            this.grainTypes = CreateGrainTypeMap(grainClassFeature, grainClassOptions.Value);

            var grainInterfaceFeature = applicationPartManager.CreateAndPopulateFeature <GrainInterfaceFeature>();

            this.invokers = CreateInvokerMap(grainInterfaceFeature);
            this.InitializeInterfaceMap();
        }
Esempio n. 4
0
        public static PlacementResult SpecifyCreation(
            SiloAddress silo,
            ActivationId activationId,
            PlacementStrategy placement,
            string grainType)
        {
            if (silo == null)
            {
                throw new ArgumentNullException(nameof(silo));
            }
            if (activationId == null)
            {
                throw new ArgumentNullException(nameof(activationId));
            }
            if (placement == null)
            {
                throw new ArgumentNullException(nameof(placement));
            }
            if (string.IsNullOrWhiteSpace(grainType))
            {
                throw new ArgumentException("'grainType' must contain a valid type name.", nameof(grainType));
            }

            return(new PlacementResult
            {
                Activation = activationId,
                Silo = silo,
                PlacementStrategy = placement,
                GrainType = grainType
            });
        }
Esempio n. 5
0
        public GrainTypeManager(
            ILocalSiloDetails siloDetails,
            IApplicationPartManager applicationPartManager,
            PlacementStrategy defaultPlacementStrategy,
            SerializationManager serializationManager,
            ILogger <GrainTypeManager> logger,
            IOptions <GrainClassOptions> grainClassOptions)
        {
            this.logger = logger;
            this.defaultPlacementStrategy = defaultPlacementStrategy;
            this.serializationManager     = serializationManager;
            grainInterfaceMap             = new GrainInterfaceMap(this.defaultPlacementStrategy);
            ClusterGrainInterfaceMap      = grainInterfaceMap;
            GrainTypeResolver             = grainInterfaceMap.GetGrainTypeResolver();
            grainInterfaceMapsBySilo      = new Dictionary <SiloAddress, GrainInterfaceMap>();

            var grainClassFeature = applicationPartManager.CreateAndPopulateFeature <GrainClassFeature>();

            this.grainTypes = CreateGrainTypeMap(grainClassFeature, grainClassOptions.Value);

            var grainInterfaceFeature = applicationPartManager.CreateAndPopulateFeature <GrainInterfaceFeature>();

            this.invokers = CreateInvokerMap(grainInterfaceFeature);
            this.InitializeInterfaceMap();
        }
Esempio n. 6
0
        public override string ToString()
        {
            var placementStr = IsNewPlacement ? PlacementStrategy.ToString() : "*not-new*";

            return(String.Format("PlacementResult({0}, {1}, {2}, {3})",
                                 Silo, Activation, placementStr, GrainType));
        }
Esempio n. 7
0
        SpecifyCreation(
            SiloAddress silo,
            PlacementStrategy placement,
            string grainType)
        {
            if (silo == null)
            {
                throw new ArgumentNullException("silo");
            }
            if (placement == null)
            {
                throw new ArgumentNullException("placement");
            }
            if (string.IsNullOrWhiteSpace(grainType))
            {
                throw new ArgumentException("'grainType' must contain a valid typename.");
            }

            return
                (new PlacementResult
            {
                Activation = ActivationId.NewId(),
                Silo = silo,
                PlacementStrategy = placement,
                GrainType = grainType
            });
        }
Esempio n. 8
0
        public static PlacementResult SpecifyCreation(
            SiloAddress silo,
            ActivationId activationId,
            PlacementStrategy placement)
        {
            if (silo == null)
            {
                throw new ArgumentNullException(nameof(silo));
            }
            if (activationId == null)
            {
                throw new ArgumentNullException(nameof(activationId));
            }
            if (placement == null)
            {
                throw new ArgumentNullException(nameof(placement));
            }

            return(new PlacementResult
            {
                Activation = activationId,
                Silo = silo,
                PlacementStrategy = placement
            });
        }
Esempio n. 9
0
 internal void GetTypeInfo(int typeCode, out string grainClass, out PlacementStrategy placement, out MultiClusterRegistrationStrategy activationStrategy, string genericArguments = null)
 {
     if (!ClusterGrainInterfaceMap.TryGetTypeInfo(typeCode, out grainClass, out placement, out activationStrategy, genericArguments))
     {
         throw new OrleansException(String.Format("Unexpected: Cannot find an implementation class for grain interface {0}", typeCode));
     }
 }
Esempio n. 10
0
 internal GrainClassData(int grainTypeCode, string grainClass, GrainInterfaceData interfaceData, PlacementStrategy placement)
 {
     GrainTypeCode      = grainTypeCode;
     GrainClass         = grainClass;
     this.interfaceData = interfaceData;
     genericClassNames  = new Dictionary <string, string>(); // TODO: initialize only for generic classes
     placementStrategy  = placement ?? PlacementStrategy.GetDefault();
 }
Esempio n. 11
0
        internal static void InitDefaultGrainStrategies()
        {
            RandomPlacement = Orleans.Runtime.RandomPlacement.Singleton;

            PreferLocalPlacement = Orleans.Runtime.PreferLocalPlacement.Singleton;

            ActivationCountBasedPlacement = Orleans.Runtime.ActivationCountBasedPlacement.Singleton;
        }
Esempio n. 12
0
 internal GrainClassData(int grainTypeCode, string grainClass, bool isGeneric, GrainInterfaceMap.GrainInterfaceData interfaceData, PlacementStrategy placement, MultiClusterRegistrationStrategy registrationStrategy)
 {
     GrainTypeCode             = grainTypeCode;
     GrainClass                = grainClass;
     this.isGeneric            = isGeneric;
     this.interfaceData        = interfaceData;
     genericClassNames         = new Dictionary <string, string>(); // TODO: initialize only for generic classes
     placementStrategy         = placement;
     this.registrationStrategy = registrationStrategy;
 }
Esempio n. 13
0
 public GrainTypeManager(bool localTestMode, SiloAssemblyLoader loader, DefaultPlacementStrategy defaultPlacementStrategy, SerializationManager serializationManager, MultiClusterRegistrationStrategyManager multiClusterRegistrationStrategyManager)
 {
     this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
     this.loader = loader;
     this.serializationManager = serializationManager;
     this.multiClusterRegistrationStrategyManager = multiClusterRegistrationStrategyManager;
     grainInterfaceMap        = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
     ClusterGrainInterfaceMap = grainInterfaceMap;
     grainInterfaceMapsBySilo = new Dictionary <SiloAddress, GrainInterfaceMap>();
 }
Esempio n. 14
0
        internal void AddEntry(int interfaceId, Type iface, int grainTypeCode, string grainInterface, string grainClass, string assembly,
                               PlacementStrategy placement, bool primaryImplementation = false)
        {
            lock (this)
            {
                GrainInterfaceData grainInterfaceData;

                if (table.ContainsKey(interfaceId))
                {
                    grainInterfaceData = table[interfaceId];
                }
                else
                {
                    grainInterfaceData = new GrainInterfaceData(interfaceId, iface, grainInterface);

                    table[interfaceId] = grainInterfaceData;

                    if (iface.IsGenericType)
                    {
                        iface = iface.GetGenericTypeDefinition();
                    }

                    var key = iface.AssemblyQualifiedName;
                    typeToInterfaceData[key] = grainInterfaceData;
                }

                var implementation = new GrainClassData(grainTypeCode, grainClass, grainInterfaceData, placement);
                if (!implementationIndex.ContainsKey(grainTypeCode))
                {
                    implementationIndex.Add(grainTypeCode, implementation);
                }

                grainInterfaceData.AddImplementation(implementation, primaryImplementation);
                if (primaryImplementation)
                {
                    primaryImplementations[grainInterface] = grainClass;
                }
                else
                {
                    if (!primaryImplementations.ContainsKey(grainInterface))
                    {
                        primaryImplementations.Add(grainInterface, grainClass);
                    }
                }

                if (localTestMode)
                {
                    if (!loadedGrainAsemblies.Contains(assembly))
                    {
                        loadedGrainAsemblies.Add(assembly);
                    }
                }
            }
        }
Esempio n. 15
0
 public GrainInterfaceMap(PlacementStrategy defaultPlacementStrategy)
 {
     table = new Dictionary <int, GrainInterfaceData>();
     typeToInterfaceData      = new Dictionary <string, GrainInterfaceData>();
     primaryImplementations   = new Dictionary <string, string>();
     implementationIndex      = new Dictionary <int, GrainClassData>();
     placementStrategiesIndex = new Dictionary <int, PlacementStrategy>();
     directoriesIndex         = new Dictionary <int, string>();
     unordered = new HashSet <int>();
     this.defaultPlacementStrategy = defaultPlacementStrategy;
 }
Esempio n. 16
0
        public GrainTypeManager(ILocalSiloDetails siloDetails, SiloAssemblyLoader loader, DefaultPlacementStrategy defaultPlacementStrategy, SerializationManager serializationManager, MultiClusterRegistrationStrategyManager multiClusterRegistrationStrategyManager)
        {
            var localTestMode = siloDetails.SiloAddress.Endpoint.Address.Equals(IPAddress.Loopback);

            this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
            this.loader = loader;
            this.serializationManager = serializationManager;
            this.multiClusterRegistrationStrategyManager = multiClusterRegistrationStrategyManager;
            grainInterfaceMap        = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
            ClusterGrainInterfaceMap = grainInterfaceMap;
            grainInterfaceMapsBySilo = new Dictionary <SiloAddress, GrainInterfaceMap>();
        }
Esempio n. 17
0
        public ActivationData(
            ActivationAddress addr,
            PlacementStrategy placedUsing,
            IActivationCollector collector,
            TimeSpan ageLimit,
            IOptions <SiloMessagingOptions> messagingOptions,
            TimeSpan maxWarningRequestProcessingTime,
            TimeSpan maxRequestProcessingTime,
            ILoggerFactory loggerFactory,
            IServiceProvider applicationServices,
            IGrainRuntime grainRuntime,
            GrainReferenceActivator referenceActivator,
            GrainTypeComponents sharedComponents,
            ActivationMessageScheduler messageScheduler)
        {
            if (null == addr)
            {
                throw new ArgumentNullException(nameof(addr));
            }
            if (null == placedUsing)
            {
                throw new ArgumentNullException(nameof(placedUsing));
            }
            if (null == collector)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            _receiveMessageInScheduler = state => this.ReceiveMessageInScheduler(state);
            _shared                              = sharedComponents;
            _messageScheduler                    = messageScheduler;
            logger                               = loggerFactory.CreateLogger <ActivationData>();
            this.lifecycle                       = new GrainLifecycle(loggerFactory.CreateLogger <LifecycleSubject>());
            this.maxRequestProcessingTime        = maxRequestProcessingTime;
            this.maxWarningRequestProcessingTime = maxWarningRequestProcessingTime;
            this.messagingOptions                = messagingOptions.Value;
            ResetKeepAliveRequest();
            Address     = addr;
            State       = ActivationState.Create;
            PlacedUsing = placedUsing;
            if (!this.GrainId.IsSystemTarget())
            {
                this.collector = collector;
            }

            CollectionAgeLimit = ageLimit;

            this.GrainReference = referenceActivator.CreateReference(addr.Grain, default);
            this.serviceScope   = applicationServices.CreateScope();
            this.Runtime        = grainRuntime;
        }
Esempio n. 18
0
#pragma warning disable 612,618
        internal static PlacementStrategy GetPlacementStrategy(Type grainClass, PlacementStrategy defaultPlacement)
        {
            PlacementStrategy placement;

            if (GetPlacementStrategy <PlacementAttribute>(
                    grainClass,
                    a => a.PlacementStrategy,
                    out placement))
            {
                return(placement);
            }

            return(defaultPlacement);
        }
Esempio n. 19
0
 public GrainInterfaceMap(bool localTestMode, PlacementStrategy defaultPlacementStrategy)
 {
     table = new Dictionary <int, GrainInterfaceData>();
     typeToInterfaceData    = new Dictionary <string, GrainInterfaceData>();
     primaryImplementations = new Dictionary <string, string>();
     implementationIndex    = new Dictionary <int, GrainClassData>();
     unordered                     = new HashSet <int>();
     this.localTestMode            = localTestMode;
     this.defaultPlacementStrategy = defaultPlacementStrategy;
     if (localTestMode) // if we are running in test mode, we'll build a list of loaded grain assemblies to help with troubleshooting deployment issue
     {
         loadedGrainAsemblies = new HashSet <string>();
     }
 }
Esempio n. 20
0
 public GrainTypeManager(bool localTestMode, SiloAssemblyLoader loader, DefaultPlacementStrategy defaultPlacementStrategy)
 {
     this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
     this.loader       = loader;
     grainInterfaceMap = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
     lock (lockable)
     {
         if (Instance != null)
         {
             throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager.");
         }
         Instance = this;
     }
 }
Esempio n. 21
0
        internal void AddEntry(int interfaceId, Type iface, int grainTypeCode, string grainInterface, string grainClass, string assembly,
                               bool isGenericGrainClass, PlacementStrategy placement, MultiClusterRegistrationStrategy registrationStrategy, bool primaryImplementation = false)
        {
            lock (this)
            {
                GrainInterfaceData grainInterfaceData;

                if (table.ContainsKey(interfaceId))
                {
                    grainInterfaceData = table[interfaceId];
                }
                else
                {
                    grainInterfaceData = new GrainInterfaceData(interfaceId, iface, grainInterface);

                    table[interfaceId] = grainInterfaceData;
                    var interfaceTypeKey = GetTypeKey(iface, isGenericGrainClass);
                    typeToInterfaceData[interfaceTypeKey] = grainInterfaceData;
                }

                var implementation = new GrainClassData(grainTypeCode, grainClass, isGenericGrainClass, grainInterfaceData, placement, registrationStrategy);
                if (!implementationIndex.ContainsKey(grainTypeCode))
                {
                    implementationIndex.Add(grainTypeCode, implementation);
                }

                grainInterfaceData.AddImplementation(implementation, primaryImplementation);
                if (primaryImplementation)
                {
                    primaryImplementations[grainInterface] = grainClass;
                }
                else
                {
                    if (!primaryImplementations.ContainsKey(grainInterface))
                    {
                        primaryImplementations.Add(grainInterface, grainClass);
                    }
                }

                if (localTestMode)
                {
                    if (!loadedGrainAsemblies.Contains(assembly))
                    {
                        loadedGrainAsemblies.Add(assembly);
                    }
                }
            }
        }
Esempio n. 22
0
        internal void AddEntry(Type iface, Type grain, PlacementStrategy placement, MultiClusterRegistrationStrategy registrationStrategy, bool primaryImplementation)
        {
            lock (this)
            {
                var grainTypeInfo       = grain.GetTypeInfo();
                var grainName           = TypeUtils.GetFullName(grainTypeInfo);
                var isGenericGrainClass = grainTypeInfo.ContainsGenericParameters;
                var grainTypeCode       = GrainInterfaceUtils.GetGrainClassTypeCode(grain);

                var grainInterfaceData = GetOrAddGrainInterfaceData(iface, isGenericGrainClass);

                var implementation = new GrainClassData(grainTypeCode, grainName, isGenericGrainClass);
                if (!implementationIndex.ContainsKey(grainTypeCode))
                {
                    implementationIndex.Add(grainTypeCode, implementation);
                }
                if (!placementStrategiesIndex.ContainsKey(grainTypeCode))
                {
                    placementStrategiesIndex.Add(grainTypeCode, placement);
                }
                if (!registrationStrategiesIndex.ContainsKey(grainTypeCode))
                {
                    registrationStrategiesIndex.Add(grainTypeCode, registrationStrategy);
                }

                grainInterfaceData.AddImplementation(implementation, primaryImplementation);
                if (primaryImplementation)
                {
                    primaryImplementations[grainInterfaceData.GrainInterface] = grainName;
                }
                else
                {
                    if (!primaryImplementations.ContainsKey(grainInterfaceData.GrainInterface))
                    {
                        primaryImplementations.Add(grainInterfaceData.GrainInterface, grainName);
                    }
                }

                if (localTestMode)
                {
                    var assembly = grainTypeInfo.Assembly.CodeBase;
                    if (!loadedGrainAsemblies.Contains(assembly))
                    {
                        loadedGrainAsemblies.Add(assembly);
                    }
                }
            }
        }
Esempio n. 23
0
        internal bool TryGetTypeInfo(int typeCode, out string grainClass, out PlacementStrategy placement, string genericArguments = null)
        {
            lock (this)
            {
                grainClass = null;
                placement  = this.defaultPlacementStrategy;
                if (!implementationIndex.TryGetValue(typeCode, out var implementation))
                {
                    return(false);
                }

                grainClass = implementation.GetClassName(genericArguments);
                placement  = placementStrategiesIndex[typeCode];
                return(true);
            }
        }
Esempio n. 24
0
        public ActivationData(
            ActivationAddress addr,
            string genericArguments,
            PlacementStrategy placedUsing,
            IMultiClusterRegistrationStrategy registrationStrategy,
            IActivationCollector collector,
            TimeSpan ageLimit,
            IOptions <SiloMessagingOptions> messagingOptions,
            TimeSpan maxWarningRequestProcessingTime,
            TimeSpan maxRequestProcessingTime,
            IRuntimeClient runtimeClient,
            ILoggerFactory loggerFactory)
        {
            if (null == addr)
            {
                throw new ArgumentNullException(nameof(addr));
            }
            if (null == placedUsing)
            {
                throw new ArgumentNullException(nameof(placedUsing));
            }
            if (null == collector)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            logger         = loggerFactory.CreateLogger <ActivationData>();
            this.lifecycle = new GrainLifecycle(loggerFactory.CreateLogger <LifecycleSubject>());
            this.maxRequestProcessingTime        = maxRequestProcessingTime;
            this.maxWarningRequestProcessingTime = maxWarningRequestProcessingTime;
            this.messagingOptions = messagingOptions.Value;
            ResetKeepAliveRequest();
            Address              = addr;
            State                = ActivationState.Create;
            PlacedUsing          = placedUsing;
            RegistrationStrategy = registrationStrategy;
            if (!Grain.IsSystemTarget)
            {
                this.collector = collector;
            }

            CollectionAgeLimit = ageLimit;

            GrainReference         = GrainReference.FromGrainId(addr.Grain, runtimeClient.GrainReferenceRuntime, genericArguments, Grain.IsSystemTarget ? addr.Silo : null);
            this.SchedulingContext = new SchedulingContext(this);
        }
Esempio n. 25
0
 public GrainTypeManager(bool localTestMode, SiloAssemblyLoader loader, DefaultPlacementStrategy defaultPlacementStrategy, SerializationManager serializationManager)
 {
     this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
     this.loader = loader;
     this.serializationManager = serializationManager;
     grainInterfaceMap         = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
     ClusterGrainInterfaceMap  = grainInterfaceMap;
     grainInterfaceMapsBySilo  = new Dictionary <SiloAddress, GrainInterfaceMap>();
     lock (lockable)
     {
         if (Instance != null)
         {
             throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager.");
         }
         Instance = this;
     }
 }
Esempio n. 26
0
        internal bool TryGetTypeInfo(int typeCode, out string grainClass, out PlacementStrategy placement, string genericArguments = null)
        {
            lock (this)
            {
                grainClass = null;
                placement  = null;

                if (!implementationIndex.ContainsKey(typeCode))
                {
                    return(false);
                }

                var implementation = implementationIndex[typeCode];
                grainClass = implementation.GetClassName(genericArguments);
                placement  = implementation.PlacementStrategy;
                return(true);
            }
        }
Esempio n. 27
0
        public GrainTypeManager(SiloInitializationParameters silo, SiloAssemblyLoader loader, DefaultPlacementStrategy defaultPlacementStrategy)
        {
            var localTestMode = silo.SiloAddress.Endpoint.Address.Equals(IPAddress.Loopback);

            this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
            this.loader              = loader;
            grainInterfaceMap        = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
            ClusterGrainInterfaceMap = grainInterfaceMap;
            grainInterfaceMapsBySilo = new Dictionary <SiloAddress, GrainInterfaceMap>();
            lock (lockable)
            {
                if (Instance != null)
                {
                    throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager.");
                }
                Instance = this;
            }
        }
Esempio n. 28
0
        public ActivationData(
            ActivationAddress addr,
            string genericArguments,
            PlacementStrategy placedUsing,
            IMultiClusterRegistrationStrategy registrationStrategy,
            IActivationCollector collector,
            TimeSpan ageLimit,
            NodeConfiguration nodeConfiguration,
            TimeSpan maxWarningRequestProcessingTime,
            TimeSpan maxRequestProcessingTime,
            IRuntimeClient runtimeClient)
        {
            if (null == addr)
            {
                throw new ArgumentNullException(nameof(addr));
            }
            if (null == placedUsing)
            {
                throw new ArgumentNullException(nameof(placedUsing));
            }
            if (null == collector)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            logger         = LogManager.GetLogger("ActivationData", LoggerType.Runtime);
            this.lifecycle = new GrainLifecycle(logger);
            this.maxRequestProcessingTime        = maxRequestProcessingTime;
            this.maxWarningRequestProcessingTime = maxWarningRequestProcessingTime;
            this.nodeConfiguration = nodeConfiguration;
            ResetKeepAliveRequest();
            Address              = addr;
            State                = ActivationState.Create;
            PlacedUsing          = placedUsing;
            RegistrationStrategy = registrationStrategy;
            if (!Grain.IsSystemTarget && !Constants.IsSystemGrain(Grain))
            {
                this.collector = collector;
            }
            CollectionAgeLimit = ageLimit;

            GrainReference         = GrainReference.FromGrainId(addr.Grain, runtimeClient.GrainReferenceRuntime, genericArguments, Grain.IsSystemTarget ? addr.Silo : null);
            this.SchedulingContext = new SchedulingContext(this);
        }
Esempio n. 29
0
        public ActivationData(
            ActivationAddress addr,
            string genericArguments,
            PlacementStrategy placedUsing,
            MultiClusterRegistrationStrategy registrationStrategy,
            IActivationCollector collector,
            TimeSpan ageLimit,
            NodeConfiguration nodeConfiguration,
            TimeSpan maxRequestProcessingTime)
        {
            if (null == addr)
            {
                throw new ArgumentNullException("addr");
            }
            if (null == placedUsing)
            {
                throw new ArgumentNullException("placedUsing");
            }
            if (null == collector)
            {
                throw new ArgumentNullException("collector");
            }

            logger = LogManager.GetLogger("ActivationData", LoggerType.Runtime);
            this.maxRequestProcessingTime = maxRequestProcessingTime;
            this.nodeConfiguration        = nodeConfiguration;
            ResetKeepAliveRequest();
            Address              = addr;
            State                = ActivationState.Create;
            PlacedUsing          = placedUsing;
            RegistrationStrategy = registrationStrategy;
            if (!Grain.IsSystemTarget && !Constants.IsSystemGrain(Grain))
            {
                this.collector = collector;
            }
            CollectionAgeLimit = ageLimit;


            GrainReference = GrainReference.FromGrainId(addr.Grain, genericArguments, Grain.IsSystemTarget ? addr.Silo : null);
        }
Esempio n. 30
0
#pragma warning disable 612,618
        internal static PlacementStrategy GetPlacementStrategy(Type grainClass)
        {
            PlacementStrategy placement;

            if (GetPlacementStrategy <StatelessWorkerAttribute>(
                    grainClass,
                    _ => GrainStrategy.StatelessWorkerPlacement,
                    out placement))
            {
                return(placement);
            }

            if (GetPlacementStrategy <PlacementAttribute>(
                    grainClass,
                    a => a.PlacementStrategy,
                    out placement))
            {
                return(placement);
            }

            return(PlacementStrategy.GetDefault());
        }