Пример #1
0
        protected AsynchAgent(string nameSuffix, ExecutorService executorService, ILoggerFactory loggerFactory)
        {
            this.executorService = executorService;
            Cts = new CancellationTokenSource();
            var thisType = GetType();

            type = thisType.Namespace + "." + thisType.Name;
            if (type.StartsWith("Orleans.", StringComparison.Ordinal))
            {
                type = type.Substring(8);
            }
            if (!string.IsNullOrEmpty(nameSuffix))
            {
                Name = type + "/" + nameSuffix;
            }
            else
            {
                Name = type;
            }

            Lockable = new object();
            State    = ThreadState.Unstarted;
            OnFault  = FaultBehavior.IgnoreFault;
            Log      = loggerFactory.CreateLogger(Name);

            AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

#if TRACK_DETAILED_STATS
            if (StatisticsCollector.CollectThreadTimeTrackingStats)
            {
                threadTracking = new ThreadTrackingStatistic(Name);
            }
#endif
        }
Пример #2
0
        protected AsynchAgent(string nameSuffix)
        {
            Cts = new CancellationTokenSource();
            var thisType = GetType();
            
            type = thisType.Namespace + "." + thisType.Name;
            if (type.StartsWith("Orleans.", StringComparison.Ordinal))
            {
                type = type.Substring(8);
            }
            if (!string.IsNullOrEmpty(nameSuffix))
            {
                Name = type + "/" + nameSuffix;
            }
            else
            {
                Name = type;
            }

            Lockable = new object();
            State = ThreadState.Unstarted;
            OnFault = FaultBehavior.IgnoreFault;
            Log = TraceLogger.GetLogger(Name, TraceLogger.LoggerType.Runtime);
            AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

#if TRACK_DETAILED_STATS
            if (StatisticsCollector.CollectThreadTimeTrackingStats)
            {
                threadTracking = new ThreadTrackingStatistic(Name);
            }
#endif
            t = new Thread(AgentThreadProc) { IsBackground = true, Name = this.Name };
        }
Пример #3
0
        public ThreadPerTaskExecutor(string name)
        {
            this.name = name;

#if TRACK_DETAILED_STATS
            if (StatisticsCollector.CollectThreadTimeTrackingStats)
            {
                threadTracking = new ThreadTrackingStatistic(Name);
            }
#endif
        }
Пример #4
0
 public void AddTracking(ThreadTrackingStatistic tts)
 {
     lock (stageGroups)
     {
         // we trim all thread numbers from thread name, so allow to group them.
         char[] toTrim    = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '/', '_', '.' };
         string stageName = tts.Name.Trim(toTrim);
         List <ThreadTrackingStatistic> stageGroup;
         if (!stageGroups.TryGetValue(stageName, out stageGroup))
         {
             stageGroup = new List <ThreadTrackingStatistic>();
             stageGroups.Add(stageName, stageGroup);
         }
         stageGroup.Add(tts);
     }
 }
Пример #5
0
 public void AddTracking(ThreadTrackingStatistic tts)
 {
     lock (stageGroups)
     {
         // we trim all thread numbers from thread name, so allow to group them.
         char[] toTrim = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '/', '_', '.' };
         string stageName = tts.Name.Trim(toTrim);
         List<ThreadTrackingStatistic> stageGroup;
         if (!stageGroups.TryGetValue(stageName, out stageGroup))
         {
             stageGroup = new List<ThreadTrackingStatistic>();
             stageGroups.Add(stageName, stageGroup);
         }
         stageGroup.Add(tts);
     }
 }
Пример #6
0
        protected AsynchAgent(string nameSuffix)
        {
            Cts = new CancellationTokenSource();
            var thisType = GetType();
            int n        = 0;

            lock (classLockable)
            {
                SequenceNumbers.TryGetValue(thisType, out n);
                n++;
                SequenceNumbers[thisType] = n;
            }

            type = thisType.Namespace + "." + thisType.Name;
            if (type.StartsWith("Orleans.", StringComparison.Ordinal))
            {
                type = type.Substring(8);
            }
            if (!string.IsNullOrEmpty(nameSuffix))
            {
                Name = type + "." + nameSuffix + "/" + n;
            }
            else
            {
                Name = type + "/" + n;
            }

            Lockable = new object();
            State    = ThreadState.Unstarted;
            OnFault  = FaultBehavior.IgnoreFault;
            Log      = TraceLogger.GetLogger(Name, TraceLogger.LoggerType.Runtime);
            AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_DomainUnload);

#if TRACK_DETAILED_STATS
            if (StatisticsCollector.CollectThreadTimeTrackingStats)
            {
                threadTracking = new ThreadTrackingStatistic(Name);
            }
#endif

            t = new Thread(AgentThreadProc)
            {
                IsBackground = true, Name = this.Name
            };
        }
Пример #7
0
        protected AsynchAgent(string nameSuffix)
        {
            Cts = new CancellationTokenSource();
            var thisType = GetType();

            type = thisType.Namespace + "." + thisType.Name;
            if (type.StartsWith("Orleans.", StringComparison.Ordinal))
            {
                type = type.Substring(8);
            }
            if (!string.IsNullOrEmpty(nameSuffix))
            {
                Name = type + "/" + nameSuffix;
            }
            else
            {
                Name = type;
            }

            Lockable = new object();
            State    = ThreadState.Unstarted;
            OnFault  = FaultBehavior.IgnoreFault;
            Log      = LogManager.GetLogger(Name, LoggerType.Runtime);
#if !NETSTANDARD
            AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
#endif

#if TRACK_DETAILED_STATS
            if (StatisticsCollector.CollectThreadTimeTrackingStats)
            {
                threadTracking = new ThreadTrackingStatistic(Name);
            }
#endif
            t = new Thread(AgentThreadProc)
            {
                IsBackground = true, Name = this.Name
            };
        }
Пример #8
0
        public QueuedExecutor(string name, CancellationTokenSource cts, bool drainAfterCancel)
        {
            if (StatisticsCollector.CollectQueueStats)
            {
                queueTracking = new QueueTrackingStatistic(name);
            }

#if TRACK_DETAILED_STATS
            if (StatisticsCollector.CollectThreadTimeTrackingStats)
            {
                threadTracking = new ThreadTrackingStatistic(Name);
            }
#endif
            this.drainAfterCancel   = drainAfterCancel;
            cancellationTokenSource = cts;
            cancellationTokenSource.Token.Register(() =>
            {
                // allow threads to get a chance to exit gracefully.
                workQueue.Add(QueueWorkItemCallback.NoOpQueueWorkItemCallback);
                workQueue.CompleteAdding();
            });
            new ThreadPerTaskExecutor(name).QueueWorkItem(_ => ProcessQueue());
        }
Пример #9
0
        public OutsideRuntimeClient(ClientConfiguration cfg, GrainFactory grainFactory, bool secondary = false)
        {
            this.grainFactory = grainFactory;
            this.clientId = GrainId.NewClientId();

            if (cfg == null)
            {
                Console.WriteLine("An attempt to create an OutsideRuntimeClient with null ClientConfiguration object.");
                throw new ArgumentException("OutsideRuntimeClient was attempted to be created with null ClientConfiguration object.", "cfg");
            }

            this.config = cfg;

            if (!TraceLogger.IsInitialized) TraceLogger.Initialize(config);
            StatisticsCollector.Initialize(config);
            SerializationManager.Initialize(config.UseStandardSerializer, cfg.SerializationProviders, config.UseJsonFallbackSerializer);
            logger = TraceLogger.GetLogger("OutsideRuntimeClient", TraceLogger.LoggerType.Runtime);
            appLogger = TraceLogger.GetLogger("Application", TraceLogger.LoggerType.Application);

            try
            {
                LoadAdditionalAssemblies();
                
                PlacementStrategy.Initialize();

                callbacks = new ConcurrentDictionary<CorrelationId, CallbackData>();
                localObjects = new ConcurrentDictionary<GuidId, LocalObjectData>();

                if (!secondary)
                {
                    UnobservedExceptionsHandlerClass.SetUnobservedExceptionHandler(UnhandledException);
                }
                // Ensure SerializationManager static constructor is called before AssemblyLoad event is invoked
                SerializationManager.GetDeserializer(typeof(String));

                clientProviderRuntime = new ClientProviderRuntime(grainFactory, new DefaultServiceProvider());
                statisticsProviderManager = new StatisticsProviderManager("Statistics", clientProviderRuntime);
                var statsProviderName = statisticsProviderManager.LoadProvider(config.ProviderConfigurations)
                    .WaitForResultWithThrow(initTimeout);
                if (statsProviderName != null)
                {
                    config.StatisticsProviderName = statsProviderName;
                }

                responseTimeout = Debugger.IsAttached ? Constants.DEFAULT_RESPONSE_TIMEOUT : config.ResponseTimeout;
                BufferPool.InitGlobalBufferPool(config);
                var localAddress = ClusterConfiguration.GetLocalIPAddress(config.PreferredFamily, config.NetInterface);

                // Client init / sign-on message
                logger.Info(ErrorCode.ClientInitializing, string.Format(
                    "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}",
                    BARS, config.DNSHostName, localAddress, clientId));
                string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}'", BARS, RuntimeVersion.Current);
                startMsg = string.Format("{0} Config= "  + Environment.NewLine + " {1}", startMsg, config);
                logger.Info(ErrorCode.ClientStarting, startMsg);

                if (TestOnlyThrowExceptionDuringInit)
                {
                    throw new Exception("TestOnlyThrowExceptionDuringInit");
                }

                config.CheckGatewayProviderSettings();

                var generation = -SiloAddress.AllocateNewGeneration(); // Client generations are negative
                var gatewayListProvider = GatewayProviderFactory.CreateGatewayListProvider(config)
                    .WithTimeout(initTimeout).Result;
                transport = new ProxiedMessageCenter(config, localAddress, generation, clientId, gatewayListProvider);
                
                if (StatisticsCollector.CollectThreadTimeTrackingStats)
                {
                    incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver");
                }
            }
            catch (Exception exc)
            {
                if (logger != null) logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc);
                ConstructorReset();
                throw;
            }
        }