Beispiel #1
0
        public void SerializationTests_Exception_DotNet()
        {
            ActivationAddress activationAddress        = ActivationAddress.NewActivationAddress(SiloAddress.NewLocalAddress(12345), GrainId.NewId());
            SiloAddress       primaryDirectoryForGrain = SiloAddress.NewLocalAddress(6789);

            Catalog.DuplicateActivationException original = new Catalog.DuplicateActivationException(activationAddress, primaryDirectoryForGrain);
            Catalog.DuplicateActivationException output   = TestingUtils.RoundTripDotNetSerializer(original);

            Assert.Equal(original.Message, output.Message);
            Assert.Equal(original.ActivationToUse, output.ActivationToUse);
            Assert.Equal(original.PrimaryDirectoryForGrain, output.PrimaryDirectoryForGrain);
        }
        // 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);

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

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

            ClientStatistics.Start(MessageCenter, 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;
                        }
                    }
                }
            }
        }
        // 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);

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

            clientProviderRuntime.StreamingInitialize();

            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;
                        }
                    }
                }
            }
        }
Beispiel #4
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();
        }
Beispiel #5
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();
        }
        // 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;
                        }
                    }
                }
            }
        }
        // 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;
                        }
                    }
                }
            }
        }