本文整理汇总了Java中sun.misc.Signal类的典型用法代码示例。如果您正苦于以下问题:Java Signal类的具体用法?Java Signal怎么用?Java Signal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Signal类属于sun.misc包,在下文中一共展示了Signal类的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: handle
import sun.misc.Signal; //导入依赖的package包/类
@Override
public void handle(Signal signal) {
if (signalCount == 0) {
System.out.println("Terminating from signal");
if (server != null) {
server.initiateShutdown();
} else {
System.out.println("...but no server found? Dazed, confused and doing nothing.");
}
System.out.println("A second signal will trigger standard Forge shutdown, a third will trigger abrupt termination.");
} else if (signalCount == 1) {
System.out.println("Caught second signal, triggering Forge-standard shutdown.");
FMLCommonHandler.instance().exitJava(1, false);
} else {
System.out.println("Caught third signal, triggering abrupt termination. Corruption is possible.");
FMLCommonHandler.instance().exitJava(2, true);
}
signalCount++;
}
示例4: testEquals
import sun.misc.Signal; //导入依赖的package包/类
@Test(dataProvider = "supportedSignals")
static void testEquals(String name, IsSupported supported, CanRegister register,
CanRaise raise, Invoked invoked) {
Object[][] data = supportedSignals();
for (int i = 0; i < data.length; i++) {
IsSupported otherSupported = (IsSupported) data[i][1];
if (supported == IsSupported.NO || otherSupported == IsSupported.NO) {
continue;
}
String otherName = (String) data[i][0];
Signal sig1 = new Signal(name);
Signal sig2 = new Signal(otherName);
if (name.equals(otherName)) {
Assert.assertEquals(sig1, sig2, "Equals failed; ");
Assert.assertEquals(sig1.hashCode(), sig2.hashCode(), "HashCode wrong; ");
} else {
Assert.assertNotEquals(sig1, sig2, "NotEquals failed; ");
Assert.assertNotEquals(sig1.hashCode(), sig2.hashCode(), "HashCode wrong; ");
}
}
}
示例5: 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);
}
}
}
示例6: 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);
}
}
}
示例7: handle
import sun.misc.Signal; //导入依赖的package包/类
/**
* Provided as part of the signal handling interface. Calls rotate().
*/
@Override
public void handle ( Signal arg0 )
{
final String signame = arg0.getName ();
if ( signame.equals ( fSignal ) )
{
log.info ( "Received signal " + arg0 + "; rotating." );
rotate ();
log.info ( "Log rotation complete." );
}
else
{
log.info ( "Received signal " + arg0 + "; ignored." );
}
}
示例8: handle
import sun.misc.Signal; //导入依赖的package包/类
@Override
public void handle(Signal signal) {
try {
for (Server server : servers) {
if (server != null) {
server.stop();
logger.info(server.getClass().getSimpleName() + " is stopped...");
while (server.running()) {
try {
Thread.sleep(100L);
} catch (InterruptedException e) { // ignore
}
}
}
}
} finally {
countDownLatch.countDown();
if (signalHandler != SIG_DFL && signalHandler != SIG_IGN) {
signalHandler.handle(signal);
}
}
}
示例9: 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);
}
示例10: handle
import sun.misc.Signal; //导入依赖的package包/类
/**
* Catch Ctrl-C from user and handle it nicely
*
* @param signal to handle
*/
@Override
public void handle(final Signal signal) {
// Stop any running cypher statements
if (currentyExecuting.get()) {
executer.reset();
} else {
// Print a literal newline here to get around us being in the middle of the prompt
logger.printError(
AnsiFormattedText.s().colorRed()
.append("\nInterrupted (Note that Cypher queries must end with a ")
.bold().append("semicolon. ").boldOff()
.append("Type ")
.bold().append(Exit.COMMAND_NAME).append(" ").boldOff()
.append("to exit the shell.)")
.formattedString());
// Clear any text which has been inputted
resetPrompt();
}
}
示例11: testSignalHandleOutsideExecution
import sun.misc.Signal; //导入依赖的package包/类
@Test
public void testSignalHandleOutsideExecution() throws Exception {
// given
InputStream inputStream = new ByteArrayInputStream("".getBytes());
InteractiveShellRunner runner = new InteractiveShellRunner(cmdExecuter, txHandler, logger,
new ShellStatementParser(), inputStream, historyFile, userMessagesHandler);
// when
runner.handle(new Signal(InteractiveShellRunner.INTERRUPT_SIGNAL));
// then
verifyNoMoreInteractions(cmdExecuter);
verify(logger).printError("@|RED \nInterrupted (Note that Cypher queries must end with a |@" +
"@|RED,BOLD semicolon. |@" +
"@|RED Type |@@|RED,BOLD :exit|@@|RED,BOLD |@" +
"@|RED to exit the shell.)|@");
}
示例12: testSignalHandleDuringExecution
import sun.misc.Signal; //导入依赖的package包/类
@Test
public void testSignalHandleDuringExecution() throws Exception {
// given
BoltStateHandler boltStateHandler = mock(BoltStateHandler.class);
FakeInterruptableShell fakeShell = spy(new FakeInterruptableShell(logger, boltStateHandler));
InputStream inputStream = new ByteArrayInputStream("RETURN 1;\n".getBytes());
InteractiveShellRunner runner = new InteractiveShellRunner(fakeShell, fakeShell, logger,
new ShellStatementParser(), inputStream, historyFile, userMessagesHandler);
// during
Thread t = new Thread(runner::runUntilEnd);
t.start();
// wait until execution has begun
while (!t.getState().equals(Thread.State.TIMED_WAITING)) {
Thread.sleep(100L);
}
// when
runner.handle(new Signal(InteractiveShellRunner.INTERRUPT_SIGNAL));
// then
verify(fakeShell).execute("RETURN 1;");
verify(fakeShell).reset();
verify(boltStateHandler).reset();
}
示例13: 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()
}
}
示例14: afterPropertiesSet
import sun.misc.Signal; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
if(LangUtils.isEmpty(graceKillProcessor)){
return ;
}
AnnotationAwareOrderComparator.sort(graceKillProcessor);
graceKillProcessor.stream().forEach(p->{
p.getSignals().forEach(s->{
if(logger.isWarnEnabled()){
logger.warn("register kill signal {}...", s);
}
Signal.handle(new Signal(s), this);
});
});
}
示例15: handle
import sun.misc.Signal; //导入依赖的package包/类
@Override
public void handle(Signal signal) {
if(logger.isWarnEnabled()){
logger.warn("receive kill signal {}...", signal.getName());
}
if(LangUtils.isEmpty(graceKillProcessor)){
return ;
}
final SignalInfo info = SignalInfo.builder()
.name(signal.getName())
.number(signal.getNumber())
.build();
graceKillProcessor.stream()
.filter(p->p.getSignals().contains(info.getName()))
.forEach(p->{
logger.warn("start to execute GraceKillProcessor[{}] ...", p.getClass());
try {
p.handle(info);
} catch (Exception e) {
logger.error("execute GraceKillProcessor["+p.getClass()+"] error: ", e);
}
logger.warn("has executed GraceKillProcessor[{}] ...", p.getClass());
});
}