/// <summary>
        /// Initializes a new instance of the <see cref="HeartBeatWorker" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="context">The context.</param>
        /// <param name="sendHeartBeat">The send heart beat.</param>
        /// <param name="threadPool">The thread pool.</param>
        /// <param name="log">The log.</param>
        /// <param name="heartBeatNotificationFactory">The heart beat notification factory.</param>
        public HeartBeatWorker(IHeartBeatConfiguration configuration, 
            IMessageContext context,
            ISendHeartBeat sendHeartBeat,
            IHeartBeatThreadPool threadPool,
            ILogFactory log,
            IWorkerHeartBeatNotificationFactory heartBeatNotificationFactory)
        {
            Guard.NotNull(() => configuration, configuration);
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => sendHeartBeat, sendHeartBeat);
            Guard.NotNull(() => threadPool, threadPool);
            Guard.NotNull(() => log, log);
            Guard.NotNull(() => heartBeatNotificationFactory, heartBeatNotificationFactory);

            _context = context;
            _checkTimespan = configuration.CheckTime;
            _sendHeartbeat = sendHeartBeat;
            _smartThreadPool = threadPool;
            _logger = log.Create();

            _runningLock = new ReaderWriterLockSlim();
            _stoppedLock = new ReaderWriterLockSlim();

            _cancel = new CancellationTokenSource();
            context.WorkerNotification.HeartBeat = heartBeatNotificationFactory.Create(_cancel.Token);
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SendHeartBeatPolicyDecorator" /> class.
 /// </summary>
 /// <param name="handler">The handler.</param>
 /// <param name="policies">The policies.</param>
 public SendHeartBeatPolicyDecorator(
     ISendHeartBeat handler,
     IPolicies policies)
 {
     _policies = policies;
     _handler  = handler;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SendHeartBeatDecorator" /> class.
 /// </summary>
 /// <param name="metrics">The metrics factory.</param>
 /// <param name="handler">The handler.</param>
 /// <param name="connectionInformation">The connection information.</param>
 public SendHeartBeatDecorator(IMetrics metrics,
     ISendHeartBeat handler,
     IConnectionInformation connectionInformation)
 {
     var name = handler.GetType().Name;
     _timer = metrics.Timer($"{connectionInformation.QueueName}.{name}.SendTimer", Units.Calls);
     _handler = handler;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SendHeartBeatDecorator" /> class.
        /// </summary>
        /// <param name="metrics">The metrics factory.</param>
        /// <param name="handler">The handler.</param>
        /// <param name="connectionInformation">The connection information.</param>
        public SendHeartBeatDecorator(IMetrics metrics,
                                      ISendHeartBeat handler,
                                      IConnectionInformation connectionInformation)
        {
            var name = "SendHeartBeat";

            _timer   = metrics.Timer($"{connectionInformation.QueueName}.{name}.SendTimer", Units.Calls);
            _handler = handler;
        }
Exemple #5
0
        public HeartBeat(ISendHeartBeat sendHeartBeat)
        {
            m_sendHeartBeat = sendHeartBeat;

            // Create a timer with a two second interval.
            m_timer = new Timer(GlobalDefine.HeartBeatInterval);
            // Hook up the Elapsed event for the timer.
            m_timer.Elapsed  += OnTimedEvent;
            m_timer.AutoReset = true;
            m_timer.Enabled   = true;
            m_sendHeartBeat.Send();
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HeartBeatWorkerFactory" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="sendHeartBeat">The send heart beat module.</param>
        /// <param name="scheduler">The scheduler.</param>
        /// <param name="logFactory">The log factory.</param>
        /// <param name="heartBeatNotificationFactory">The heart beat notification factory.</param>
        public HeartBeatWorkerFactory(IHeartBeatConfiguration configuration,
                                      ISendHeartBeat sendHeartBeat,
                                      IHeartBeatScheduler scheduler,
                                      ILogFactory logFactory,
                                      IWorkerHeartBeatNotificationFactory heartBeatNotificationFactory)
        {
            Guard.NotNull(() => configuration, configuration);
            Guard.NotNull(() => sendHeartBeat, sendHeartBeat);
            Guard.NotNull(() => scheduler, scheduler);
            Guard.NotNull(() => logFactory, logFactory);
            Guard.NotNull(() => heartBeatNotificationFactory, heartBeatNotificationFactory);

            _configuration = configuration;
            _sendHeartBeat = sendHeartBeat;
            _scheduler     = scheduler;
            _logFactory    = logFactory;
            _heartBeatNotificationFactory = heartBeatNotificationFactory;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HeartBeatWorkerFactory" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="sendHeartBeat">The send heart beat module.</param>
        /// <param name="threadPool">The thread pool.</param>
        /// <param name="logFactory">The log factory.</param>
        /// <param name="heartBeatNotificationFactory">The heart beat notification factory.</param>
        public HeartBeatWorkerFactory(IHeartBeatConfiguration configuration,
            ISendHeartBeat sendHeartBeat,
            IHeartBeatThreadPoolFactory threadPool,
            ILogFactory logFactory,
            IWorkerHeartBeatNotificationFactory heartBeatNotificationFactory)
        {
            Guard.NotNull(() => configuration, configuration);
            Guard.NotNull(() => sendHeartBeat, sendHeartBeat);
            Guard.NotNull(() => threadPool, threadPool);
            Guard.NotNull(() => logFactory, logFactory);
            Guard.NotNull(() => heartBeatNotificationFactory, heartBeatNotificationFactory);

            _configuration = configuration;
            _sendHeartBeat = sendHeartBeat;
            _threadPool = threadPool;
            _logFactory = logFactory;
            _heartBeatNotificationFactory = heartBeatNotificationFactory;
        }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HeartBeatWorker" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="context">The context.</param>
        /// <param name="sendHeartBeat">The send heart beat.</param>
        /// <param name="scheduler">The scheduler.</param>
        /// <param name="log">The log.</param>
        /// <param name="heartBeatNotificationFactory">The heart beat notification factory.</param>
        public HeartBeatWorker(IHeartBeatConfiguration configuration,
                               IMessageContext context,
                               ISendHeartBeat sendHeartBeat,
                               IHeartBeatScheduler scheduler,
                               ILogFactory log,
                               IWorkerHeartBeatNotificationFactory heartBeatNotificationFactory)
        {
            Guard.NotNull(() => configuration, configuration);
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => sendHeartBeat, sendHeartBeat);
            Guard.NotNull(() => scheduler, scheduler);
            Guard.NotNull(() => log, log);
            Guard.NotNull(() => heartBeatNotificationFactory, heartBeatNotificationFactory);

            _context       = context;
            _checkTime     = configuration.UpdateTime;
            _sendHeartbeat = sendHeartBeat;
            _scheduler     = scheduler;
            _logger        = log.Create();

            _cancel = new CancellationTokenSource();
            context.WorkerNotification.HeartBeat = heartBeatNotificationFactory.Create(_cancel.Token);
        }
        private HeartBeatWorker Create(TimeSpan checkSpan, string updateTime, IMessageContext context, ISendHeartBeat sendHeartBeat)
        {
            var fixture = new Fixture().Customize(new AutoNSubstituteCustomization());

            fixture.Inject(context);
            fixture.Inject(sendHeartBeat);
            var threadPoolConfiguration = fixture.Create <IHeartBeatThreadPoolConfiguration>();

            threadPoolConfiguration.ThreadsMax.Returns(1);
            fixture.Inject(threadPoolConfiguration);
            IHeartBeatConfiguration configuration = fixture.Create <HeartBeatConfiguration>();

            configuration.Time       = checkSpan;
            configuration.UpdateTime = updateTime;
            fixture.Inject(configuration);
            var threadpool = fixture.Create <IHeartBeatScheduler>();

            fixture.Inject(threadpool);
            return(fixture.Create <HeartBeatWorker>());
        }
 private HeartBeatWorker Create(TimeSpan checkSpan, int interval, IMessageContext context, ISendHeartBeat sendHeartBeat, bool useThreadPool)
 {
     var fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
     fixture.Inject(context);
     fixture.Inject(sendHeartBeat);
     var threadPoolConfiguration = fixture.Create<IHeartBeatThreadPoolConfiguration>();
     threadPoolConfiguration.ThreadsMax.Returns(1);
     threadPoolConfiguration.ThreadsMin.Returns(1);
     fixture.Inject(threadPoolConfiguration);
     IHeartBeatConfiguration configuration = fixture.Create<HeartBeatConfiguration>();
     configuration.Time = checkSpan;
     configuration.Interval = interval;
     fixture.Inject(configuration);
     IHeartBeatThreadPool threadpool;
     if (!useThreadPool)
     {
         threadpool = fixture.Create<IHeartBeatThreadPool>();
     }
     else
     {
         threadpool = fixture.Create<HeartBeatThreadPool>();
         threadpool.Start();
     }
     fixture.Inject(threadpool);
     return fixture.Create<HeartBeatWorker>();
 }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SendHeartBeatDecorator"/> class.
 /// </summary>
 /// <param name="handler">The handler.</param>
 /// <param name="tracer">The tracer.</param>
 /// <param name="headers">The headers.</param>
 public SendHeartBeatDecorator(ISendHeartBeat handler, ITracer tracer, IStandardHeaders headers)
 {
     _handler = handler;
     _tracer  = tracer;
     _headers = headers;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SendHeartBeatDecorator"/> class.
 /// </summary>
 /// <param name="handler">The handler.</param>
 /// <param name="tracer">The tracer.</param>
 /// <param name="headers">The headers.</param>
 public SendHeartBeatDecorator(ISendHeartBeat handler, ActivitySource tracer, IStandardHeaders headers)
 {
     _handler = handler;
     _tracer  = tracer;
     _headers = headers;
 }