Consider class, utilising Apache Ignite.NET library
public interface ICluster
{
void Join();
void Leave();
}
public class ApacheIgniteClusterImpl : ICluster
{
private IIgnite Ignite { get; set; }
private int MulticastPort { get; }
private int ThinClientPort { get; }
public ApacheIgniteClusterImpl(int multicastPort = 47401, int thinClientPort = 10800)
{
MulticastPort = multicastPort;
ThinClientPort = thinClientPort;
}
public void Join()
{
if (Ignite != null)
{
return;
}
var configuration = new IgniteConfiguration
{
ClientConnectorConfiguration = new ClientConnectorConfiguration
{
Port = ThinClientPort,
},
DiscoverySpi = new TcpDiscoverySpi
{
IpFinder = new TcpDiscoveryMulticastIpFinder()
{
MulticastPort = MulticastPort,
}
},
JvmOptions = new List<string>()
{
"-DIGNITE_NO_SHUTDOWN_HOOK=true",
},
};
// Start
Ignite = Ignition.Start(configuration);
}
public void Leave()
{
Ignition.Stop(null, true);
Ignite = null;
}
}
Normally, in .NET Standard we are allowed to hook into AppDomain.CurrentDomain.ProcessExit
event where we could do our cleanup stuff. However, once JVM is created by Apache Ignite.NET AppDomain.CurrentDomain.ProcessExit
will never be fired when I kill console application on MacOS with kill <pid>
.
I've done some research while debugging, and found out that it will happen somewhere after private static Jvm CreateJvm(IgniteConfiguration cfg, ILogger log)
has been called.
Any idea what happens there and if there any chance we can hook into AppDomain.CurrentDomain.ProcessExit
?
UPD: Neither AppDomain.CurrentDomain.DomainUnload
nor System.Runtime.Loader.AssemblyLoadContext.Unloading
will work too.