2023-05-03 12:18:37 +00:00
|
|
|
|
using Utils;
|
|
|
|
|
|
|
|
|
|
namespace KubernetesWorkflow
|
|
|
|
|
{
|
|
|
|
|
public class ApplicationLifecycle
|
|
|
|
|
{
|
2023-05-04 07:16:15 +00:00
|
|
|
|
private static object instanceLock = new object();
|
2023-05-03 12:18:37 +00:00
|
|
|
|
private static ApplicationLifecycle? instance;
|
|
|
|
|
private readonly NumberSource servicePortNumberSource = new NumberSource(30001);
|
|
|
|
|
private readonly NumberSource namespaceNumberSource = new NumberSource(0);
|
|
|
|
|
|
|
|
|
|
private ApplicationLifecycle()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ApplicationLifecycle Instance
|
|
|
|
|
{
|
|
|
|
|
// I know singletons are quite evil. But we need to be sure this object is created only once
|
|
|
|
|
// and persists for the entire application lifecycle.
|
|
|
|
|
get
|
|
|
|
|
{
|
2023-05-04 07:16:15 +00:00
|
|
|
|
lock (instanceLock)
|
|
|
|
|
{
|
|
|
|
|
if (instance == null) instance = new ApplicationLifecycle();
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
2023-05-03 12:18:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NumberSource GetServiceNumberSource()
|
|
|
|
|
{
|
|
|
|
|
return servicePortNumberSource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetTestNamespace()
|
|
|
|
|
{
|
|
|
|
|
return namespaceNumberSource.GetNextNumber().ToString("D5");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|