/// <summary> /// Casts a grain to a specific grain interface. /// </summary> /// <typeparam name="TGrainInterface">The type of the grain interface.</typeparam> /// <param name="grain">The grain to cast.</param> public static TGrainInterface Cast <TGrainInterface>(this Runtime.IAddressable grain) { return(GrainFactory.Cast <TGrainInterface>(grain)); }
public OutsideRuntimeClient(ClientConfiguration cfg, GrainFactory grainFactory, bool secondary = false) { this.grainFactory = grainFactory; this.clientId = GrainId.NewClientId(); if (cfg == null) { Console.WriteLine("An attempt to create an OutsideRuntimeClient with null ClientConfiguration object."); throw new ArgumentException("OutsideRuntimeClient was attempted to be created with null ClientConfiguration object.", "cfg"); } this.config = cfg; if (!TraceLogger.IsInitialized) { TraceLogger.Initialize(config); } StatisticsCollector.Initialize(config); SerializationManager.Initialize(config.UseStandardSerializer); logger = TraceLogger.GetLogger("OutsideRuntimeClient", TraceLogger.LoggerType.Runtime); appLogger = TraceLogger.GetLogger("Application", TraceLogger.LoggerType.Application); try { LoadAdditionalAssemblies(); PlacementStrategy.Initialize(); callbacks = new ConcurrentDictionary <CorrelationId, CallbackData>(); localObjects = new ConcurrentDictionary <GuidId, LocalObjectData>(); if (!secondary) { UnobservedExceptionsHandlerClass.SetUnobservedExceptionHandler(UnhandledException); } // Ensure SerializationManager static constructor is called before AssemblyLoad event is invoked SerializationManager.GetDeserializer(typeof(String)); // Ensure that any assemblies that get loaded in the future get recorded AppDomain.CurrentDomain.AssemblyLoad += NewAssemblyHandler; // Load serialization info for currently-loaded assemblies foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (!assembly.ReflectionOnly) { SerializationManager.FindSerializationInfo(assembly); } } clientProviderRuntime = new ClientProviderRuntime(grainFactory); statisticsProviderManager = new StatisticsProviderManager("Statistics", clientProviderRuntime); var statsProviderName = statisticsProviderManager.LoadProvider(config.ProviderConfigurations) .WaitForResultWithThrow(initTimeout); if (statsProviderName != null) { config.StatisticsProviderName = statsProviderName; } responseTimeout = Debugger.IsAttached ? Constants.DEFAULT_RESPONSE_TIMEOUT : config.ResponseTimeout; BufferPool.InitGlobalBufferPool(config); var localAddress = ClusterConfiguration.GetLocalIPAddress(config.PreferredFamily, config.NetInterface); // Client init / sign-on message logger.Info(ErrorCode.ClientInitializing, string.Format( "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}", BARS, config.DNSHostName, localAddress, clientId)); string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}'", BARS, RuntimeVersion.Current); startMsg = string.Format("{0} Config= " + Environment.NewLine + " {1}", startMsg, config); logger.Info(ErrorCode.ClientStarting, startMsg); if (TestOnlyThrowExceptionDuringInit) { throw new ApplicationException("TestOnlyThrowExceptionDuringInit"); } config.CheckGatewayProviderSettings(); var generation = -SiloAddress.AllocateNewGeneration(); // Client generations are negative var gatewayListProvider = GatewayProviderFactory.CreateGatewayListProvider(config) .WithTimeout(initTimeout).Result; transport = new ProxiedMessageCenter(config, localAddress, generation, clientId, gatewayListProvider); if (StatisticsCollector.CollectThreadTimeTrackingStats) { incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver"); } } catch (Exception exc) { if (logger != null) { logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc); } ConstructorReset(); throw; } }
/// <summary> /// Converts this grain to a specific grain interface. /// </summary> /// <typeparam name="TGrainInterface">The type of the grain interface.</typeparam> /// <param name="grain">The grain to convert.</param> /// <returns>A strongly typed <c>GrainReference</c> of grain interface type TGrainInterface.</returns> public static TGrainInterface AsReference <TGrainInterface>(this Runtime.IAddressable grain) { return(GrainFactory.Cast <TGrainInterface>(grain.AsWeaklyTypedReference())); }