using System;
using System.Threading.Tasks;
namespace LaunchDarkly.EventSource
{
///
/// This interface defines the public members of .
///
public interface IEventSource
{
#region Public Events
///
/// Occurs when the connection to the EventSource API has been opened.
///
event EventHandler Opened;
///
/// Occurs when the connection to the EventSource API has been closed.
///
event EventHandler Closed;
///
/// Occurs when a Server Sent Event from the EventSource API has been received.
///
event EventHandler MessageReceived;
///
/// Occurs when a comment has been received from the EventSource API.
///
event EventHandler CommentReceived;
///
/// Occurs when an error has happened when the EventSource is open and processing Server Sent Events.
///
event EventHandler Error;
#endregion Public Events
#region Public Properties
///
/// Gets the state of the EventSource connection.
///
ReadyState ReadyState { get; }
#endregion
#region Public Methods
///
/// Initiates a connection to the SSE server and begins parsing events.
///
/// a that will be completed only when the
/// EventSource is closed
/// if the method was called again after the
/// stream connection was already active
Task StartAsync();
///
/// Triggers the same "close and retry" behavior as if an error had been encountered on the stream.
///
///
///
/// If the stream is currently active, this closes the connection, waits for some amount of time
/// as determined by the usual backoff behavior (and ), and
/// then attempts to reconnect. If the stream is not yet connected, is already waiting to
/// reconnect, or has been permanently shut down, this has no effect.
///
///
/// The method returns immediately without waiting for the reconnection to happen. You will
/// receive and events when it does happen (or an
/// event if the new connection attempt fails).
///
///
/// true if the delay before reconnection should be reset to
/// the lowest level of the currently active bounds, which could be the temporary bounds if
/// is in effect; false if it
/// should increase according to the usual exponential backoff logic
void Restart(bool resetBackoffDelay);
///
/// Temporarily replaces the bounds used to compute reconnection delays.
///
///
///
/// The configured and
/// normally govern the
/// exponential backoff between reconnection attempts. This method installs different
/// bounds at runtime, so a caller can slow reconnection down without reconfiguring or
/// recreating the EventSource.
///
///
/// The bounds are temporary: they remain in effect until either a connection stays
/// open for at least
/// , at which point the
/// configured bounds are restored automatically, or
/// is called.
///
///
/// Changing the bounds resets the backoff level, so the next delay is computed from the new
/// rather than continuing to grow from where it left off.
/// Calling this with bounds that are already in effect does nothing, so it is safe to call
/// repeatedly.
///
///
/// Negative values are changed to zero. If is greater than
/// , delays are limited to . No
/// argument causes this method to throw, and no argument can cause a later reconnect to
/// fail.
///
///
/// A server-directed reconnection time received via the SSE retry: field supersedes
/// , and the configured
/// along with it. Such a
/// value does not affect , so the ceiling set here continues to
/// bound reconnection.
///
///
/// It is safe to call this from any thread, including from an
/// handler.
///
///
/// the lowest delay to use while these bounds are in effect,
/// unless a server-directed retry: value supersedes it
/// the highest delay to use while these bounds are in effect
///
void SetTemporaryRetryDelayBounds(TimeSpan initialDelay, TimeSpan maxDelay);
///
/// Discards any bounds installed by
/// , restoring the configured
/// and, unless a server-directed
/// retry: value is in effect, the configured
/// .
///
///
///
/// Restoring the configured bounds resets the backoff level. If no temporary bounds
/// are in effect this does nothing. The count of reconnection attempts is not reset.
/// Calling this is not required as the configured bounds are also restored automatically
/// after a connection stays open for
/// .
///
///
/// A server-directed reconnection time received via the SSE retry: field is not
/// discarded and continues to supersede
/// , so the configured
/// minimum may not be the one actually in use afterwards. Only a later retry: value
/// replaces it. is unaffected
/// and is always restored.
///
///
///
void ClearTemporaryRetryDelayBounds();
///
/// Closes the connection to the SSE server. The EventSource cannot be reopened after this.
///
void Close();
#endregion
}
}