/// <summary> /// Initializes a new instance of the <see cref="CommunicationEntryPoint"/> class. /// </summary> /// <param name="endpointStorage">The collection that stores information about all known endpoints.</param> /// <param name="commands">The collection that stores information about all the known remote commands.</param> /// <param name="notifications">The collection that stores information about all the known remote notifications.</param> /// <param name="verifyConnectionTo">The function that is used to verify connections to remote endpoints.</param> /// <param name="configuration">The object that stores the configuration for the application.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="endpointStorage"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="commands"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="notifications"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="verifyConnectionTo"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="configuration"/> is <see langword="null" />. /// </exception> public CommunicationEntryPoint( IStoreInformationAboutEndpoints endpointStorage, ISendCommandsToRemoteEndpoints commands, INotifyOfRemoteEndpointEvents notifications, VerifyEndpointConnectionStatus verifyConnectionTo, IConfiguration configuration) { { Lokad.Enforce.Argument(() => endpointStorage); Lokad.Enforce.Argument(() => commands); Lokad.Enforce.Argument(() => notifications); Lokad.Enforce.Argument(() => verifyConnectionTo); } m_MessageSendTimeout = configuration.HasValueFor(CommunicationConfigurationKeys.WaitForResponseTimeoutInMilliSeconds) ? TimeSpan.FromMilliseconds(configuration.Value <int>(CommunicationConfigurationKeys.WaitForResponseTimeoutInMilliSeconds)) : TimeSpan.FromMilliseconds(CommunicationConstants.DefaultWaitForResponseTimeoutInMilliSeconds); m_EndpointStorage = endpointStorage; m_EndpointStorage.OnEndpointConnected += HandleOnEndpointConnected; m_EndpointStorage.OnEndpointDisconnected += HandleOnEndpointDisconnected; m_Commands = commands; m_Commands.OnEndpointConnected += HandleOnEndpointConnected; m_Commands.OnEndpointDisconnected += HandleOnEndpointDisconnected; m_Notifications = notifications; m_Notifications.OnEndpointConnected += HandleOnEndpointConnected; m_Notifications.OnEndpointDisconnected += HandleOnEndpointDisconnected; m_VerifyConnectionTo = verifyConnectionTo; }
/// <summary> /// Initializes a new instance of the <see cref="InteractionHandshakeConductor"/> class. /// </summary> /// <param name="localEndpoint">The endpoint ID of the local endpoint.</param> /// <param name="endpointInformationStorage">The object that stores information about the known endpoints.</param> /// <param name="interactionSubjects">The collection that contains all the registered subjects and their commands and notifications.</param> /// <param name="commandProxyHub">The object that stores the command proxy objects.</param> /// <param name="notificationProxyHub">The object that stores the notification proxy objects.</param> /// <param name="sendMessage">The action that is used to send a message to a remote endpoint.</param> /// <param name="sendMessageAndWaitForResponse"> /// The function that sends out a message to the given endpoint and returns a task that will, eventually, hold the return message. /// </param> /// <param name="sendTimeout">The maximum amount of time the instance will wait for a response message to be returned.</param> /// <param name="diagnostics">The object that provides the diagnostics methods for the application.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="localEndpoint"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="endpointInformationStorage"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="interactionSubjects"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="commandProxyHub"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="notificationProxyHub"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="sendMessage"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="sendMessageAndWaitForResponse"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="diagnostics"/> is <see langword="null" />. /// </exception> public InteractionHandshakeConductor( EndpointId localEndpoint, IStoreInformationAboutEndpoints endpointInformationStorage, IStoreInteractionSubjects interactionSubjects, IStoreRemoteCommandProxies commandProxyHub, IStoreRemoteNotificationProxies notificationProxyHub, SendMessage sendMessage, SendMessageAndWaitForResponse sendMessageAndWaitForResponse, TimeSpan sendTimeout, SystemDiagnostics diagnostics) { { Lokad.Enforce.Argument(() => localEndpoint); Lokad.Enforce.Argument(() => endpointInformationStorage); Lokad.Enforce.Argument(() => interactionSubjects); Lokad.Enforce.Argument(() => commandProxyHub); Lokad.Enforce.Argument(() => notificationProxyHub); Lokad.Enforce.Argument(() => sendMessage); Lokad.Enforce.Argument(() => sendMessageAndWaitForResponse); Lokad.Enforce.Argument(() => diagnostics); } m_Current = localEndpoint; m_EndpointInformationStorage = endpointInformationStorage; m_EndpointInformationStorage.OnEndpointConnected += HandleEndpointSignIn; m_InteractionSubjects = interactionSubjects; m_CommandProxyHub = commandProxyHub; m_NotificationProxyHub = notificationProxyHub; m_SendMessage = sendMessage; m_SendMessageAndWaitForResponse = sendMessageAndWaitForResponse; m_Diagnostics = diagnostics; m_SendTimeout = sendTimeout; }
/// <summary> /// Initializes a new instance of the <see cref="MessageHandler"/> class. /// </summary> /// <param name="endpoints"> /// The object that stores the endpoint information for all the endpoints that we are permitted to /// communicate with. /// </param> /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param> /// <param name="scheduler">The object used for scheduling reactive extension tasks.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="endpoints"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />. /// </exception> public MessageHandler(IStoreInformationAboutEndpoints endpoints, SystemDiagnostics systemDiagnostics, IScheduler scheduler = null) { { Lokad.Enforce.Argument(() => endpoints); Lokad.Enforce.Argument(() => systemDiagnostics); } m_Endpoints = endpoints; m_Diagnostics = systemDiagnostics; m_Scheduler = scheduler ?? Scheduler.Default; }
/// <summary> /// Initializes a new instance of the <see cref="EndpointDisconnectProcessAction"/> class. /// </summary> /// <param name="endpointStorage">The object that stores information about all the known endpoints.</param> /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="endpointStorage"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />. /// </exception> public EndpointDisconnectProcessAction( IStoreInformationAboutEndpoints endpointStorage, SystemDiagnostics systemDiagnostics) { { Lokad.Enforce.Argument(() => endpointStorage); Lokad.Enforce.Argument(() => systemDiagnostics); } m_EndpointStorage = endpointStorage; m_Diagnostics = systemDiagnostics; }
/// <summary> /// Initializes a new instance of the <see cref="RemoteCommandHub"/> class. /// </summary> /// <param name="endpointInformationStorage">The object that provides notification of the signing in and signing out of endpoints.</param> /// <param name="builder">The object that is responsible for building the command proxies.</param> /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="endpointInformationStorage"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="builder"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />. /// </exception> internal RemoteCommandHub( IStoreInformationAboutEndpoints endpointInformationStorage, CommandProxyBuilder builder, SystemDiagnostics systemDiagnostics) : base( endpointInformationStorage, (endpoint, type) => (CommandSetProxy)builder.ProxyConnectingTo(endpoint, type), systemDiagnostics) { { Lokad.Enforce.Argument(() => builder); } }
/// <summary> /// Initializes a new instance of the <see cref="RemoteEndpointProxyHub{TProxyObject}"/> class. /// </summary> /// <param name="endpointInformationStorage">The object that provides notification of the signing in and signing out of endpoints.</param> /// <param name="builder">The function that is responsible for building the proxies.</param> /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="endpointInformationStorage"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="builder"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />. /// </exception> protected RemoteEndpointProxyHub( IStoreInformationAboutEndpoints endpointInformationStorage, Func <EndpointId, Type, TProxyObject> builder, SystemDiagnostics systemDiagnostics) { { Lokad.Enforce.Argument(() => endpointInformationStorage); Lokad.Enforce.Argument(() => builder); Lokad.Enforce.Argument(() => systemDiagnostics); } m_EndpointInformationStorage = endpointInformationStorage; m_EndpointInformationStorage.OnEndpointDisconnected += HandleEndpointSignOut; m_Builder = builder; m_Diagnostics = systemDiagnostics; }
/// <summary> /// Initializes a new instance of the <see cref="ConnectionMonitor"/> class. /// </summary> /// <param name="endpoints">The collection that contains all the known endpoints.</param> /// <param name="verifyConnectionTo">The function that is used to verify connections with remote endpoints.</param> /// <param name="timer">The timer which is used to signal the next keep-alive moment.</param> /// <param name="now">The function that is used to get the current time and date.</param> /// <param name="configuration">The object that stores the configuration for the application.</param> /// <param name="keepAliveCustomDataBuilder">The function that is used to provide custom data for the connect message.</param> /// <param name="keepAliveResponseDataHandler">The function that is used to return the custom data from a response connect message.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="endpoints"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="verifyConnectionTo"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="timer"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="now"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="configuration"/> is <see langword="null" />. /// </exception> public ConnectionMonitor( IStoreInformationAboutEndpoints endpoints, VerifyEndpointConnectionStatusWithCustomData verifyConnectionTo, ITimer timer, Func <DateTimeOffset> now, IConfiguration configuration, KeepAliveCustomDataBuilder keepAliveCustomDataBuilder = null, KeepAliveResponseDataHandler keepAliveResponseDataHandler = null) { { Lokad.Enforce.Argument(() => endpoints); Lokad.Enforce.Argument(() => verifyConnectionTo); Lokad.Enforce.Argument(() => timer); Lokad.Enforce.Argument(() => now); Lokad.Enforce.Argument(() => configuration); } m_VerifyConnectionTo = verifyConnectionTo; m_Now = now; m_KeepAliveCustomDataBuilder = keepAliveCustomDataBuilder; m_KeepAliveResponseDataHandler = keepAliveResponseDataHandler; m_MaximumNumberOfMissedKeepAliveSignals = configuration.HasValueFor( CommunicationConfigurationKeys.MaximumNumberOfMissedConnectionConfirmations) ? configuration.Value <int>(CommunicationConfigurationKeys.MaximumNumberOfMissedConnectionConfirmations) : CommunicationConstants.DefaultMaximumNumberOfMissedKeepAliveSignals; m_MaximumTimeBetweenConnectionConfirmations = configuration.HasValueFor( CommunicationConfigurationKeys.MaximumTimeInMillisecondsBetweenConnectionConfirmations) ? TimeSpan.FromMilliseconds( configuration.Value <int>(CommunicationConfigurationKeys.MaximumTimeInMillisecondsBetweenConnectionConfirmations)) : TimeSpan.FromMilliseconds(CommunicationConstants.DefaultMaximumTimeInMillisecondsBetweenConnectionConfirmations); m_MessageSendTimeout = configuration.HasValueFor(CommunicationConfigurationKeys.WaitForResponseTimeoutInMilliSeconds) ? TimeSpan.FromMilliseconds(configuration.Value <int>(CommunicationConfigurationKeys.WaitForResponseTimeoutInMilliSeconds)) : TimeSpan.FromMilliseconds(CommunicationConstants.DefaultWaitForResponseTimeoutInMilliSeconds); m_Endpoints = endpoints; m_Endpoints.OnEndpointConnected += HandleOnEndpointConnected; m_Endpoints.OnEndpointDisconnected += HandleOnEndpointDisconnected; m_Timer = timer; m_Timer.OnElapsed += HandleKeepAliveIntervalOnElapsed; }
/// <summary> /// Initializes a new instance of the <see cref="ProtocolLayer"/> class. /// </summary> /// <param name="endpoints">The collection that contains all the potential endpoints.</param> /// <param name="channelBuilder"> /// The function that returns a tuple of a <see cref="IProtocolChannel"/> and a <see cref="IDirectIncomingMessages"/> /// based on the type of the <see cref="IChannelTemplate"/> that is related to the channel. /// </param> /// <param name="channelTypesToUse">The collection that contains all the channel types for which a channel should be opened.</param> /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="endpoints"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="channelBuilder"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="channelTypesToUse"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />. /// </exception> public ProtocolLayer( IStoreInformationAboutEndpoints endpoints, Func <ChannelTemplate, EndpointId, Tuple <IProtocolChannel, IDirectIncomingMessages> > channelBuilder, IEnumerable <ChannelTemplate> channelTypesToUse, SystemDiagnostics systemDiagnostics) { { Lokad.Enforce.Argument(() => endpoints); Lokad.Enforce.Argument(() => channelBuilder); Lokad.Enforce.Argument(() => channelTypesToUse); Lokad.Enforce.Argument(() => systemDiagnostics); } m_Endpoints = endpoints; m_ChannelBuilder = channelBuilder; m_ChannelTypesToUse = channelTypesToUse; m_Diagnostics = systemDiagnostics; m_Endpoints.OnEndpointDisconnecting += HandleEndpointDisconnecting; }