private ClientSession(ApplicationConfiguration config, ConnectionModel connection, ILogger logger, Func <ConnectionModel, EndpointConnectivityState, Task> statusCb, TimeSpan?maxOpTimeout, string sessionName, TimeSpan?timeout, TimeSpan?keepAlive) { _sessionName = sessionName ?? Guid.NewGuid().ToString(); _logger = (logger ?? Log.Logger).ForContext("SourceContext", new { name = _sessionName, sessionId = Interlocked.Increment(ref _sessionCounter), url = connection.Endpoint.Url }, true); _connection = connection.Clone(); _config = config; _config.CertificateValidator.CertificateValidation += OnValidate; _timeout = timeout ?? TimeSpan.FromMilliseconds( _config.ClientConfiguration.DefaultSessionTimeout); _statusCb = statusCb; _cts = new CancellationTokenSource(); _lastState = EndpointConnectivityState.Connecting; _keepAlive = keepAlive ?? TimeSpan.FromSeconds(5); _lastActivity = DateTime.UtcNow; // Align the default device method timeout _opTimeout = maxOpTimeout ?? TimeSpan.FromMinutes(8); _session = null; _acquired = new TaskCompletionSource <Session>(); _urlQueue = new ConcurrentQueue <string>(_connection.Endpoint.GetAllUrls()); _queue = new PriorityQueue <int, SessionOperation>(); _enqueueEvent = new TaskCompletionSource <bool>( TaskContinuationOptions.RunContinuationsAsynchronously); #pragma warning disable RECS0002 // Convert anonymous method to method group _processor = Task.Factory.StartNew(() => RunAsync(), _cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default).Unwrap(); #pragma warning restore RECS0002 // Convert anonymous method to method group _logger.Information("Session created."); }
/// <summary> /// Create new key /// </summary> /// <param name="connection"></param> public ConnectionIdentifier(ConnectionModel connection) { Connection = connection?.Clone() ?? throw new ArgumentNullException(nameof(connection)); _hash = Connection.CreateConsistentHash(); }