@Override public synchronized void kill() { if (!isDisposed()) { LOG.warning("kill() may leave the underlying app running in in-process mode."); setState(State.KILLED); disconnect(); // Interrupt the thread. This is not guaranteed to kill the app, though. if (app != null) { app.interrupt(); } } }
/** * Starts a Spark application. * * @see AbstractLauncher#startApplication(SparkAppHandle.Listener...) * @param listeners Listeners to add to the handle before the app is launched. * @return A handle for the launched application. */ @Override public SparkAppHandle startApplication(SparkAppHandle.Listener... listeners) throws IOException { if (builder.isClientMode(builder.getEffectiveConfig())) { LOG.warning("It's not recommended to run client-mode applications using InProcessLauncher."); } Method main = findSparkSubmit(); LauncherServer server = LauncherServer.getOrCreateServer(); InProcessAppHandle handle = new InProcessAppHandle(server); for (SparkAppHandle.Listener l : listeners) { handle.addListener(l); } String secret = server.registerHandle(handle); setConf(LauncherProtocol.CONF_LAUNCHER_PORT, String.valueOf(server.getPort())); setConf(LauncherProtocol.CONF_LAUNCHER_SECRET, secret); List<String> sparkArgs = builder.buildSparkSubmitArgs(); String[] argv = sparkArgs.toArray(new String[sparkArgs.size()]); String appName = CommandBuilderUtils.firstNonEmpty(builder.appName, builder.mainClass, "<unknown>"); handle.start(appName, main, argv); return handle; }
synchronized void start(String appName, Method main, String[] args) { CommandBuilderUtils.checkState(app == null, "Handle already started."); if (appName.length() > MAX_APP_NAME_LEN) { appName = "..." + appName.substring(appName.length() - MAX_APP_NAME_LEN); } app = new Thread(() -> { try { main.invoke(null, (Object) args); } catch (Throwable t) { LOG.log(Level.WARNING, "Application failed with exception.", t); setState(State.FAILED); } dispose(); }); app.setName(String.format(THREAD_NAME_FMT, THREAD_IDS.incrementAndGet(), appName)); app.start(); }
/** * Starts a Spark application. * * @see AbstractLauncher#startApplication(SparkAppHandle.Listener...) * @param listeners Listeners to add to the handle before the app is launched. * @return A handle for the launched application. */ @Override public SparkAppHandle startApplication(SparkAppHandle.Listener... listeners) throws IOException { if (builder.isClientMode(builder.getEffectiveConfig())) { LOG.warning("It's not recommended to run client-mode applications using InProcessLauncher."); } Method main = findSparkSubmit(); LauncherServer server = LauncherServer.getOrCreateServer(); InProcessAppHandle handle = new InProcessAppHandle(server); for (SparkAppHandle.Listener l : listeners) { handle.addListener(l); } String secret = server.registerHandle(handle); setConf(LauncherProtocol.CONF_LAUNCHER_PORT, String.valueOf(server.getPort())); setConf(LauncherProtocol.CONF_LAUNCHER_SECRET, secret); List<String> sparkArgs = builder.buildSparkSubmitArgs(); String[] argv = sparkArgs.toArray(new String[sparkArgs.size()]); String appName = CommandBuilderUtils.firstNonEmpty(builder.appName, builder.mainClass, "<unknown>"); handle.start(appName, main, argv); return handle; }
synchronized void start(String appName, Method main, String[] args) { CommandBuilderUtils.checkState(app == null, "Handle already started."); if (appName.length() > MAX_APP_NAME_LEN) { appName = "..." + appName.substring(appName.length() - MAX_APP_NAME_LEN); } app = new Thread(() -> { try { main.invoke(null, (Object) args); } catch (Throwable t) { LOG.log(Level.WARNING, "Application failed with exception.", t); setState(State.FAILED); } dispose(); }); app.setName(String.format(THREAD_NAME_FMT, THREAD_IDS.incrementAndGet(), appName)); app.start(); }
@Override public synchronized void kill() { if (!isDisposed()) { LOG.warning("kill() may leave the underlying app running in in-process mode."); setState(State.KILLED); disconnect(); // Interrupt the thread. This is not guaranteed to kill the app, though. if (app != null) { app.interrupt(); } } }