
hudson.lifecycle.Lifecycle Maven / Gradle / Ivy
package hudson.lifecycle;
import hudson.ExtensionPoint;
import hudson.model.Hudson;
/**
* Provides the capability for starting/stopping/restarting/uninstalling Hudson.
*
*
* The steps to perform these operations depend on how Hudson is launched,
* so the concrete instance of this method (which is VM-wide singleton) is discovered
* by looking up a FQCN from the system property "hudson.lifecycle".
*
* @author Kohsuke Kawaguchi
* @since 1.254
*/
public abstract class Lifecycle implements ExtensionPoint {
private static Lifecycle INSTANCE = null;
/**
* Gets the singleton instance.
*
* @return never null
*/
public synchronized static Lifecycle get() {
if(INSTANCE==null) {
String p = System.getProperty("hudson.lifecycle");
if(p!=null) {
try {
ClassLoader cl = Hudson.getInstance().getPluginManager().uberClassLoader;
INSTANCE = (Lifecycle)cl.loadClass(p).newInstance();
} catch (InstantiationException e) {
InstantiationError x = new InstantiationError(e.getMessage());
x.initCause(e);
throw x;
} catch (IllegalAccessException e) {
IllegalAccessError x = new IllegalAccessError(e.getMessage());
x.initCause(e);
throw x;
} catch (ClassNotFoundException e) {
NoClassDefFoundError x = new NoClassDefFoundError(e.getMessage());
x.initCause(e);
throw x;
}
} else {
// no lifecycle given. use the default one
INSTANCE = new Lifecycle() {
};
}
}
return INSTANCE;
}
}