/// <summary> /// A long-running loop performing pool maintenance. Each iteration runs <see cref="MaintainPool"/>. /// This is a static method to allow the target pool to be garbage collected, at which point the /// method will complete. (This method only retains a week reference to the specified pool.) /// </summary> /// <param name="pool">The pool to maintain.</param> /// <returns>A task which completes when the maintenance loop has finished, due to the session pool being /// garbage collected</returns> private static async Task PoolMaintenanceLoop(SessionPool pool) { // Keep a weak reference so that the pool can be garbage collected and we can stop the // maintenance task. var weakRef = new WeakReference <SessionPool>(pool); // Make sure that even if the pool variable is captured due to compiler implementation details, // it won't prevent garbage collection. pool = null; while (true) { if (!weakRef.TryGetTarget(out var localPool)) { return; } try { localPool.MaintainPool(); } catch (Exception e) { localPool._logger.Error($"Error running {nameof(SessionPool)} maintenance task", e); } var scheduler = localPool._scheduler; var delay = localPool.Options.MaintenanceLoopDelay; // Allow the pool to be collected while we're waiting. localPool = null; await scheduler.Delay(delay, CancellationToken.None).ConfigureAwait(false); } }
internal static bool CheckForSessionExpiredError(this RpcException rpcException, Func <Session> sessionFunc) { if (rpcException.IsSessionExpiredError()) { SessionPool.MarkSessionExpired(sessionFunc()); } return(false); }
internal TargetedSessionPool(SessionPool parent, DatabaseName databaseName, bool acquireSessionsImmediately) : base(parent) { _databaseName = GaxPreconditions.CheckNotNull(databaseName, nameof(databaseName)); _createSessionRequest = new CreateSessionRequest { DatabaseAsDatabaseName = databaseName }; if (acquireSessionsImmediately) { StartAcquisitionTasksIfNecessary(); } }
internal DetachedSessionPool(SessionPool parent) : base(parent) { }
protected SessionPoolBase(SessionPool parent) => Parent = parent;