mirror of https://github.com/apache/druid.git
ExecutorMain: Shut down when our parent disappears
This commit is contained in:
parent
243e70a3c0
commit
6324225a4f
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package com.metamx.druid.merger.worker.executor;
|
package com.metamx.druid.merger.worker.executor;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
import com.metamx.common.lifecycle.Lifecycle;
|
import com.metamx.common.lifecycle.Lifecycle;
|
||||||
import com.metamx.common.logger.Logger;
|
import com.metamx.common.logger.Logger;
|
||||||
import com.metamx.druid.log.LogLevelAdjuster;
|
import com.metamx.druid.log.LogLevelAdjuster;
|
||||||
|
@ -26,6 +27,9 @@ import com.metamx.druid.merger.common.TaskStatus;
|
||||||
import com.metamx.druid.merger.common.task.Task;
|
import com.metamx.druid.merger.common.task.Task;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
@ -55,6 +59,34 @@ public class ExecutorMain
|
||||||
System.exit(2);
|
System.exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Spawn monitor thread to keep a watch on our parent process
|
||||||
|
// If stdin reaches eof, the parent is gone, and we should shut down
|
||||||
|
final ExecutorService parentMonitorExec = Executors.newSingleThreadExecutor(
|
||||||
|
new ThreadFactoryBuilder()
|
||||||
|
.setNameFormat("parent-monitor-%d")
|
||||||
|
.setDaemon(true)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
parentMonitorExec.submit(
|
||||||
|
new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
int b = -1;
|
||||||
|
try {
|
||||||
|
b = System.in.read();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e, "Failed to read from stdin");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO ugh this is gross
|
||||||
|
System.exit(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Task task = node.getJsonMapper().readValue(new File(args[0]), Task.class);
|
final Task task = node.getJsonMapper().readValue(new File(args[0]), Task.class);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue