public ServerMonitor(
            ServerId serverId,
            EndPoint endPoint,
            IConnectionFactory connectionFactory,
            ServerMonitorSettings serverMonitorSettings,
            IEventSubscriber eventSubscriber,
            IRoundTripTimeMonitor roundTripTimeMonitor,
            ServerApi serverApi)
        {
            _monitorCancellationTokenSource = new CancellationTokenSource();
            _serverId          = Ensure.IsNotNull(serverId, nameof(serverId));
            _endPoint          = Ensure.IsNotNull(endPoint, nameof(endPoint));
            _connectionFactory = Ensure.IsNotNull(connectionFactory, nameof(connectionFactory));
            Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));
            _serverMonitorSettings = Ensure.IsNotNull(serverMonitorSettings, nameof(serverMonitorSettings));

            _baseDescription      = _currentDescription = new ServerDescription(_serverId, endPoint, reasonChanged: "InitialDescription", heartbeatInterval: serverMonitorSettings.HeartbeatInterval);
            _roundTripTimeMonitor = Ensure.IsNotNull(roundTripTimeMonitor, nameof(roundTripTimeMonitor));

            _state = new InterlockedInt32(State.Initial);
            eventSubscriber.TryGetEventHandler(out _heartbeatStartedEventHandler);
            eventSubscriber.TryGetEventHandler(out _heartbeatSucceededEventHandler);
            eventSubscriber.TryGetEventHandler(out _heartbeatFailedEventHandler);
            eventSubscriber.TryGetEventHandler(out _sdamInformationEventHandler);
            _serverApi = serverApi;

            _heartbeatCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_monitorCancellationTokenSource.Token);
        }
 public ServerMonitorFactory(
     ServerMonitorSettings serverMonitorSettings,
     IConnectionFactory connectionFactory,
     IEventSubscriber eventSubscriber,
     ServerApi serverApi)
 {
     _serverMonitorSettings = Ensure.IsNotNull(serverMonitorSettings, nameof(serverMonitorSettings));
     _connectionFactory     = Ensure.IsNotNull(connectionFactory, nameof(connectionFactory));
     _eventSubscriber       = Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));
     _serverApi             = serverApi;
 }
 public ServerMonitor(
     ServerId serverId,
     EndPoint endPoint,
     IConnectionFactory connectionFactory,
     ServerMonitorSettings serverMonitorSettings,
     IEventSubscriber eventSubscriber,
     ServerApi serverApi)
     : this(
         serverId,
         endPoint,
         connectionFactory,
         serverMonitorSettings,
         eventSubscriber,
         roundTripTimeMonitor : new RoundTripTimeMonitor(
             connectionFactory,
             serverId,
             endPoint,
             Ensure.IsNotNull(serverMonitorSettings, nameof(serverMonitorSettings)).HeartbeatInterval,
             serverApi),
         serverApi)
 {
 }