|
| 1 | +using System; |
| 2 | +using System.Threading.Tasks; |
| 3 | + |
| 4 | +namespace NetMQ.Monitoring |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// NetMQMonitor interface, implement to fake the NetMQMonitor in tests. |
| 8 | + /// </summary> |
| 9 | + public interface INetMQMonitor : IDisposable |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// The monitoring address. |
| 13 | + /// </summary> |
| 14 | + string Endpoint { get; } |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// Get whether this monitor is currently running. |
| 18 | + /// </summary> |
| 19 | + /// <remarks> |
| 20 | + /// Start the monitor running via either <see cref="Start"/> or <see cref="AttachToPoller{T}"/>. |
| 21 | + /// Stop the monitor via either <see cref="Stop"/> or <see cref="DetachFromPoller()"/>. |
| 22 | + /// </remarks> |
| 23 | + bool IsRunning { get; } |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Gets and sets the timeout interval for poll iterations when using <see cref="Start"/> and <see cref="Stop"/>. |
| 27 | + /// </summary> |
| 28 | + /// <remarks> |
| 29 | + /// The higher the number the longer it may take the to stop the monitor. |
| 30 | + /// This value has no effect when the monitor is run via <see cref="AttachToPoller{T}"/>. |
| 31 | + /// </remarks> |
| 32 | + TimeSpan Timeout { get; set; } |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Raised whenever any monitored event fires. |
| 36 | + /// </summary> |
| 37 | + event EventHandler<NetMQMonitorEventArgs>? EventReceived; |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Occurs when a connection is made to a socket. |
| 41 | + /// </summary> |
| 42 | + event EventHandler<NetMQMonitorSocketEventArgs>? Connected; |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Occurs when a synchronous connection attempt failed, and its completion is being polled for. |
| 46 | + /// </summary> |
| 47 | + event EventHandler<NetMQMonitorErrorEventArgs>? ConnectDelayed; |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Occurs when an asynchronous connect / reconnection attempt is being handled by a reconnect timer. |
| 51 | + /// </summary> |
| 52 | + event EventHandler<NetMQMonitorIntervalEventArgs>? ConnectRetried; |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Occurs when a socket is bound to an address and is ready to accept connections. |
| 56 | + /// </summary> |
| 57 | + event EventHandler<NetMQMonitorSocketEventArgs>? Listening; |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Occurs when a socket could not bind to an address. |
| 61 | + /// </summary> |
| 62 | + event EventHandler<NetMQMonitorErrorEventArgs>? BindFailed; |
| 63 | + |
| 64 | + /// <summary> |
| 65 | + /// Occurs when a connection from a remote peer has been established with a socket's listen address. |
| 66 | + /// </summary> |
| 67 | + event EventHandler<NetMQMonitorSocketEventArgs>? Accepted; |
| 68 | + |
| 69 | + /// <summary> |
| 70 | + /// Occurs when a connection attempt to a socket's bound address fails. |
| 71 | + /// </summary> |
| 72 | + event EventHandler<NetMQMonitorErrorEventArgs>? AcceptFailed; |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Occurs when a connection was closed. |
| 76 | + /// </summary> |
| 77 | + event EventHandler<NetMQMonitorSocketEventArgs>? Closed; |
| 78 | + |
| 79 | + /// <summary> |
| 80 | + /// Occurs when a connection couldn't be closed. |
| 81 | + /// </summary> |
| 82 | + event EventHandler<NetMQMonitorErrorEventArgs>? CloseFailed; |
| 83 | + |
| 84 | + /// <summary> |
| 85 | + /// Occurs when the stream engine (TCP and IPC specific) detects a corrupted / broken session. |
| 86 | + /// </summary> |
| 87 | + event EventHandler<NetMQMonitorSocketEventArgs>? Disconnected; |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// Add the monitor object to a NetMQPoller, register to <see cref="EventReceived"/> to be signalled on new events |
| 91 | + /// </summary> |
| 92 | + /// <param name="poller"></param> |
| 93 | + /// <typeparam name="T"></typeparam> |
| 94 | + /// <exception cref="ArgumentNullException"></exception> |
| 95 | + /// <exception cref="InvalidOperationException"></exception> |
| 96 | + void AttachToPoller<T>(T poller) where T : INetMQPoller; |
| 97 | + |
| 98 | + /// <summary> |
| 99 | + /// Remove the monitor object from attached poller |
| 100 | + /// </summary> |
| 101 | + void DetachFromPoller(); |
| 102 | + |
| 103 | + /// <summary> |
| 104 | + /// Start monitor the socket, the method doesn't start a new thread and will block until the monitor poll is stopped |
| 105 | + /// </summary> |
| 106 | + /// <exception cref="InvalidOperationException">The Monitor must not have already started nor attached to a poller.</exception> |
| 107 | + void Start(); |
| 108 | + |
| 109 | + /// <summary> |
| 110 | + /// Start a background task for the monitoring operation. |
| 111 | + /// </summary> |
| 112 | + /// <returns></returns> |
| 113 | + Task StartAsync(); |
| 114 | + |
| 115 | + /// <summary> |
| 116 | + /// Stop monitoring. Blocks until monitoring completed. |
| 117 | + /// </summary> |
| 118 | + /// <exception cref="InvalidOperationException">If this monitor is attached to a poller you must detach it first and not use the stop method.</exception> |
| 119 | + void Stop(); |
| 120 | + } |
| 121 | +} |
0 commit comments