예제 #1
0
        private Cluster() 
        {
            Scheduler = new WatchdogScheduler(
                new EventLoopScheduler(ts =>
                {
                    var thread = new Thread(ts) { Name = "kafka-scheduler " + _id, IsBackground = true };
                    CurrentWorkerThread = thread;
                    _log.Debug("Created new thread '{0}'", thread.Name);
                    return thread;
                }));

            // Init synchronization context of scheduler thread
            Scheduler.Schedule(() => SynchronizationContext.SetSynchronizationContext(new RxSyncContextFromScheduler(Scheduler)));

            var hangTimeout = TimeSpan.FromMinutes(1);
            Scheduler.DelaySampler.Where(_ => _ > hangTimeout).
                FirstOrDefaultAsync().
                Subscribe(_ =>
                {
                    var thread = CurrentWorkerThread;
                    if (thread != null)
                    {
                        var msg = string.Format("Driver handler thread is stuck for {0} (>{1}ms). Aborting!", _, hangTimeout);
                        _log.Fatal(msg);
                        thread.Abort();
                        if (OnThreadHang != null)
                            OnThreadHang(new WorkingThreadHungException(msg));
                    }
                });


            // build a subject that relays any changes to a partition's error state to anyone observing.
            BuildPartitionStateChangeSubject();
            _newBrokerSubject = BuildnewBrokersSubject();
        }
예제 #2
0
        private Cluster()
        {
            Scheduler = new WatchdogScheduler(
                new EventLoopScheduler(ts =>
            {
                var thread = new Thread(ts)
                {
                    Name = "kafka-scheduler " + _id, IsBackground = true
                };
                CurrentWorkerThread = thread;
                _log.Debug("Created new thread '{0}'", thread.Name);
                return(thread);
            }));

            // Init synchronization context of scheduler thread
            Scheduler.Schedule(() => SynchronizationContext.SetSynchronizationContext(new RxSyncContextFromScheduler(Scheduler)));

            var hangTimeout = TimeSpan.FromMinutes(1);

            _watchdogSubscription = Scheduler.DelaySampler.Where(_ => _ > hangTimeout).
                                    FirstOrDefaultAsync().
                                    Subscribe(_ =>
            {
                var thread = CurrentWorkerThread;
                if (thread != null)
                {
                    var msg = string.Format("Driver handler thread is stuck for {0} (>{1}ms). Aborting!", _, hangTimeout);
                    _log.Fatal(msg);
                    thread.Abort();
                    if (OnThreadHang != null)
                    {
                        OnThreadHang(new WorkingThreadHungException(msg));
                    }
                }
            });


            // build a subject that relays any changes to a partition's error state to anyone observing.
            BuildPartitionStateChangeSubject();
            _newBrokerSubject = BuildnewBrokersSubject();
        }