Ejemplo n.º 1
0
 public void Dispose()
 {
     if (tableReportTimer != null)
         tableReportTimer.Dispose();
     tableReportTimer = null;
 }
        public void Reset(bool cleanup)
        {
            Utils.SafeExecute(() =>
            {
                if (logger != null)
                {
                    logger.Info("OutsideRuntimeClient.Reset(): client Id " + clientId);
                }
            }, this.logger);

            Utils.SafeExecute(() =>
            {
                if (typeMapRefreshTimer != null)
                {
                    typeMapRefreshTimer.Dispose();
                    typeMapRefreshTimer = null;
                }
            }, logger, "Client.typeMapRefreshTimer.Dispose");
            Utils.SafeExecute(() =>
            {
                if (clientProviderRuntime != null)
                {
                    clientProviderRuntime.Reset(cleanup).WaitWithThrow(ResetTimeout);
                }
            }, logger, "Client.clientProviderRuntime.Reset");
            Utils.SafeExecute(() =>
            {
                incomingMessagesThreadTimeTracking?.OnStopExecution();
            }, logger, "Client.incomingMessagesThreadTimeTracking.OnStopExecution");
            Utils.SafeExecute(() =>
            {
                if (transport != null)
                {
                    transport.PrepareToStop();
                }
            }, logger, "Client.PrepareToStop-Transport");

            listenForMessages = false;
            Utils.SafeExecute(() =>
            {
                if (listeningCts != null)
                {
                    listeningCts.Cancel();
                }
            }, logger, "Client.Stop-ListeningCTS");
            Utils.SafeExecute(() =>
            {
                if (transport != null)
                {
                    transport.Stop();
                }
            }, logger, "Client.Stop-Transport");
            Utils.SafeExecute(() =>
            {
                if (ClientStatistics != null)
                {
                    ClientStatistics.Stop();
                }
            }, logger, "Client.Stop-ClientStatistics");
            ConstructorReset();
        }
Ejemplo n.º 3
0
        // used for testing to (carefully!) allow two clients in the same process
        private async Task StartInternal(Func <Exception, Task <bool> > retryFilter)
        {
            // Initialize the gateway list provider, since information from the cluster is required to successfully
            // initialize subsequent services.
            var initializedGatewayProvider = new[] { false };

            await ExecuteWithRetries(async() =>
            {
                if (!initializedGatewayProvider[0])
                {
                    await this.gatewayListProvider.InitializeGatewayListProvider();
                    initializedGatewayProvider[0] = true;
                }

                var gateways = await this.gatewayListProvider.GetGateways();
                if (gateways.Count == 0)
                {
                    var gatewayProviderType = this.gatewayListProvider.GetType().GetParseableName();
                    var err = $"Could not find any gateway in {gatewayProviderType}. Orleans client cannot initialize.";
                    logger.Error(ErrorCode.GatewayManager_NoGateways, err);
                    throw new SiloUnavailableException(err);
                }
            },
                                     retryFilter);

            var generation = -SiloAddress.AllocateNewGeneration(); // Client generations are negative

            transport = ActivatorUtilities.CreateInstance <ClientMessageCenter>(this.ServiceProvider, localAddress, generation, handshakeClientId);
            transport.RegisterLocalMessageHandler(Message.Categories.Application, this.HandleMessage);
            transport.Start();
            CurrentActivationAddress = ActivationAddress.NewActivationAddress(transport.MyAddress, handshakeClientId);

            // Keeping this thread handling it very simple for now. Just queue task on thread pool.
            Task.Run(this.RunClientMessagePump).Ignore();

            await ExecuteWithRetries(
                async() => this.GrainTypeResolver = await transport.GetGrainTypeResolver(this.InternalGrainFactory),
                retryFilter);

            this.typeMapRefreshTimer = new AsyncTaskSafeTimer(
                this.logger,
                RefreshGrainTypeResolver,
                null,
                this.typeMapRefreshInterval,
                this.typeMapRefreshInterval);

            ClientStatistics.Start(transport, clientId);

            await ExecuteWithRetries(StreamingInitialize, retryFilter);

            async Task ExecuteWithRetries(Func <Task> task, Func <Exception, Task <bool> > shouldRetry)
            {
                while (true)
                {
                    try
                    {
                        await task();

                        return;
                    }
                    catch (Exception exception) when(shouldRetry != null)
                    {
                        var retry = await shouldRetry(exception);

                        if (!retry)
                        {
                            throw;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        // used for testing to (carefully!) allow two clients in the same process
        private async Task StartInternal(Func <Exception, Task <bool> > retryFilter)
        {
            // Initialize the gateway list provider, since information from the cluster is required to successfully
            // initialize subsequent services.
            var initializedGatewayProvider = new[] { false };

            await ExecuteWithRetries(async() =>
            {
                if (!initializedGatewayProvider[0])
                {
                    await this.gatewayListProvider.InitializeGatewayListProvider();
                    initializedGatewayProvider[0] = true;
                }

                var gateways = await this.gatewayListProvider.GetGateways();
                if (gateways.Count == 0)
                {
                    var gatewayProviderType = this.gatewayListProvider.GetType().GetParseableName();
                    var err = $"Could not find any gateway in {gatewayProviderType}. Orleans client cannot initialize.";
                    logger.Error(ErrorCode.GatewayManager_NoGateways, err);
                    throw new OrleansException(err);
                }
            },
                                     retryFilter);

            var generation = -SiloAddress.AllocateNewGeneration(); // Client generations are negative

            transport = ActivatorUtilities.CreateInstance <ClientMessageCenter>(this.ServiceProvider, localAddress, generation, handshakeClientId);
            transport.Start();
            CurrentActivationAddress = ActivationAddress.NewActivationAddress(transport.MyAddress, handshakeClientId);

            listeningCts = new CancellationTokenSource();
            var ct = listeningCts.Token;

            listenForMessages = true;

            // Keeping this thread handling it very simple for now. Just queue task on thread pool.
            Task.Run(
                () =>
            {
                while (listenForMessages && !ct.IsCancellationRequested)
                {
                    try
                    {
                        RunClientMessagePump(ct);
                    }
                    catch (Exception exc)
                    {
                        logger.Error(ErrorCode.Runtime_Error_100326, "RunClientMessagePump has thrown exception", exc);
                    }
                }
            },
                ct).Ignore();

            await ExecuteWithRetries(async() =>
            {
                var originalTimeout = this.GetResponseTimeout();
                try
                {
                    await RefreshGrainTypeResolver(null);
                }
                finally
                {
                    this.SetResponseTimeout(originalTimeout);
                }
            },
                                     retryFilter);

            this.typeMapRefreshTimer = new AsyncTaskSafeTimer(
                this.logger,
                RefreshGrainTypeResolver,
                null,
                this.typeMapRefreshInterval,
                this.typeMapRefreshInterval);

            ClientStatistics.Start(transport, clientId);

            await ExecuteWithRetries(StreamingInitialize, retryFilter);

            async Task ExecuteWithRetries(Func <Task> task, Func <Exception, Task <bool> > shouldRetry)
            {
                while (true)
                {
                    try
                    {
                        await task();

                        return;
                    }
                    catch (Exception exception) when(shouldRetry != null)
                    {
                        var retry = await shouldRetry(exception);

                        if (!retry)
                        {
                            throw;
                        }
                    }
                }
            }
        }