コード例 #1
0
        }                                    // might hold metadata used by response pipeline

        public CallbackData(
            Action <Message, TaskCompletionSource <object> > callback,
            Func <Message, bool> resendFunc,
            TaskCompletionSource <object> ctx,
            Message msg,
            Action <Message> unregisterDelegate,
            MessagingOptions messagingOptions,
            ILogger logger,
            ILogger timerLogger,
            ApplicationRequestsStatisticsGroup requestStatistics)
        {
            // We are never called without a callback func, but best to double check.
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }
            // We are never called without a resend func, but best to double check.
            if (resendFunc == null)
            {
                throw new ArgumentNullException(nameof(resendFunc));
            }
            this.logger            = logger;
            this.callback          = callback;
            this.resendFunc        = resendFunc;
            context                = ctx;
            Message                = msg;
            unregister             = unregisterDelegate;
            alreadyFired           = false;
            this.messagingOptions  = messagingOptions;
            this.TransactionInfo   = TransactionContext.GetTransactionInfo();
            this.timerLogger       = timerLogger;
            this.requestStatistics = requestStatistics;
        }
コード例 #2
0
ファイル: InsideRuntimeClient.cs プロジェクト: timb33/orleans
 public InsideRuntimeClient(
     ILocalSiloDetails siloDetails,
     GrainTypeManager typeManager,
     TypeMetadataCache typeMetadataCache,
     OrleansTaskScheduler scheduler,
     IServiceProvider serviceProvider,
     MessageFactory messageFactory,
     ITransactionAgent transactionAgent,
     ILoggerFactory loggerFactory,
     IOptions <SiloMessagingOptions> messagingOptions,
     IGrainCancellationTokenRuntime cancellationTokenRuntime,
     IOptions <SchedulingOptions> schedulerOptions,
     ApplicationRequestsStatisticsGroup appRequestStatistics)
 {
     this.ServiceProvider          = serviceProvider;
     this.MySilo                   = siloDetails.SiloAddress;
     this.disposables              = new List <IDisposable>();
     this.callbacks                = new ConcurrentDictionary <CorrelationId, CallbackData>();
     this.typeManager              = typeManager;
     this.messageFactory           = messageFactory;
     this.transactionAgent         = transactionAgent;
     this.Scheduler                = scheduler;
     this.ConcreteGrainFactory     = new GrainFactory(this, typeMetadataCache);
     this.logger                   = loggerFactory.CreateLogger <InsideRuntimeClient>();
     this.invokeExceptionLogger    = loggerFactory.CreateLogger($"{typeof(Grain).FullName}.InvokeException");
     this.loggerFactory            = loggerFactory;
     this.messagingOptions         = messagingOptions.Value;
     this.cancellationTokenRuntime = cancellationTokenRuntime;
     this.appRequestStatistics     = appRequestStatistics;
     this.schedulingOptions        = schedulerOptions.Value;
 }
コード例 #3
0
ファイル: CallbackData.cs プロジェクト: tcunning/orleans
        public void OnTimeout()
        {
            if (alreadyFired)
            {
                return;
            }
            var msg = this.Message; // Local working copy

            lock (this)
            {
                if (alreadyFired)
                {
                    return;
                }

                if (Config.ResendOnTimeout && resendFunc(msg))
                {
                    if (logger.IsVerbose)
                    {
                        logger.Verbose("OnTimeout - Resend {0} for {1}", msg.ResendCount, msg);
                    }
                    return;
                }

                alreadyFired = true;
                DisposeTimer();
                if (StatisticsCollector.CollectApplicationRequestsStats)
                {
                    timeSinceIssued.Stop();
                }

                if (unregister != null)
                {
                    unregister();
                }
            }

            string messageHistory = msg.GetTargetHistory();
            string errorMsg       = String.Format("Response did not arrive on time in {0} for message: {1}. Target History is: {2}",
                                                  timeout, msg, messageHistory);

            logger.Warn(ErrorCode.Runtime_Error_100157, "{0}. About to break its promise.", errorMsg);

            var error = new Message(Message.Categories.Application, Message.Directions.Response)
            {
                Result     = Message.ResponseTypes.Error,
                BodyObject = Response.ExceptionResponse(new TimeoutException(errorMsg))
            };

            if (StatisticsCollector.CollectApplicationRequestsStats)
            {
                ApplicationRequestsStatisticsGroup.OnAppRequestsEnd(timeSinceIssued.Elapsed);
                ApplicationRequestsStatisticsGroup.OnAppRequestsTimedOut();
            }

            callback(error, context);
        }
コード例 #4
0
        internal ClientStatisticsManager(ClientConfiguration config)
        {
            this.config   = config;
            runtimeStats  = new RuntimeStatisticsGroup();
            logStatistics = new LogStatistics(config.StatisticsLogWriteInterval, false);
            logger        = LogManager.GetLogger(GetType().Name);

            MessagingStatisticsGroup.Init(false);
            NetworkingStatisticsGroup.Init(false);
            ApplicationRequestsStatisticsGroup.Init(config.ResponseTimeout);
        }
コード例 #5
0
 public ClientStatisticsManager(
     SerializationManager serializationManager,
     ILoggerFactory loggerFactory,
     IOptions <ClientStatisticsOptions> statisticsOptions)
 {
     this.statisticsOptions = statisticsOptions.Value;
     this.logStatistics     = new LogStatistics(this.statisticsOptions.LogWriteInterval, false, serializationManager, loggerFactory);
     MessagingStatisticsGroup.Init(false);
     NetworkingStatisticsGroup.Init(false);
     ApplicationRequestsStatisticsGroup.Init();
 }
コード例 #6
0
 public ClientStatisticsManager(ClientConfiguration config, SerializationManager serializationManager, IServiceProvider serviceProvider, ILoggerFactory loggerFactory)
 {
     this.config          = config;
     this.serviceProvider = serviceProvider;
     runtimeStats         = new RuntimeStatisticsGroup(loggerFactory);
     logStatistics        = new LogStatistics(config.StatisticsLogWriteInterval, false, serializationManager, loggerFactory);
     logger             = new LoggerWrapper <ClientStatisticsManager>(loggerFactory);
     this.loggerFactory = loggerFactory;
     MessagingStatisticsGroup.Init(false);
     NetworkingStatisticsGroup.Init(false);
     ApplicationRequestsStatisticsGroup.Init(config.ResponseTimeout);
 }
コード例 #7
0
 public SharedCallbackData(
     Action <Message> unregister,
     ILogger logger,
     MessagingOptions messagingOptions,
     ApplicationRequestsStatisticsGroup requestStatistics)
 {
     RequestStatistics     = requestStatistics;
     this.Unregister       = unregister;
     this.Logger           = logger;
     this.MessagingOptions = messagingOptions;
     this.ResponseTimeout  = messagingOptions.ResponseTimeout;
 }
コード例 #8
0
        public ClientStatisticsManager(ClientConfiguration config, SerializationManager serializationManager, IServiceProvider serviceProvider)
        {
            this.config          = config;
            this.serviceProvider = serviceProvider;
            runtimeStats         = new RuntimeStatisticsGroup();
            logStatistics        = new LogStatistics(config.StatisticsLogWriteInterval, false, serializationManager);
            logger = LogManager.GetLogger(GetType().Name);

            MessagingStatisticsGroup.Init(false);
            NetworkingStatisticsGroup.Init(false);
            ApplicationRequestsStatisticsGroup.Init(config.ResponseTimeout);
        }
コード例 #9
0
 public ClientStatisticsManager(ClientConfiguration config, SerializationManager serializationManager, IServiceProvider serviceProvider, ILoggerFactory loggerFactory, IOptions <StatisticsOptions> statisticsOptions, IOptions <ClusterClientOptions> clusterClientOptions)
 {
     this.config               = config;
     this.statisticsOptions    = statisticsOptions.Value;
     this.serviceProvider      = serviceProvider;
     this.clusterClientOptions = clusterClientOptions.Value;
     runtimeStats              = new RuntimeStatisticsGroup(loggerFactory);
     logStatistics             = new LogStatistics(this.statisticsOptions.LogWriteInterval, false, serializationManager, loggerFactory);
     logger             = loggerFactory.CreateLogger <ClientStatisticsManager>();
     this.loggerFactory = loggerFactory;
     MessagingStatisticsGroup.Init(false);
     NetworkingStatisticsGroup.Init(false);
     ApplicationRequestsStatisticsGroup.Init(config.ResponseTimeout);
 }
コード例 #10
0
ファイル: SharedCallbackData.cs プロジェクト: zmyer/orleans
 public SharedCallbackData(
     Func <Message, bool> resendFunc,
     Action <Message> unregister,
     ILogger logger,
     MessagingOptions messagingOptions,
     SerializationManager serializationManager,
     ApplicationRequestsStatisticsGroup requestStatistics)
 {
     RequestStatistics         = requestStatistics;
     this.ShouldResend         = resendFunc;
     this.Unregister           = unregister;
     this.serializationManager = serializationManager;
     this.Logger           = logger;
     this.MessagingOptions = messagingOptions;
     this.ResponseTimeout  = messagingOptions.ResponseTimeout;
 }
コード例 #11
0
ファイル: CallbackData.cs プロジェクト: tcunning/orleans
        public void DoCallback(Message response)
        {
            if (alreadyFired)
            {
                return;
            }
            lock (this)
            {
                if (alreadyFired)
                {
                    return;
                }

                if (response.Result == Message.ResponseTypes.Rejection && response.RejectionType == Message.RejectionTypes.Transient)
                {
                    if (resendFunc(Message))
                    {
                        return;
                    }
                }

                alreadyFired = true;
                DisposeTimer();
                if (StatisticsCollector.CollectApplicationRequestsStats)
                {
                    timeSinceIssued.Stop();
                }
                if (unregister != null)
                {
                    unregister();
                }
            }
            if (Message.WriteMessagingTraces)
            {
                response.AddTimestamp(Message.LifecycleTag.InvokeIncoming);
            }
            if (logger.IsVerbose2)
            {
                logger.Verbose2("Message {0} timestamps: {1}", response, response.GetTimestampString());
            }
            if (StatisticsCollector.CollectApplicationRequestsStats)
            {
                ApplicationRequestsStatisticsGroup.OnAppRequestsEnd(timeSinceIssued.Elapsed);
            }
            // do callback outside the CallbackData lock. Just not a good practice to hold a lock for this unrelated operation.
            callback(response, context);
        }
コード例 #12
0
        public InsideRuntimeClient(
            ILocalSiloDetails siloDetails,
            TypeMetadataCache typeMetadataCache,
            OrleansTaskScheduler scheduler,
            IServiceProvider serviceProvider,
            MessageFactory messageFactory,
            ITransactionAgent transactionAgent,
            ILoggerFactory loggerFactory,
            IOptions <SiloMessagingOptions> messagingOptions,
            ApplicationRequestsStatisticsGroup appRequestStatistics,
            MessagingTrace messagingTrace,
            GrainReferenceActivator referenceActivator,
            GrainInterfaceTypeResolver interfaceIdResolver,
            GrainInterfaceTypeToGrainTypeResolver interfaceToTypeResolver,
            ImrGrainMethodInvokerProvider invokers)
        {
            this.ServiceProvider       = serviceProvider;
            this.MySilo                = siloDetails.SiloAddress;
            this.disposables           = new List <IDisposable>();
            this.callbacks             = new ConcurrentDictionary <CorrelationId, CallbackData>();
            this.messageFactory        = messageFactory;
            this.transactionAgent      = transactionAgent;
            this.Scheduler             = scheduler;
            this.ConcreteGrainFactory  = new GrainFactory(this, typeMetadataCache, referenceActivator, interfaceIdResolver, interfaceToTypeResolver);
            this.logger                = loggerFactory.CreateLogger <InsideRuntimeClient>();
            this.invokeExceptionLogger = loggerFactory.CreateLogger($"{typeof(Grain).FullName}.InvokeException");
            this.loggerFactory         = loggerFactory;
            this.messagingOptions      = messagingOptions.Value;
            this.appRequestStatistics  = appRequestStatistics;
            this.messagingTrace        = messagingTrace;
            this.invokers              = invokers;

            this.sharedCallbackData = new SharedCallbackData(
                msg => this.UnregisterCallback(msg.Id),
                this.loggerFactory.CreateLogger <CallbackData>(),
                this.messagingOptions,
                this.appRequestStatistics,
                this.messagingOptions.ResponseTimeout);

            this.systemSharedCallbackData = new SharedCallbackData(
                msg => this.UnregisterCallback(msg.Id),
                this.loggerFactory.CreateLogger <CallbackData>(),
                this.messagingOptions,
                this.appRequestStatistics,
                this.messagingOptions.SystemResponseTimeout);
        }
コード例 #13
0
 public ClientStatisticsManager(
     IOptions <MonitoringStorageOptions> storageOptions,
     SerializationManager serializationManager,
     IServiceProvider serviceProvider,
     ILoggerFactory loggerFactory,
     IOptions <ClientStatisticsOptions> statisticsOptions,
     IOptions <ClusterClientOptions> clusterClientOptions)
 {
     this.statisticsOptions    = statisticsOptions.Value;
     this.storageOptions       = storageOptions.Value;
     this.serviceProvider      = serviceProvider;
     this.clusterClientOptions = clusterClientOptions.Value;
     logStatistics             = new LogStatistics(this.statisticsOptions.LogWriteInterval, false, serializationManager, loggerFactory);
     logger = loggerFactory.CreateLogger <ClientStatisticsManager>();
     MessagingStatisticsGroup.Init(false);
     NetworkingStatisticsGroup.Init(false);
     ApplicationRequestsStatisticsGroup.Init();
     this.dnsHostName = Dns.GetHostName();
 }
コード例 #14
0
ファイル: CallbackData.cs プロジェクト: wanglong/orleans
        private void OnFail(Message msg, Message error, string resendLogMessageFormat, bool isOnTimeout = false)
        {
            lock (this)
            {
                if (alreadyFired)
                {
                    return;
                }

                if (config.ResendOnTimeout && resendFunc(msg))
                {
                    if (logger.IsVerbose)
                    {
                        logger.Verbose(resendLogMessageFormat, msg.ResendCount, msg);
                    }
                    return;
                }

                alreadyFired = true;
                DisposeTimer();
                if (StatisticsCollector.CollectApplicationRequestsStats)
                {
                    timeSinceIssued.Stop();
                }

                if (unregister != null)
                {
                    unregister();
                }
            }

            if (StatisticsCollector.CollectApplicationRequestsStats)
            {
                ApplicationRequestsStatisticsGroup.OnAppRequestsEnd(timeSinceIssued.Elapsed);
                if (isOnTimeout)
                {
                    ApplicationRequestsStatisticsGroup.OnAppRequestsTimedOut();
                }
            }

            callback(error, context);
        }
コード例 #15
0
        public void DoCallback(Message response)
        {
            if (alreadyFired)
            {
                return;
            }
            lock (this)
            {
                if (alreadyFired)
                {
                    return;
                }

                if (response.Result == Message.ResponseTypes.Rejection && response.RejectionType == Message.RejectionTypes.Transient)
                {
                    if (resendFunc(Message))
                    {
                        return;
                    }
                }

                alreadyFired = true;
                DisposeTimer();
                if (StatisticsCollector.CollectApplicationRequestsStats)
                {
                    timeSinceIssued.Stop();
                }
                if (unregister != null)
                {
                    unregister();
                }
            }
            if (StatisticsCollector.CollectApplicationRequestsStats)
            {
                ApplicationRequestsStatisticsGroup.OnAppRequestsEnd(timeSinceIssued.Elapsed);
            }
            // do callback outside the CallbackData lock. Just not a good practice to hold a lock for this unrelated operation.
            callback(response, context);
        }
コード例 #16
0
        internal async Task Start(ClientConfiguration config, StatisticsProviderManager statsManager, IMessageCenter transport, Guid clientId)
        {
            MessagingStatisticsGroup.Init(false);
            NetworkingStatisticsGroup.Init(false);
            ApplicationRequestsStatisticsGroup.Init(config.ResponseTimeout);

            runtimeStats.Start();

            // Configure Metrics
            IProvider statsProvider = null;

            if (!string.IsNullOrEmpty(config.StatisticsProviderName))
            {
                var extType = config.StatisticsProviderName;
                statsProvider = statsManager.GetProvider(extType);
                var metricsDataPublisher = statsProvider as IClientMetricsDataPublisher;
                if (metricsDataPublisher == null)
                {
                    var msg = String.Format("Trying to create {0} as a metrics publisher, but the provider is not configured."
                                            , extType);
                    throw new ArgumentException(msg, "ProviderType (configuration)");
                }
                var configurableMetricsDataPublisher = metricsDataPublisher as IConfigurableClientMetricsDataPublisher;
                if (configurableMetricsDataPublisher != null)
                {
                    configurableMetricsDataPublisher.AddConfiguration(
                        config.DeploymentId, config.DNSHostName, clientId.ToString(), transport.MyAddress.Endpoint.Address);
                }
                tableStatistics = new ClientTableStatistics(transport, metricsDataPublisher, runtimeStats)
                {
                    MetricsTableWriteInterval = config.StatisticsMetricsTableWriteInterval
                };
            }
            else if (config.UseAzureSystemStore)
            {
                // Hook up to publish client metrics to Azure storage table
                var publisher = await ClientMetricsTableDataManager.GetManager(config, transport.MyAddress.Endpoint.Address, clientId);

                tableStatistics = new ClientTableStatistics(transport, publisher, runtimeStats)
                {
                    MetricsTableWriteInterval = config.StatisticsMetricsTableWriteInterval
                };
            }

            // Configure Statistics
            if (config.StatisticsWriteLogStatisticsToTable)
            {
                if (statsProvider != null)
                {
                    logStatistics.StatsTablePublisher = statsProvider as IStatisticsPublisher;
                    // Note: Provider has already been Init-ialized above.
                }
                else if (config.UseAzureSystemStore)
                {
                    var statsDataPublisher = await StatsTableDataManager.GetManager(false, config.DataConnectionString, config.DeploymentId, transport.MyAddress.Endpoint.ToString(), clientId.ToString(), config.DNSHostName);

                    logStatistics.StatsTablePublisher = statsDataPublisher;
                }
            }
            logStatistics.Start();
        }