I have a class that uses static methods to wrap remote API calls.
Generally speaking, I don't want my API server to "listen" for these calls all the time, but instead only listen when the class is being used by a program. So I need a way to tell the server to "wake up" when the class gets loaded (how I send the "wake up" message is irrelevant).
I know that I can wake the server up when the first class method is invoked, but I want it to be ready as soon as the class is loaded into a running program (even if it is loaded lazily).
Also, it would be nice to know when the class is no longer used, so I can tell the server to go back to sleep.
Basically, I'm looking for a "constructor" and a "finalizer" of an entire class. Can this be done?
EDIT: A very important thing I forgot to mention, I can't have the user manually initialize/finalize the class using public static methods or anything like that. The class needs to feel like a regular native class.