本文整理汇总了Java中sun.misc.Signal.handle方法的典型用法代码示例。如果您正苦于以下问题:Java Signal.handle方法的具体用法?Java Signal.handle怎么用?Java Signal.handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.misc.Signal
的用法示例。
在下文中一共展示了Signal.handle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSignal
import sun.misc.Signal; //导入方法依赖的package包/类
/**
* Set up a Un*x signal handler to call {@link #restartApplication(Runnable, boolean)} when the signal
* is received.
*
* @param signalName Name of the signal.
* @param onExit A runnable to perform on exit.
* @param withNewest If a jar, should we find the newest?
* @param pidFile the name of a file to write the process id too
*/
public static void onSignal(final String signalName, Runnable onExit, boolean withNewest, String pidFile) {
Signal sig = new Signal(signalName);
Signal.handle(sig, signal -> {
restartApplication(onExit, withNewest);
});
if (pidFile != null) {
final Path pidFilePath = Paths.get(pidFile);
try {
Files.deleteIfExists(pidFilePath);
Files.createFile(pidFilePath);
Files.write(pidFilePath, String.format("%d\n", getProcessPid()).getBytes());
} catch (IOException e) {
throw new UncheckedIOException("Can not create pid file: " + pidFile, e);
}
}
}
示例2: initializeBasicFeatures
import sun.misc.Signal; //导入方法依赖的package包/类
/**
* Initializes basic features of the VM, including all of the VM schemes and the trap handling mechanism.
* It also parses some program arguments that were not parsed earlier.
*/
protected final void initializeBasicFeatures() {
MaxineVM vm = vm();
vm.phase = MaxineVM.Phase.STARTING;
// Now we can decode all the other VM arguments using the full language
if (VMOptions.parseStarting()) {
VMLog.checkLogOptions();
vmConfig().initializeSchemes(MaxineVM.Phase.STARTING);
if (Heap.ExcessiveGCFrequency != 0) {
new ExcessiveGCDaemon(Heap.ExcessiveGCFrequency).start();
}
if (Deoptimization.DeoptimizeALot != 0 && Deoptimization.UseDeopt) {
new DeoptimizeALot(Deoptimization.DeoptimizeALot).start();
}
// Install the signal handler for dumping threads when SIGHUP is received
Signal.handle(new Signal("QUIT"), new PrintThreads(false));
}
}
示例3: testRaiseNoConsumer
import sun.misc.Signal; //导入方法依赖的package包/类
@Test
static void testRaiseNoConsumer() {
Signal signal = new Signal("INT");
SignalHandler orig = null;
try {
orig = Signal.handle(signal, SignalHandler.SIG_DFL);
printf("oldHandler: %s%n", orig);
if (orig == SignalHandler.SIG_IGN) {
// SIG_IGN for TERM means it cannot be handled
return;
}
Signal.raise(signal);
Assert.fail("Should have thrown IllegalArgumentException");
} catch (IllegalArgumentException iae) {
printf("IAE message: %s%n", iae.getMessage());
} finally {
// Restore original signal handler
if (orig != null && signal != null) {
Signal.handle(signal, orig);
}
}
}
示例4: checkLastHandler
import sun.misc.Signal; //导入方法依赖的package包/类
@Test()
static void checkLastHandler() {
if (RUNNING_WITH_Xrs) {
return;
}
Signal signal = new Signal("TERM");
Handler h1 = new Handler();
Handler h2 = new Handler();
SignalHandler orig = Signal.handle(signal, h1);
if (orig == SignalHandler.SIG_IGN) {
// SIG_IGN for TERM means it cannot be handled
return;
}
try {
SignalHandler prev = Signal.handle(signal, h2);
Assert.assertSame(prev, h1, "prev handler mismatch");
prev = Signal.handle(signal, h1);
Assert.assertSame(prev, h2, "prev handler mismatch");
} finally {
if (orig != null && signal != null) {
Signal.handle(signal, orig);
}
}
}
示例5: InteractiveShellRunner
import sun.misc.Signal; //导入方法依赖的package包/类
public InteractiveShellRunner(@Nonnull StatementExecuter executer,
@Nonnull TransactionHandler txHandler,
@Nonnull Logger logger,
@Nonnull StatementParser statementParser,
@Nonnull InputStream inputStream,
@Nonnull File historyFile,
@Nonnull UserMessagesHandler userMessagesHandler) throws IOException {
this.userMessagesHandler = userMessagesHandler;
this.currentyExecuting = new AtomicBoolean(false);
this.executer = executer;
this.txHandler = txHandler;
this.logger = logger;
this.statementParser = statementParser;
this.reader = setupConsoleReader(logger, inputStream);
this.historian = FileHistorian.setupHistory(reader, logger, historyFile);
// Catch ctrl-c
Signal.handle(new Signal(INTERRUPT_SIGNAL), this);
}
示例6: setup
import sun.misc.Signal; //导入方法依赖的package包/类
static void setup() {
if (handler != null) return;
SignalHandler sh = new SignalHandler() {
public void handle(Signal sig) {
Shutdown.exit(sig.getNumber() + 0200);
}
};
handler = sh;
try {
Signal.handle(new Signal("INT"), sh);
Signal.handle(new Signal("TERM"), sh);
} catch (IllegalArgumentException e) {
// When -Xrs is specified the user is responsible for
// ensuring that shutdown hooks are run by calling
// System.exit()
}
}
示例7: renderOutput
import sun.misc.Signal; //导入方法依赖的package包/类
public void renderOutput(PrintStream out, OutputFormat outputFormat, boolean interactive)
{
Thread clientThread = Thread.currentThread();
SignalHandler oldHandler = Signal.handle(SIGINT, signal -> {
if (ignoreUserInterrupt.get() || client.isClosed()) {
return;
}
userAbortedQuery.set(true);
client.close();
clientThread.interrupt();
});
try {
renderQueryOutput(out, outputFormat, interactive);
}
finally {
Signal.handle(SIGINT, oldHandler);
Thread.interrupted(); // clear interrupt status
}
}
示例8: startSignalHandler
import sun.misc.Signal; //导入方法依赖的package包/类
/**
* <p>
* startSignalHandler
* </p>
*/
protected void startSignalHandler() {
Signal.handle(new Signal("INT"), new SignalHandler() {
private boolean interrupted = false;
@Override
public void handle(Signal arg0) {
if (interrupted)
System.exit(0);
try {
interrupted = true;
if (process != null)
process.waitFor();
} catch (InterruptedException e) {
logger.warn("",e);
}
}
});
}
示例9: setup
import sun.misc.Signal; //导入方法依赖的package包/类
static void setup() {
if (handler != null) return;
SignalHandler sh = new SignalHandler() {
public void handle(Signal sig) {
Shutdown.exit(sig.getNumber() + 0200);
}
};
handler = sh;
try {
Signal.handle(new Signal("INT"), sh);
Signal.handle(new Signal("TERM"), sh);
} catch (IllegalArgumentException e) {
// When -Xrs is specified the user is responsible for
// ensuring that shutdown hooks are run by calling
// System.exit()
}
}
示例10: setup
import sun.misc.Signal; //导入方法依赖的package包/类
static void setup() {
if (handler != null) return;
SignalHandler sh = new SignalHandler() {
public void handle(Signal sig) {
Shutdown.exit(sig.getNumber() + 0200);
}
};
handler = sh;
try {
Signal.handle(new Signal("HUP"), sh);
Signal.handle(new Signal("INT"), sh);
Signal.handle(new Signal("TERM"), sh);
} catch (IllegalArgumentException e) {
// When -Xrs is specified the user is responsible for
// ensuring that shutdown hooks are run by calling
// System.exit()
}
}
示例11: handleShutdown
import sun.misc.Signal; //导入方法依赖的package包/类
public static boolean handleShutdown(Class<?> clazz, String[] args,
final AtomicBoolean running) {
if (args != null && args.length > 0 && args[0].equals("stop")) {
running.set(false);
return true;
}
SignalHandler handler = new SignalHandler() {
@Override
public void handle(Signal signal) {
running.set(false);
}
};
String command = System.getProperty("sun.java.command");
if (command == null || command.isEmpty()) {
return false;
}
if (clazz.getName().equals(command.split(" ")[0])) {
Signal.handle(new Signal("INT"), handler);
Signal.handle(new Signal("TERM"), handler);
}
return false;
}
示例12: addUnixSignalStatusHandle
import sun.misc.Signal; //导入方法依赖的package包/类
private static void addUnixSignalStatusHandle() {
Signal.handle(new Signal("USR2"), new SignalHandler() {
@Override
public void handle(Signal sig) {
System.err.print("::: "+new Date()+" ::: RECIVE SIGNAL "+sig+" ::: Internal Server Status: ");
if(sig!=null){
if(status==STATUS_STARTING){
System.err.println("'STATUS_STARTING' :::");
}else if(status==STATUS_RUNNING){
System.err.println("'STATUS_RUNNING' :::");
}else if(status==STATUS_STOPING){
System.err.println("'STATUS_STOPING' :::");
}else{
System.err.println("'STATUS_UNKNOWN' :::");
}
}
System.err.flush();
}
});
}
示例13: SentenceSourceIndexer
import sun.misc.Signal; //导入方法依赖的package包/类
SentenceSourceIndexer(Directory dir, Language language, int maxSentences, Analyzer analyzer) {
if (analyzer == null) {
this.indexer = new Indexer(dir, language);
} else {
this.indexer = new Indexer(dir, language, analyzer);
}
this.indexer.setLowercaseOnly(LC_ONLY);
this.maxSentences = maxSentences;
Signal.handle(new Signal("HUP"), signal -> {
stopped = true;
System.out.println("----- Got SIGHUP, will commit and exit ----");
try {
indexer.commit();
System.out.println("----- commit done, will exit now ----");
} catch (Exception e) {
e.printStackTrace();
}
System.exit(1);
});
}
示例14: AbstractSignalHandler
import sun.misc.Signal; //导入方法依赖的package包/类
public AbstractSignalHandler() {
// kill命令
Signal termSignal = new Signal("TERM");
Signal.handle(termSignal, this);
// ctrl+c命令
Signal intSignal = new Signal("INT");
Signal.handle(intSignal, this);
}
示例15: main
import sun.misc.Signal; //导入方法依赖的package包/类
public static void main(String[] args) {
StatMessageSender sender = new StatMessageSender();
// kill命令
Signal termSignal = new Signal("TERM");
Signal.handle(termSignal, sender);
// ctrl+c命令
Signal intSignal = new Signal("INT");
Signal.handle(intSignal, sender);
sender.run();
}