tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
SwappableDmbProvider.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
7
9{
14 {
18 public const string LiveGameDirectory = "Live";
19
21 public string DmbName => BaseProvider.DmbName;
22
25
28
31
35 public bool Swapped => swapped != 0;
36
40 protected IDmbProvider BaseProvider { get; }
41
45 protected IIOManager IOManager { get; }
46
51
55 volatile int swapped;
56
63 public SwappableDmbProvider(IDmbProvider baseProvider, IIOManager ioManager, IFilesystemLinkFactory symlinkFactory)
64 {
65 BaseProvider = baseProvider ?? throw new ArgumentNullException(nameof(baseProvider));
66 IOManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
67 LinkFactory = symlinkFactory ?? throw new ArgumentNullException(nameof(symlinkFactory));
68 }
69
71 public virtual ValueTask DisposeAsync() => BaseProvider.DisposeAsync();
72
74 public void KeepAlive() => BaseProvider.KeepAlive();
75
81 public ValueTask MakeActive(CancellationToken cancellationToken)
82 {
83 if (Interlocked.Exchange(ref swapped, 1) != 0)
84 throw new InvalidOperationException("Already swapped!");
85
86 return DoSwap(cancellationToken);
87 }
88
94 public abstract Task FinishActivationPreparation(CancellationToken cancellationToken);
95
101 protected abstract ValueTask DoSwap(CancellationToken cancellationToken);
102 }
103}
Information about an engine installation.
A IDmbProvider that uses filesystem links to change directory structure underneath the server process...
ValueTask DoSwap(CancellationToken cancellationToken)
Perform the swapping action.
SwappableDmbProvider(IDmbProvider baseProvider, IIOManager ioManager, IFilesystemLinkFactory symlinkFactory)
Initializes a new instance of the SwappableDmbProvider class.
Task FinishActivationPreparation(CancellationToken cancellationToken)
Should be awaited. before calling MakeActive(CancellationToken) to ensure the SwappableDmbProvider is...
void KeepAlive()
Disposing the IDmbProvider won't cause a cleanup of the working directory.
bool Swapped
If MakeActive(CancellationToken) has been run.
IDmbProvider BaseProvider
The IDmbProvider we are swapping for.
const string LiveGameDirectory
The directory where the BaseProvider is symlinked to.
ValueTask MakeActive(CancellationToken cancellationToken)
Make the SwappableDmbProvider active by replacing the live link with our CompileJob.
IFilesystemLinkFactory LinkFactory
The IFilesystemLinkFactory to use.
Provides absolute paths to the latest compiled .dmbs.
void KeepAlive()
Disposing the IDmbProvider won't cause a cleanup of the working directory.
EngineVersion EngineVersion
The Api.Models.EngineVersion used to build the .dmb.
Models.CompileJob CompileJob
The CompileJob of the .dmb.
Interface for using filesystems.
Definition IIOManager.cs:13
string ResolvePath()
Retrieve the full path of the current working directory.