use of org.apache.sling.launchpad.base.shared.Launcher in project sling by apache.
the class Main method doStart.
protected boolean doStart(final URL launcherJar) {
// prevent duplicate start
if (this.started) {
info("Apache Sling has already been started", null);
return true;
}
info("Starting Apache Sling in " + slingHome, null);
this.started = true;
Loader loaderTmp = null;
try {
final File launchpadHome = getLaunchpadHome(slingHome, commandLineArgs);
loaderTmp = new Loader(launchpadHome) {
@Override
protected void info(String msg) {
Main.info(msg, null);
}
};
} catch (IllegalArgumentException iae) {
error("Cannot launch: Launchpad folder cannot be used: " + iae.getMessage(), null);
return false;
}
this.loader = loaderTmp;
if (launcherJar != null) {
try {
loader.installLauncherJar(launcherJar);
} catch (IOException ioe) {
error("Cannot launch: Cannot install " + launcherJar + " for use", ioe);
return false;
}
} else {
info("No Launcher JAR to install", null);
}
Object object = null;
try {
object = loader.loadLauncher(SharedConstants.DEFAULT_SLING_MAIN);
} catch (IllegalArgumentException iae) {
error("Cannot launch: Failed loading Sling class " + SharedConstants.DEFAULT_SLING_MAIN, iae);
return false;
}
if (object instanceof Launcher) {
// configure the launcher
Launcher sling = (Launcher) object;
sling.setNotifiable(new Notified());
sling.setCommandLine(commandLineArgs);
sling.setSlingHome(slingHome);
// launch it
info("Starting launcher ...", null);
if (sling.start()) {
info("Startup completed", null);
this.sling = sling;
addShutdownHook();
return true;
}
error("Cannot launch: Launcher.start() returned false", null);
} else {
error("Cannot launch: Class " + SharedConstants.DEFAULT_SLING_MAIN + " is not a Launcher class", null);
}
return false;
}
use of org.apache.sling.launchpad.base.shared.Launcher in project sling by apache.
the class SlingServlet method startSling.
/**
* Installs the launcher jar from the given URL (if not <code>null</code>)
* and launches Sling from that launcher.
*/
private void startSling(URL launcherJar) {
synchronized (this) {
if (sling != null) {
log("Apache Sling already started, nothing to do");
return;
} else if (startingSling != null) {
log("Apache Sling being started by Thread " + startingSling);
return;
}
startingSling = Thread.currentThread();
}
if (launcherJar != null) {
try {
log("Checking launcher JAR in " + slingHome);
loader.installLauncherJar(launcherJar);
} catch (IOException ioe) {
startupFailure("Failed installing " + launcherJar, ioe);
return;
}
} else {
log("No Launcher JAR to install");
}
Object object = null;
try {
object = loader.loadLauncher(SharedConstants.DEFAULT_SLING_SERVLET);
} catch (IllegalArgumentException iae) {
startupFailure("Cannot load Launcher Servlet " + SharedConstants.DEFAULT_SLING_SERVLET, iae);
return;
}
if (object instanceof Servlet) {
Servlet sling = (Servlet) object;
if (sling instanceof Launcher) {
Launcher slingLauncher = (Launcher) sling;
slingLauncher.setNotifiable(this);
slingLauncher.setCommandLine(properties);
slingLauncher.setSlingHome(slingHome);
}
try {
log("Starting launcher ...");
sling.init(getServletConfig());
this.sling = sling;
this.startFailureCounter = 0;
log("Startup completed");
} catch (ServletException se) {
startupFailure(null, se);
}
}
// reset the starting flag
synchronized (this) {
startingSling = null;
}
}
Aggregations