コード例 #1
0
 private void EnsureInitialized()
 {
     if (!isInitialized)
     {
         lock (this.initializationLock)
         {
             if (!isInitialized)
             {
                 this.messageCenter     = this.connectionShared.ServiceProvider.GetRequiredService <ClientMessageCenter>();
                 this.connectionManager = this.connectionShared.ServiceProvider.GetRequiredService <ConnectionManager>();
                 this.isInitialized     = true;
             }
         }
     }
 }
コード例 #2
0
 public ClientOutboundConnection(
     SiloAddress remoteSiloAddress,
     ConnectionContext connection,
     ConnectionDelegate middleware,
     ClientMessageCenter messageCenter,
     ConnectionManager connectionManager,
     ConnectionOptions connectionOptions,
     ConnectionCommon connectionShared)
     : base(connection, middleware, connectionShared)
 {
     this.messageCenter          = messageCenter;
     this.connectionManager      = connectionManager;
     this.connectionOptions      = connectionOptions;
     this.remoteSiloAddress      = remoteSiloAddress ?? throw new ArgumentNullException(nameof(remoteSiloAddress));
     this.MessageReceivedCounter = MessagingStatisticsGroup.GetMessageReceivedCounter(this.remoteSiloAddress);
     this.MessageSentCounter     = MessagingStatisticsGroup.GetMessageSendCounter(this.remoteSiloAddress);
 }
コード例 #3
0
 public ClientOutboundConnection(
     SiloAddress remoteSiloAddress,
     ConnectionContext connection,
     ConnectionDelegate middleware,
     MessageFactory messageFactory,
     IServiceProvider serviceProvider,
     ClientMessageCenter messageCenter,
     INetworkingTrace trace,
     ConnectionManager connectionManager,
     ConnectionOptions connectionOptions)
     : base(connection, middleware, serviceProvider, trace)
 {
     this.messageFactory    = messageFactory;
     this.messageCenter     = messageCenter;
     this.connectionManager = connectionManager;
     this.connectionOptions = connectionOptions;
     this.RemoteSiloAddress = remoteSiloAddress ?? throw new ArgumentNullException(nameof(remoteSiloAddress));
 }
コード例 #4
0
 public ClientOutboundConnection(
     ConnectionContext connection,
     ConnectionDelegate middleware,
     MessageFactory messageFactory,
     IServiceProvider serviceProvider,
     ClientMessageCenter messageCenter,
     GatewayManager gatewayManager,
     INetworkingTrace trace)
     : base(connection, middleware, serviceProvider, trace)
 {
     this.messageFactory = messageFactory;
     this.messageCenter  = messageCenter;
     this.gatewayManager = gatewayManager;
     if (connection.RemoteEndPoint is IPEndPoint ipEndpoint)
     {
         this.TargetSilo = SiloAddress.New(ipEndpoint, 0);
     }
 }
コード例 #5
0
 protected override Connection CreateConnection(ConnectionContext context)
 {
     if (this.messageCenter is null)
     {
         this.messageCenter = this.serviceProvider.GetRequiredService <ClientMessageCenter>();
     }
     if (this.gatewayManager is null)
     {
         this.gatewayManager = this.serviceProvider.GetRequiredService <GatewayManager>();
     }
     return(new ClientOutboundConnection(
                context,
                this.ConnectionDelegate,
                this.messageFactory,
                this.serviceProvider,
                this.messageCenter,
                this.gatewayManager,
                this.trace));
 }
コード例 #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;
                        }
                    }
                }
            }
        }