@Override public synchronized void kill() { if (!disposed) { disconnect(); } if (childProc != null) { try { childProc.exitValue(); } catch (IllegalThreadStateException e) { childProc.destroyForcibly(); } finally { childProc = null; } } }
@Override public synchronized void kill() { if (!disposed) { disconnect(); } if (childProc != null) { try { childProc.exitValue(); } catch (IllegalThreadStateException e) { // Child is still alive. Try to use Java 8's "destroyForcibly()" if available, // fall back to the old API if it's not there. try { Method destroy = childProc.getClass().getMethod("destroyForcibly"); destroy.invoke(childProc); } catch (Exception inner) { childProc.destroy(); } } finally { childProc = null; } } }
@Override public void close() throws IOException { synchronized (clients) { clients.remove(this); } super.close(); if (handle != null) { if (!handle.getState().isFinal()) { LOG.log(Level.WARNING, "Lost connection to spark application."); handle.setState(SparkAppHandle.State.LOST); } handle.disconnect(); } }
@Override public void close() throws IOException { synchronized (clients) { clients.remove(this); } super.close(); if (handle != null) { if (!handle.getState().isFinal()) { LOG.log(Level.WARNING, "Lost connection to spark application."); handle.setState(SparkAppHandle.State.LOST); } handle.disconnect(); } }
@Override public synchronized void kill() { if (!isDisposed()) { setState(State.KILLED); disconnect(); if (childProc != null) { if (childProc.isAlive()) { childProc.destroyForcibly(); } childProc = null; } } }
@Override public synchronized void kill() { if (!isDisposed()) { setState(State.KILLED); disconnect(); if (childProc != null) { if (childProc.isAlive()) { childProc.destroyForcibly(); } childProc = null; } } }
@Test public void testAppHandleDisconnect() throws Exception { LauncherServer server = LauncherServer.getOrCreateServer(); ChildProcAppHandle handle = new ChildProcAppHandle(server); String secret = server.registerHandle(handle); TestClient client = null; try { Socket s = new Socket(InetAddress.getLoopbackAddress(), server.getPort()); client = new TestClient(s); client.send(new Hello(secret, "1.4.0")); client.send(new SetAppId("someId")); // Wait until we know the server has received the messages and matched the handle to the // connection before disconnecting. eventually(Duration.ofSeconds(1), Duration.ofMillis(10), () -> { assertEquals("someId", handle.getAppId()); }); handle.disconnect(); waitForError(client, secret); } finally { handle.kill(); close(client); client.clientThread.join(); } }