Exemplo n.º 1
0
        private GrainAddress GenerateActivationAddress()
        {
            var grainId  = LegacyGrainId.GetGrainIdForTesting(Guid.NewGuid());
            var siloAddr = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 5000), ++generation);

            return(GrainAddress.NewActivationAddress(siloAddr, grainId));
        }
Exemplo n.º 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);
Exemplo n.º 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 = 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);

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