-
-
Notifications
You must be signed in to change notification settings - Fork 911
/
ContentStreamingService.cs
78 lines (70 loc) · 2.41 KB
/
ContentStreamingService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
#pragma warning disable SA1405 // Debug.Assert must provide message text
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Stride.Core.Extensions;
namespace Stride.Core.Streaming
{
/// <summary>
/// Streamable resources content management service.
/// </summary>
public class ContentStreamingService : IDisposable
{
private readonly Dictionary<string, ContentStorage> containers = new Dictionary<string, ContentStorage>();
/// <summary>
/// The unused data chunks lifetime.
/// </summary>
public TimeSpan UnusedDataChunksLifetime = TimeSpan.FromSeconds(3);
/// <summary>
/// Gets the storage container.
/// </summary>
/// <param name="storageHeader">The storage header.</param>
/// <returns>Content Storage container.</returns>
public ContentStorage GetStorage(ref ContentStorageHeader storageHeader)
{
ContentStorage result;
lock (containers)
{
if (!containers.TryGetValue(storageHeader.DataUrl, out result))
{
result = new ContentStorage(this);
containers.Add(storageHeader.DataUrl, result);
}
result.Init(ref storageHeader);
}
Debug.Assert(result != null && result.Url == storageHeader.DataUrl);
return result;
}
/// <summary>
/// Updates this service.
/// </summary>
public void Update()
{
lock (containers)
{
foreach (var e in containers)
e.Value.ReleaseUnusedChunks();
}
}
/// <summary>
/// Performs resources disposing.
/// </summary>
public void Dispose()
{
lock (containers)
{
containers.ForEach(x => x.Value.ReleaseChunks());
containers.Clear();
}
}
internal void UnregisterStorage(ContentStorage storage)
{
lock (containers)
{
containers.Remove(storage.Url);
}
}
}
}