use of sun.misc.Signal in project hive by apache.
the class CliDriver method processLine.
/**
* Processes a line of semicolon separated commands
*
* @param line
* The commands to process
* @param allowInterrupting
* When true the function will handle SIG_INT (Ctrl+C) by interrupting the processing and
* returning -1
* @return 0 if ok
*/
public CommandProcessorResponse processLine(String line, boolean allowInterrupting) throws CommandProcessorException {
SignalHandler oldSignal = null;
Signal interruptSignal = null;
if (allowInterrupting) {
// Remember all threads that were running at the time we started line processing.
// Hook up the custom Ctrl+C handler while processing this line
interruptSignal = new Signal("INT");
oldSignal = Signal.handle(interruptSignal, new SignalHandler() {
private boolean interruptRequested;
@Override
public void handle(Signal signal) {
boolean initialRequest = !interruptRequested;
interruptRequested = true;
// Kill the VM on second ctrl+c
if (!initialRequest) {
console.printInfo("Exiting the JVM");
System.exit(127);
}
// Interrupt the CLI thread to stop the current statement and return
// to prompt
console.printInfo("Interrupting... Be patient, this might take some time.");
console.printInfo("Press Ctrl+C again to kill JVM");
// First, kill any running MR jobs
HadoopJobExecHelper.killRunningJobs();
TezJobExecHelper.killRunningJobs();
HiveInterruptUtils.interrupt();
}
});
}
try {
CommandProcessorResponse lastRet = new CommandProcessorResponse();
CommandProcessorResponse ret;
// we can not use "split" function directly as ";" may be quoted
List<String> commands = splitSemiColon(line);
StringBuilder command = new StringBuilder();
for (String oneCmd : commands) {
if (StringUtils.endsWith(oneCmd, "\\")) {
command.append(StringUtils.chop(oneCmd) + ";");
continue;
} else {
command.append(oneCmd);
}
if (StringUtils.isBlank(command.toString())) {
continue;
}
try {
ret = processCmd(command.toString());
lastRet = ret;
} catch (CommandProcessorException e) {
boolean ignoreErrors = HiveConf.getBoolVar(conf, HiveConf.ConfVars.CLIIGNOREERRORS);
if (!ignoreErrors) {
throw e;
}
} finally {
command.setLength(0);
}
}
return lastRet;
} finally {
// Once we are done processing the line, restore the old handler
if (oldSignal != null && interruptSignal != null) {
Signal.handle(interruptSignal, oldSignal);
}
}
}
use of sun.misc.Signal in project jstorm by alibaba.
the class JStormSignalHandler method registerSignal.
/**
* Register signal to system
* if callback is null, then the current process will ignore this signal
*/
public synchronized void registerSignal(int signalNumber, Runnable callback, boolean replace) {
String signalName = signalMap.get(signalNumber);
if (signalName == null) {
LOG.warn("Invalid signalNumber " + signalNumber);
return;
}
LOG.info("Begin to register signal of {}", signalName);
try {
SignalHandler oldHandler = Signal.handle(new Signal(signalName), this);
LOG.info("Successfully register {} handler", signalName);
Runnable old = signalHandlers.put(signalNumber, callback);
if (old != null) {
if (!replace) {
oldSignalHandlers.put(signalNumber, oldHandler);
} else {
LOG.info("Successfully old {} handler will be replaced", signalName);
}
}
LOG.info("Successfully register signal of {}", signalName);
} catch (Exception e) {
LOG.error("Failed to register " + signalName + ":" + signalNumber + ", Signal already used by VM or OS: SIGILL");
}
}
use of sun.misc.Signal in project Saturn by vipshop.
the class ShutdownGracefullyIT method test_A_TERM_Signal.
@Test
public void test_A_TERM_Signal() throws Exception {
SystemEnvProperties.VIP_SATURN_SHUTDOWN_TIMEOUT = 10;
startExecutorList(1);
final int shardCount = 3;
final String jobName = "test_A_TERM_Signal";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 8;
status.finished = false;
status.timeout = false;
LongtimeJavaJob.statusMap.put(key, status);
}
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(50);
ShutdownHandler.exitAfterHandler(false);
Signal.raise(new Signal("TERM"));
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.finished) {
return false;
}
}
return true;
}
}, 10);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
stopExecutorListGracefully();
}
use of sun.misc.Signal in project Saturn by vipshop.
the class ShutdownGracefullyIT method test_B_INT_Signal.
@Test
public void test_B_INT_Signal() throws Exception {
SystemEnvProperties.VIP_SATURN_SHUTDOWN_TIMEOUT = 5;
startExecutorList(1);
final int shardCount = 3;
final String jobName = "test_B_INT_Signal";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 3;
status.finished = false;
status.timeout = false;
LongtimeJavaJob.statusMap.put(key, status);
}
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(50);
ShutdownHandler.exitAfterHandler(false);
Signal.raise(new Signal("INT"));
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.finished) {
return false;
}
}
return true;
}
}, 5);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
stopExecutorListGracefully();
}
use of sun.misc.Signal in project oap by oaplatform.
the class Boot method installSignals.
private static void installSignals() {
SignalHandler handler = signal -> {
log.info("cought signal: {}", signal.getName());
System.out.println("cought signal: " + signal.getName());
System.out.flush();
exit(0);
};
Signal.handle(new Signal("INT"), handler);
Signal.handle(new Signal("TERM"), handler);
}
Aggregations