From 8956f6ff4a44284957623310bc48be558ecd529f Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Tue, 26 Feb 2013 16:40:05 -0500 Subject: Move ResourcePool to common --- MediaBrowser.Common/Kernel/ResourcePool.cs | 79 ++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 MediaBrowser.Common/Kernel/ResourcePool.cs (limited to 'MediaBrowser.Common/Kernel/ResourcePool.cs') diff --git a/MediaBrowser.Common/Kernel/ResourcePool.cs b/MediaBrowser.Common/Kernel/ResourcePool.cs new file mode 100644 index 000000000..8a2ab8af8 --- /dev/null +++ b/MediaBrowser.Common/Kernel/ResourcePool.cs @@ -0,0 +1,79 @@ +using System; +using System.Threading; + +namespace MediaBrowser.Common.Kernel +{ + /// + /// This is just a collection of semaphores to control the number of concurrent executions of various resources + /// + public class ResourcePool : IDisposable + { + /// + /// You tube + /// + public readonly SemaphoreSlim YouTube = new SemaphoreSlim(5, 5); + + /// + /// The trakt + /// + public readonly SemaphoreSlim Trakt = new SemaphoreSlim(5, 5); + + /// + /// The tv db + /// + public readonly SemaphoreSlim TvDb = new SemaphoreSlim(5, 5); + + /// + /// The movie db + /// + public readonly SemaphoreSlim MovieDb = new SemaphoreSlim(5, 5); + + /// + /// The fan art + /// + public readonly SemaphoreSlim FanArt = new SemaphoreSlim(5, 5); + + /// + /// The mb + /// + public readonly SemaphoreSlim Mb = new SemaphoreSlim(5, 5); + + /// + /// Apple doesn't seem to like too many simulataneous requests. + /// + public readonly SemaphoreSlim AppleTrailerVideos = new SemaphoreSlim(1, 1); + + /// + /// The apple trailer images + /// + public readonly SemaphoreSlim AppleTrailerImages = new SemaphoreSlim(1, 1); + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool dispose) + { + if (dispose) + { + YouTube.Dispose(); + Trakt.Dispose(); + TvDb.Dispose(); + MovieDb.Dispose(); + FanArt.Dispose(); + Mb.Dispose(); + AppleTrailerVideos.Dispose(); + AppleTrailerImages.Dispose(); + } + } + } +} -- cgit v1.2.3