コード例 #1
0
        // used for testing to (carefully!) allow two clients in the same process
        internal void StartInternal()
        {
            transport.Start();
            LogManager.MyIPEndPoint  = transport.MyAddress.Endpoint; // transport.MyAddress is only set after transport is Started.
            CurrentActivationAddress = ActivationAddress.NewActivationAddress(transport.MyAddress, handshakeClientId);
            ClientStatistics         = new ClientStatisticsManager(config);

            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.Factory.StartNew(() =>
            {
                try
                {
                    RunClientMessagePump(ct);
                }
                catch (Exception exc)
                {
                    logger.Error(ErrorCode.Runtime_Error_100326, "RunClientMessagePump has thrown exception", exc);
                }
            }
                                  );
            grainInterfaceMap = transport.GetTypeCodeMap(grainFactory).Result;

            ClientStatistics.Start(statisticsProviderManager, transport, clientId)
            .WaitWithThrow(initTimeout);

            StreamingInitialize();
        }
コード例 #2
0
        // used for testing to (carefully!) allow two clients in the same process
        private async Task StartInternal(CancellationToken cancellationToken)
        {
            var retryFilter = ServiceProvider.GetService <IClientConnectionRetryFilter>();

            var gatewayManager = this.ServiceProvider.GetRequiredService <GatewayManager>();

            await ExecuteWithRetries(
                async() => await gatewayManager.StartAsync(cancellationToken),
                retryFilter,
                cancellationToken);

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

            MessageCenter = ActivatorUtilities.CreateInstance <ClientMessageCenter>(this.ServiceProvider, localAddress, generation, clientId);
            MessageCenter.RegisterLocalMessageHandler(this.HandleMessage);
            await ExecuteWithRetries(
                async() => await MessageCenter.StartAsync(cancellationToken),
                retryFilter,
                cancellationToken);

            CurrentActivationAddress = GrainAddress.NewActivationAddress(MessageCenter.MyAddress, clientId.GrainId);

            this.gatewayObserver = new ClientGatewayObserver(gatewayManager);
            this.InternalGrainFactory.CreateObjectReference <IClientGatewayObserver>(this.gatewayObserver);

            await ExecuteWithRetries(
                async() => await this.ServiceProvider.GetRequiredService <ClientClusterManifestProvider>().StartAsync(),
                retryFilter,
                cancellationToken);

            ClientStatistics.Start(MessageCenter, clientId.GrainId);
コード例 #3
0
        // used for testing to (carefully!) allow two clients in the same process
        private async Task StartInternal(CancellationToken cancellationToken)
        {
            var retryFilterInterface = ServiceProvider.GetService <IClientConnectionRetryFilter>();
            Func <Exception, CancellationToken, Task <bool> > retryFilter = RetryFilter;

            var gatewayManager = this.ServiceProvider.GetRequiredService <GatewayManager>();

            await ExecuteWithRetries(async() => await gatewayManager.StartAsync(cancellationToken), retryFilter);

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

            MessageCenter = ActivatorUtilities.CreateInstance <ClientMessageCenter>(this.ServiceProvider, localAddress, generation, clientId);
            MessageCenter.RegisterLocalMessageHandler(this.HandleMessage);
            MessageCenter.Start();
            CurrentActivationAddress = ActivationAddress.NewActivationAddress(MessageCenter.MyAddress, clientId.GrainId);

            this.gatewayObserver = new ClientGatewayObserver(gatewayManager);
            this.InternalGrainFactory.CreateObjectReference <IClientGatewayObserver>(this.gatewayObserver);

            await ExecuteWithRetries(
                async() => await this.ServiceProvider.GetRequiredService <ClientClusterManifestProvider>().StartAsync(),
                retryFilter);

            ClientStatistics.Start(MessageCenter, clientId.GrainId);

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

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

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

            async Task <bool> RetryFilter(Exception exception, CancellationToken cancellationToken)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return(false);
                }

                if (retryFilterInterface is { })
                {
                    var result = await retryFilterInterface.ShouldRetryConnectionAttempt(exception, cancellationToken);

                    return(result && !cancellationToken.IsCancellationRequested);
                }
コード例 #4
0
        // used for testing to (carefully!) allow two clients in the same process
        private async Task StartInternal(Func <Exception, Task <bool> > retryFilter)
        {
            var gatewayManager = this.ServiceProvider.GetRequiredService <GatewayManager>();

            await ExecuteWithRetries(async() => await gatewayManager.StartAsync(CancellationToken.None), retryFilter);

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

            MessageCenter = ActivatorUtilities.CreateInstance <ClientMessageCenter>(this.ServiceProvider, localAddress, generation, clientId);
            MessageCenter.RegisterLocalMessageHandler(this.HandleMessage);
            MessageCenter.Start();
            CurrentActivationAddress = ActivationAddress.NewActivationAddress(MessageCenter.MyAddress, clientId.GrainId);

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

            await ExecuteWithRetries(
                async() => await this.ServiceProvider.GetRequiredService <ClientClusterManifestProvider>().StartAsync(),
                retryFilter);

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

            ClientStatistics.Start(MessageCenter, clientId.GrainId);

            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;
                        }
                    }
                }
            }
        }
コード例 #5
0
        // used for testing to (carefully!) allow two clients in the same process
        private async Task StartInternal()
        {
            await this.gatewayListProvider.InitializeGatewayListProvider(config, LogManager.GetLogger(gatewayListProvider.GetType().Name))
            .WithTimeout(initTimeout);

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

            transport = ActivatorUtilities.CreateInstance <ProxiedMessageCenter>(this.ServiceProvider, localAddress, generation, handshakeClientId);
            transport.Start();
            LogManager.MyIPEndPoint  = transport.MyAddress.Endpoint; // transport.MyAddress is only set after transport is Started.
            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();
            grainInterfaceMap = await transport.GetTypeCodeMap(this.InternalGrainFactory);

            await ClientStatistics.Start(statisticsProviderManager, transport, clientId)
            .WithTimeout(initTimeout);

            await StreamingInitialize();
        }
コード例 #6
0
        // used for testing to (carefully!) allow two clients in the same process
        private async Task StartInternal()
        {
            await this.gatewayListProvider.InitializeGatewayListProvider()
            .WithTimeout(initTimeout, $"gatewayListProvider.InitializeGatewayListProvider failed due to timeout {initTimeout}");

            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();
            grainTypeResolver = await transport.GetGrainTypeResolver(this.InternalGrainFactory);

            ClientStatistics.Start(transport, clientId);

            await StreamingInitialize();
        }
コード例 #7
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.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() => 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;
                        }
                    }
                }
            }
        }
コード例 #8
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, clientId);
            transport.RegisterLocalMessageHandler(this.HandleMessage);
            transport.Start();
            CurrentActivationAddress = ActivationAddress.NewActivationAddress(transport.MyAddress, clientId);

            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;
                        }
                    }
                }
            }
        }