예제 #1
0
        /// <summary>
        /// Gets a reference to a grain.
        /// </summary>
        /// <typeparam name="TGrainInterface">The interface to get.</typeparam>
        /// <param name="primaryKey">The primary key of the grain.</param>
        /// <param name="grainClassNamePrefix">An optional class name prefix used to find the runtime type of the grain.</param>
        /// <returns>A reference to the specified grain.</returns>
        public TGrainInterface GetGrain <TGrainInterface>(long primaryKey, string grainClassNamePrefix = null) where TGrainInterface : IGrainWithIntegerKey
        {
            Type interfaceType  = typeof(TGrainInterface);
            var  implementation = this.GetGrainClassData(interfaceType, grainClassNamePrefix);
            var  grainId        = TypeCodeMapper.ComposeGrainId(implementation, primaryKey, interfaceType);

            return(this.Cast <TGrainInterface>(this.MakeGrainReferenceFromType(interfaceType, grainId)));
        }
예제 #2
0
 /// <summary>
 /// Gets a reference to a grain.
 /// </summary>
 /// <typeparam name="TGrainInterface">The interface to get.</typeparam>
 /// <param name="primaryKey">The primary key of the grain.</param>
 /// <param name="grainClassNamePrefix">An optional class name prefix used to find the runtime type of the grain.</param>
 /// <returns></returns>
 public TGrainInterface GetGrain <TGrainInterface>(long primaryKey, string grainClassNamePrefix = null) where TGrainInterface : IGrainWithIntegerKey
 {
     return(Cast <TGrainInterface>(
                GrainFactoryBase.MakeGrainReference_FromType(
                    baseTypeCode => TypeCodeMapper.ComposeGrainId(baseTypeCode, primaryKey, typeof(TGrainInterface)),
                    typeof(TGrainInterface),
                    grainClassNamePrefix)));
 }
예제 #3
0
        /// <summary>
        /// Gets a reference to a grain.
        /// </summary>
        /// <typeparam name="TGrainInterface">The interface to get.</typeparam>
        /// <param name="primaryKey">The primary key of the grain.</param>
        /// <param name="keyExtension">The key extention of the grain.</param>
        /// <param name="grainClassNamePrefix">An optional class name prefix used to find the runtime type of the grain.</param>
        /// <returns></returns>
        public TGrainInterface GetGrain <TGrainInterface>(long primaryKey, string keyExtension, string grainClassNamePrefix = null)
            where TGrainInterface : IGrainWithIntegerCompoundKey
        {
            GrainFactoryBase.DisallowNullOrWhiteSpaceKeyExtensions(keyExtension);

            return(Cast <TGrainInterface>(
                       GrainFactoryBase.MakeGrainReference_FromType(
                           baseTypeCode => TypeCodeMapper.ComposeGrainId(baseTypeCode, primaryKey, typeof(TGrainInterface), keyExtension),
                           typeof(TGrainInterface),
                           grainClassNamePrefix)));
        }
예제 #4
0
 /// <summary>
 /// Fabricate a grain reference for a grain with the specified Guid primary key
 /// </summary>
 /// <param name="grainInterfaceType">Grain type</param>
 /// <param name="primaryKey">Primary key for the grain</param>
 /// <param name="grainClassNamePrefix">Prefix or full name of the grain class to disambiguate multiple implementations.</param>
 /// <returns><c>GrainReference</c> for connecting to the self-managed grain with the specified primary key</returns>
 /// <exception cref="System.ArgumentException">If called for a grain type that is not a valid grain type.</exception>
 public static IAddressable MakeGrainReferenceInternal(
     Type grainInterfaceType,
     string primaryKey,
     string grainClassNamePrefix = null)
 {
     return
         (MakeGrainReference_FromType(
              implementation => TypeCodeMapper.ComposeGrainId(implementation, primaryKey, grainInterfaceType),
              grainInterfaceType,
              grainClassNamePrefix));
 }
예제 #5
0
        private GrainClassData GetGrainClassData(Type interfaceType, string grainClassNamePrefix)
        {
            if (!GrainInterfaceUtils.IsGrainType(interfaceType))
            {
                throw new ArgumentException("Cannot fabricate grain-reference for non-grain type: " + interfaceType.FullName);
            }

            var implementation = TypeCodeMapper.GetImplementation(this.runtimeClient.GrainTypeResolver, interfaceType, grainClassNamePrefix);

            return(implementation);
        }
예제 #6
0
        /// <summary>
        /// Gets a reference to a grain.
        /// </summary>
        /// <typeparam name="TGrainInterface">The interface to get.</typeparam>
        /// <param name="primaryKey">The primary key of the grain.</param>
        /// <param name="keyExtension">The key extention of the grain.</param>
        /// <param name="grainClassNamePrefix">An optional class name prefix used to find the runtime type of the grain.</param>
        /// <returns>A reference to the specified grain.</returns>
        public TGrainInterface GetGrain <TGrainInterface>(long primaryKey, string keyExtension, string grainClassNamePrefix = null)
            where TGrainInterface : IGrainWithIntegerCompoundKey
        {
            GrainFactoryBase.DisallowNullOrWhiteSpaceKeyExtensions(keyExtension);

            Type interfaceType  = typeof(TGrainInterface);
            var  implementation = this.GetGrainClassData(interfaceType, grainClassNamePrefix);
            var  grainId        = TypeCodeMapper.ComposeGrainId(implementation, primaryKey, interfaceType, keyExtension);

            return(this.Cast <TGrainInterface>(this.MakeGrainReferenceFromType(interfaceType, grainId)));
        }
예제 #7
0
 /// <summary>
 /// Fabricate a grain reference for a grain with the specified Guid primary key
 /// </summary>
 /// <param name="grainInterfaceType">Grain type</param>
 /// <param name="interfaceId">Type code value for this self-managed grain type</param>
 /// <param name="primaryKey">Primary key for the grain</param>
 /// <param name="grainClassNamePrefix">Prefix or full name of the grain class to disambiguate multiple implementations.</param>
 /// <returns><c>GrainReference</c> for connecting to the self-managed grain with the specified primary key</returns>
 /// <exception cref="System.ArgumentException">If called for a grain type that is not a valid grain type.</exception>
 public static IAddressable MakeGrainReferenceInternal(
     Type grainInterfaceType,
     int interfaceId,
     string primaryKey,
     string grainClassNamePrefix = null)
 {
     return
         (MakeGrainReference(
              baseTypeCode => TypeCodeMapper.ComposeGrainId(baseTypeCode, primaryKey, grainInterfaceType),
              grainInterfaceType,
              interfaceId,
              grainClassNamePrefix));
 }
예제 #8
0
        /// <summary>
        /// Fabricate a grain reference for an extended-key grain with the specified Int64 primary key
        /// </summary>
        /// <param name="grainInterfaceType">Grain type</param>
        /// <param name="primaryKey">Primary key for the grain</param>
        /// <param name="keyExt">Extended key for the grain</param>
        /// <param name="grainClassNamePrefix">Prefix or full name of the grain class to disambiguate multiple implementations.</param>
        /// <returns><c>GrainReference</c> for connecting to the grain with the specified primary key</returns>
        /// <exception cref="System.ArgumentException">If called for a grain type that is not a valid grain type.</exception>
        public static IAddressable MakeKeyExtendedGrainReferenceInternal(
            Type grainInterfaceType,
            long primaryKey,
            string keyExt,
            string grainClassNamePrefix = null)
        {
            DisallowNullOrWhiteSpaceKeyExtensions(keyExt);

            return
                (MakeGrainReference_FromType(
                     implementation => TypeCodeMapper.ComposeGrainId(implementation, primaryKey, grainInterfaceType, keyExt),
                     grainInterfaceType,
                     grainClassNamePrefix));
        }
예제 #9
0
        internal static IAddressable MakeGrainReference_FromType(
            Func <GrainClassData, GrainId> getGrainId,
            Type interfaceType,
            string grainClassNamePrefix = null)
        {
            CheckRuntimeEnvironmentSetup();
            if (!GrainInterfaceData.IsGrainType(interfaceType))
            {
                throw new ArgumentException("Cannot fabricate grain-reference for non-grain type: " + interfaceType.FullName);
            }
            var     implementation = TypeCodeMapper.GetImplementation(interfaceType, grainClassNamePrefix);
            GrainId grainId        = getGrainId(implementation);

            return(GrainReference.FromGrainId(grainId, interfaceType.IsGenericType ? interfaceType.UnderlyingSystemType.FullName : null));
        }
예제 #10
0
        /// <summary>
        /// Fabricate a grain reference for an extended-key grain with the specified Guid primary key
        /// </summary>
        /// <param name="grainInterfaceType">Grain type</param>
        /// <param name="interfaceId">Type code value for this grain type</param>
        /// <param name="primaryKey">Primary key for the grain</param>
        /// <param name="keyExt">Extended key for the grain</param>
        /// <param name="grainClassNamePrefix">Prefix or full name of the grain class to disambiguate multiple implementations.</param>
        /// <returns><c>GrainReference</c> for connecting to the grain with the specified primary key</returns>
        /// <exception cref="System.ArgumentException">If called for a grain type that is not a valid grain type.</exception>
        public static IAddressable MakeKeyExtendedGrainReferenceInternal(
            Type grainInterfaceType,
            int interfaceId,
            Guid primaryKey,
            string keyExt,
            string grainClassNamePrefix = null)
        {
            DisallowNullOrWhiteSpaceKeyExtensions(keyExt);

            return
                (MakeGrainReference(
                     baseTypeCode => TypeCodeMapper.ComposeGrainId(baseTypeCode, primaryKey, grainInterfaceType, keyExt),
                     grainInterfaceType,
                     interfaceId,
                     grainClassNamePrefix));
        }
예제 #11
0
        private static GrainId ConstructGrainId(string[] args, string operation)
        {
            if (args == null || args.Length < 2)
            {
                PrintUsage();
                return(null);
            }
            string interfaceTypeCodeOrImplClassName = args[0];
            int    interfaceTypeCodeDataLong;
            long   implementationTypeCode;

            if (Int32.TryParse(interfaceTypeCodeOrImplClassName, out interfaceTypeCodeDataLong))
            {
                // parsed it as int, so it is an interface type code.
                implementationTypeCode = TypeCodeMapper.GetImplementation(interfaceTypeCodeDataLong).GrainTypeCode;
            }
            else
            {
                // interfaceTypeCodeOrImplClassName is the implementation class name
                implementationTypeCode = TypeCodeMapper.GetImplementation(interfaceTypeCodeOrImplClassName).GrainTypeCode;
            }

            var     grainIdStr = args[1];
            GrainId grainId    = null;
            long    grainIdLong;
            Guid    grainIdGuid;

            if (Int64.TryParse(grainIdStr, out grainIdLong))
            {
                grainId = GrainId.GetGrainId(implementationTypeCode, grainIdLong);
            }
            else if (Guid.TryParse(grainIdStr, out grainIdGuid))
            {
                grainId = GrainId.GetGrainId(implementationTypeCode, grainIdGuid);
            }

            WriteStatus(string.Format("**Full Grain Id to {0} is: GrainId = {1}", operation, grainId.ToFullString()));
            return(grainId);
        }