aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Data/ConnectionPool.cs
diff options
context:
space:
mode:
authorNick <20588554+nicknsy@users.noreply.github.com>2023-10-18 19:27:05 -0700
committerNick <20588554+nicknsy@users.noreply.github.com>2023-10-18 19:27:05 -0700
commitcd662506a1f63f9b20e7f5caa9b671eb3d71ea5a (patch)
treeb58f7158e21e7ed21d77b0f0abfce23d796b3fe3 /Emby.Server.Implementations/Data/ConnectionPool.cs
parentc7feea27fde8af60984c8fe41444dc245dbde395 (diff)
parentde08d38a6f2a6e773fa1000574e08322605b56d3 (diff)
Merge branch 'master' into trickplay
Diffstat (limited to 'Emby.Server.Implementations/Data/ConnectionPool.cs')
-rw-r--r--Emby.Server.Implementations/Data/ConnectionPool.cs79
1 files changed, 0 insertions, 79 deletions
diff --git a/Emby.Server.Implementations/Data/ConnectionPool.cs b/Emby.Server.Implementations/Data/ConnectionPool.cs
deleted file mode 100644
index 5ea7e934f..000000000
--- a/Emby.Server.Implementations/Data/ConnectionPool.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-using System;
-using System.Collections.Concurrent;
-using SQLitePCL.pretty;
-
-namespace Emby.Server.Implementations.Data;
-
-/// <summary>
-/// A pool of SQLite Database connections.
-/// </summary>
-public sealed class ConnectionPool : IDisposable
-{
- private readonly BlockingCollection<SQLiteDatabaseConnection> _connections = new();
- private bool _disposed;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ConnectionPool" /> class.
- /// </summary>
- /// <param name="count">The number of database connection to create.</param>
- /// <param name="factory">Factory function to create the database connections.</param>
- public ConnectionPool(int count, Func<SQLiteDatabaseConnection> factory)
- {
- for (int i = 0; i < count; i++)
- {
- _connections.Add(factory.Invoke());
- }
- }
-
- /// <summary>
- /// Gets a database connection from the pool if one is available, otherwise blocks.
- /// </summary>
- /// <returns>A database connection.</returns>
- public ManagedConnection GetConnection()
- {
- if (_disposed)
- {
- ThrowObjectDisposedException();
- }
-
- return new ManagedConnection(_connections.Take(), this);
-
- static void ThrowObjectDisposedException()
- {
- throw new ObjectDisposedException(nameof(ConnectionPool));
- }
- }
-
- /// <summary>
- /// Return a database connection to the pool.
- /// </summary>
- /// <param name="connection">The database connection to return.</param>
- public void Return(SQLiteDatabaseConnection connection)
- {
- if (_disposed)
- {
- connection.Dispose();
- return;
- }
-
- _connections.Add(connection);
- }
-
- /// <inheritdoc />
- public void Dispose()
- {
- if (_disposed)
- {
- return;
- }
-
- foreach (var connection in _connections)
- {
- connection.Dispose();
- }
-
- _connections.Dispose();
-
- _disposed = true;
- }
-}