Exemple #1
0
 /// <summary>Constructs a reference to the grain with the specified ID.</summary>
 /// <param name="grainId">The ID of the grain to refer to.</param>
 /// <param name="runtime">The runtime client</param>
 /// <param name="genericArguments">Type arguments in case of a generic grain.</param>
 internal static GrainReference FromGrainId(GrainId grainId, IGrainReferenceRuntime runtime, string genericArguments = null)
 {
     return(new GrainReference(grainId, genericArguments, runtime));
 }
Exemple #2
0
 internal static GrainReference NewObserverGrainReference(ObserverGrainId observerId, IGrainReferenceRuntime runtime)
 {
     return(new GrainReference(observerId.GrainId, null, runtime));
 }
Exemple #3
0
        /// <summary>Constructs a reference to the grain with the specified Id.</summary>
        /// <param name="grainId">The Id of the grain to refer to.</param>
        /// <param name="genericArgument">Type arguments in case of a generic grain.</param>
        /// <param name="systemTargetSilo">Target silo in case of a system target reference.</param>
        /// <param name="observerId">Observer ID in case of an observer reference.</param>
        /// <param name="runtime">The runtime which this grain reference is bound to.</param>
        private GrainReference(GrainId grainId, string genericArgument, SiloAddress systemTargetSilo, GuidId observerId, IGrainReferenceRuntime runtime)
        {
            GrainId = grainId;
            this.genericArguments = genericArgument;
            this.SystemTargetSilo = systemTargetSilo;
            this.observerId       = observerId;
            this.runtime          = runtime;
            if (String.IsNullOrEmpty(genericArgument))
            {
                genericArguments = null; // always keep it null instead of empty.
            }

            // SystemTarget checks
            if (grainId.IsSystemTarget && systemTargetSilo == null)
            {
                throw new ArgumentNullException("systemTargetSilo", String.Format("Trying to create a GrainReference for SystemTarget grain id {0}, but passing null systemTargetSilo.", grainId));
            }
            if (grainId.IsSystemTarget && genericArguments != null)
            {
                throw new ArgumentException(String.Format("Trying to create a GrainReference for SystemTarget grain id {0}, and also passing non-null genericArguments {1}.", grainId, genericArguments), "genericArgument");
            }
            if (grainId.IsSystemTarget && observerId != null)
            {
                throw new ArgumentException(String.Format("Trying to create a GrainReference for SystemTarget grain id {0}, and also passing non-null observerId {1}.", grainId, observerId), "genericArgument");
            }
            if (!grainId.IsSystemTarget && systemTargetSilo != null)
            {
                throw new ArgumentException(String.Format("Trying to create a GrainReference for non-SystemTarget grain id {0}, but passing a non-null systemTargetSilo {1}.", grainId, systemTargetSilo), "systemTargetSilo");
            }

            // ObserverId checks
            if (grainId.IsClient && observerId == null)
            {
                throw new ArgumentNullException("observerId", String.Format("Trying to create a GrainReference for Observer with Client grain id {0}, but passing null observerId.", grainId));
            }
            if (grainId.IsClient && genericArguments != null)
            {
                throw new ArgumentException(String.Format("Trying to create a GrainReference for Client grain id {0}, and also passing non-null genericArguments {1}.", grainId, genericArguments), "genericArgument");
            }
            if (grainId.IsClient && systemTargetSilo != null)
            {
                throw new ArgumentException(String.Format("Trying to create a GrainReference for Client grain id {0}, and also passing non-null systemTargetSilo {1}.", grainId, systemTargetSilo), "genericArgument");
            }
            if (!grainId.IsClient && observerId != null)
            {
                throw new ArgumentException(String.Format("Trying to create a GrainReference with non null Observer {0}, but non Client grain id {1}.", observerId, grainId), "observerId");
            }
        }
        internal void ConsumeServices(IServiceProvider services)
        {
            try
            {
                AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

                this.ServiceProvider = services;

                var connectionLostHandlers = this.ServiceProvider.GetServices <ConnectionToClusterLostHandler>();
                foreach (var handler in connectionLostHandlers)
                {
                    this.ClusterConnectionLost += handler;
                }

                var gatewayCountChangedHandlers = this.ServiceProvider.GetServices <GatewayCountChangedHandler>();
                foreach (var handler in gatewayCountChangedHandlers)
                {
                    this.GatewayCountChanged += handler;
                }

                var clientInvokeCallbacks = this.ServiceProvider.GetServices <ClientInvokeCallback>();
                foreach (var handler in clientInvokeCallbacks)
                {
                    this.ClientInvokeCallback += handler;
                }

                this.InternalGrainFactory = this.ServiceProvider.GetRequiredService <IInternalGrainFactory>();
                this.messageFactory       = this.ServiceProvider.GetService <MessageFactory>();

                var serializationManager = this.ServiceProvider.GetRequiredService <SerializationManager>();
                this.localObjects = new InvokableObjectManager(
                    this,
                    serializationManager,
                    this.messagingTrace,
                    this.loggerFactory.CreateLogger <InvokableObjectManager>());

                var timerLogger = this.loggerFactory.CreateLogger <SafeTimer>();
                var minTicks    = Math.Min(this.clientMessagingOptions.ResponseTimeout.Ticks, TimeSpan.FromSeconds(1).Ticks);
                var period      = TimeSpan.FromTicks(minTicks);
                this.callbackTimer = new SafeTimer(timerLogger, this.OnCallbackExpiryTick, null, period, period);

                this.GrainReferenceRuntime = this.ServiceProvider.GetRequiredService <IGrainReferenceRuntime>();

                BufferPool.InitGlobalBufferPool(this.clientMessagingOptions);

                this.clientProviderRuntime = this.ServiceProvider.GetRequiredService <ClientProviderRuntime>();

                this.localAddress = this.clientMessagingOptions.LocalAddress ?? ConfigUtilities.GetLocalIPAddress(this.clientMessagingOptions.PreferredFamily, this.clientMessagingOptions.NetworkInterfaceName);

                // Client init / sign-on message
                logger.Info(ErrorCode.ClientInitializing, string.Format(
                                "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}",
                                BARS, Dns.GetHostName(), localAddress, clientId));
                string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}' in AppDomain={2}",
                                                BARS, RuntimeVersion.Current, PrintAppDomainDetails());
                logger.Info(ErrorCode.ClientStarting, startMsg);

                if (TestOnlyThrowExceptionDuringInit)
                {
                    throw new InvalidOperationException("TestOnlyThrowExceptionDuringInit");
                }

                this.gatewayListProvider = this.ServiceProvider.GetRequiredService <IGatewayListProvider>();

                var statisticsLevel = statisticsOptions.Value.CollectionLevel;
                if (statisticsLevel.CollectThreadTimeTrackingStats())
                {
                    incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver", this.loggerFactory, this.statisticsOptions, this.schedulerStageStatistics);
                }
            }
            catch (Exception exc)
            {
                if (logger != null)
                {
                    logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc);
                }
                ConstructorReset();
                throw;
            }
        }
Exemple #5
0
 /// <summary>
 /// Binds this instance to a runtime.
 /// </summary>
 /// <param name="runtime">The runtime.</param>
 internal void Bind(IGrainReferenceRuntime runtime)
 {
     this.runtime = runtime;
 }
Exemple #6
0
 internal static GrainReference NewObserverGrainReference(GrainId grainId, GuidId observerId, IGrainReferenceRuntime runtime)
 {
     return(new GrainReference(grainId, null, null, observerId, runtime));
 }
Exemple #7
0
 /// <summary>Constructs a reference to the grain with the specified ID.</summary>
 /// <param name="grainId">The ID of the grain to refer to.</param>
 /// <param name="runtime">The runtime client</param>
 /// <param name="genericArguments">Type arguments in case of a generic grain.</param>
 /// <param name="systemTargetSilo">Target silo in case of a system target reference.</param>
 internal static GrainReference FromGrainId(GrainId grainId, IGrainReferenceRuntime runtime, string genericArguments = null, SiloAddress systemTargetSilo = null)
 {
     return(new GrainReference(grainId, genericArguments, systemTargetSilo, null, runtime));
 }
Exemple #8
0
        internal void ConsumeServices(IServiceProvider services)
        {
            this.ServiceProvider = services;

            var connectionLostHandlers = this.ServiceProvider.GetServices <ConnectionToClusterLostHandler>();

            foreach (var handler in connectionLostHandlers)
            {
                this.ClusterConnectionLost += handler;
            }

            var clientInvokeCallbacks = this.ServiceProvider.GetServices <ClientInvokeCallback>();

            foreach (var handler in clientInvokeCallbacks)
            {
                this.ClientInvokeCallback += handler;
            }

            this.InternalGrainFactory = this.ServiceProvider.GetRequiredService <IInternalGrainFactory>();
            this.ClientStatistics     = this.ServiceProvider.GetRequiredService <ClientStatisticsManager>();
            this.SerializationManager = this.ServiceProvider.GetRequiredService <SerializationManager>();
            this.messageFactory       = this.ServiceProvider.GetService <MessageFactory>();

            this.config = this.ServiceProvider.GetRequiredService <ClientConfiguration>();

            var resolvedClientMessagingOptions = this.ServiceProvider.GetRequiredService <IOptions <ClientMessagingOptions> >();

            this.clientMessagingOptions = resolvedClientMessagingOptions.Value;

            this.GrainReferenceRuntime = this.ServiceProvider.GetRequiredService <IGrainReferenceRuntime>();

            var statisticsOptions = this.ServiceProvider.GetRequiredService <IOptions <ClientStatisticsOptions> >().Value;

            StatisticsCollector.Initialize(statisticsOptions.CollectionLevel);

            BufferPool.InitGlobalBufferPool(resolvedClientMessagingOptions.Value);

            try
            {
                AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

                clientProviderRuntime = this.ServiceProvider.GetRequiredService <ClientProviderRuntime>();

                responseTimeout   = Debugger.IsAttached ? Constants.DEFAULT_RESPONSE_TIMEOUT : config.ResponseTimeout;
                this.localAddress = ConfigUtilities.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, handshakeClientId));
                string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}' in AppDomain={2}",
                                                BARS, RuntimeVersion.Current, PrintAppDomainDetails());
                startMsg = string.Format("{0} Config= " + Environment.NewLine + " {1}", startMsg, config);
                logger.Info(ErrorCode.ClientStarting, startMsg);

                if (TestOnlyThrowExceptionDuringInit)
                {
                    throw new InvalidOperationException("TestOnlyThrowExceptionDuringInit");
                }

                this.gatewayListProvider = this.ServiceProvider.GetRequiredService <IGatewayListProvider>();

                if (StatisticsCollector.CollectThreadTimeTrackingStats)
                {
                    incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver", this.loggerFactory);
                }
            }
            catch (Exception exc)
            {
                if (logger != null)
                {
                    logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc);
                }
                ConstructorReset();
                throw;
            }
        }
Exemple #9
0
        internal void ConsumeServices(IServiceProvider services)
        {
            this.ServiceProvider = services;

            var connectionLostHandlers = services.GetServices <ConnectionToClusterLostHandler>();

            foreach (var handler in connectionLostHandlers)
            {
                this.ClusterConnectionLost += handler;
            }

            var clientInvokeCallbacks = services.GetServices <ClientInvokeCallback>();

            foreach (var handler in clientInvokeCallbacks)
            {
                this.ClientInvokeCallback += handler;
            }

            this.InternalGrainFactory = this.ServiceProvider.GetRequiredService <IInternalGrainFactory>();
            this.ClientStatistics     = this.ServiceProvider.GetRequiredService <ClientStatisticsManager>();
            this.SerializationManager = this.ServiceProvider.GetRequiredService <SerializationManager>();
            this.messageFactory       = this.ServiceProvider.GetService <MessageFactory>();

            this.config = services.GetRequiredService <ClientConfiguration>();
            this.GrainReferenceRuntime = this.ServiceProvider.GetRequiredService <IGrainReferenceRuntime>();

            if (!LogManager.IsInitialized)
            {
                LogManager.Initialize(config);
            }
            StatisticsCollector.Initialize(config);
            this.assemblyProcessor = this.ServiceProvider.GetRequiredService <AssemblyProcessor>();
            this.assemblyProcessor.Initialize();

            logger         = LogManager.GetLogger("OutsideRuntimeClient", LoggerType.Runtime);
            this.AppLogger = LogManager.GetLogger("Application", LoggerType.Application);

            BufferPool.InitGlobalBufferPool(config);


            try
            {
                LoadAdditionalAssemblies();

                if (!UnobservedExceptionsHandlerClass.TrySetUnobservedExceptionHandler(UnhandledException))
                {
                    logger.Warn(ErrorCode.Runtime_Error_100153, "Unable to set unobserved exception handler because it was already set.");
                }

                AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

                clientProviderRuntime     = this.ServiceProvider.GetRequiredService <ClientProviderRuntime>();
                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;
                this.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, handshakeClientId));
                string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}' in AppDomain={2}",
                                                BARS, RuntimeVersion.Current, PrintAppDomainDetails());
                startMsg = string.Format("{0} Config= " + Environment.NewLine + " {1}", startMsg, config);
                logger.Info(ErrorCode.ClientStarting, startMsg);

                if (TestOnlyThrowExceptionDuringInit)
                {
                    throw new InvalidOperationException("TestOnlyThrowExceptionDuringInit");
                }

                this.gatewayListProvider = this.ServiceProvider.GetRequiredService <IGatewayListProvider>();
                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;
            }
        }