Github user squito commented on a diff in the pull request:
https://github.com/apache/spark/pull/7052#discussion_r37813078
--- Diff:
launcher/src/main/java/org/apache/spark/launcher/ChildProcAppHandle.java ---
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.launcher;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * Handle implementation for monitoring apps started as a child process.
+ */
+class ChildProcAppHandle implements SparkAppHandle {
+
+ private static final ThreadFactory REDIRECTOR_FACTORY =
+ new NamedThreadFactory("ChildProcOutputRedirector-%d");
+
+ private final String secret;
+ private final LauncherServer server;
+
+ private Process childProc;
+ private boolean disposed;
+ private LauncherConnection connection;
+ private List<Listener> listeners;
+ private State state;
+ private String appId;
+ private OutputRedirector redirector;
+
+ ChildProcAppHandle(String secret, LauncherServer server) {
+ this.secret = secret;
+ this.server = server;
+ this.state = State.UNKNOWN;
+ }
+
+ @Override
+ public synchronized void addListener(Listener l) {
+ if (listeners == null) {
+ listeners = new ArrayList<>();
+ }
+ listeners.add(l);
+ }
+
+ @Override
+ public State getState() {
+ return state;
+ }
+
+ @Override
+ public String getAppId() {
+ return appId;
+ }
+
+ @Override
+ public void stop() {
+ CommandBuilderUtils.checkState(connection != null, "Application is
still not connected.");
+ try {
+ connection.send(new LauncherProtocol.Stop());
+ } catch (IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ }
+
+ @Override
+ public synchronized void disconnect() {
+ if (!disposed) {
+ disposed = true;
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (IOException ioe) {
+ // no-op.
+ }
+ }
+ server.unregister(this);
+ if (redirector != null) {
+ redirector.stop();
+ }
+ }
+ }
+
+ @Override
+ public synchronized void kill() {
+ if (!disposed) {
+ disconnect();
+ if (childProc != null) {
+ childProc.destroy();
+ childProc = null;
+ }
+ }
+ }
+
+ String getSecret() {
+ return secret;
+ }
+
+ void setChildProc(Process childProc) {
+ this.childProc = childProc;
+ this.redirector = new OutputRedirector(childProc.getInputStream(),
REDIRECTOR_FACTORY);
+ }
+
+ void setConnection(LauncherConnection connection) {
+ this.connection = connection;
+ }
+
+ LauncherServer getServer() {
+ return server;
+ }
+
+ LauncherConnection getConnection() {
+ return connection;
+ }
+
+ void setState(State s) {
+ if (!state.isFinal()) {
--- End diff --
rather than being a no-op if the state is already final, shoudl it throw an
exception? Are there OK cases for trying to change the case after its final?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]