Search in sources :

Example 1 with Signal

use of sun.misc.Signal in project neo4j by neo4j.

the class AdversarySignals method installAsSIGUSR2.

public synchronized void installAsSIGUSR2() {
    if (!installed) {
        Signal.handle(new Signal("USR2"), new SignalHandler() {

            @Override
            public void handle(Signal sig) {
                handleSignal();
            }
        });
        installed = true;
    }
}
Also used : Signal(sun.misc.Signal) SignalHandler(sun.misc.SignalHandler)

Example 2 with Signal

use of sun.misc.Signal in project bazel by bazelbuild.

the class JUnit4TestXmlListenerTest method signalHandlerWritesXml.

@Test
public void signalHandlerWritesXml() throws Exception {
    TestSuiteModelSupplier mockModelSupplier = mock(TestSuiteModelSupplier.class);
    TestSuiteModel mockModel = mock(TestSuiteModel.class);
    CancellableRequestFactory mockRequestFactory = mock(CancellableRequestFactory.class);
    OutputStream mockXmlStream = mock(OutputStream.class);
    JUnit4TestXmlListener listener = new JUnit4TestXmlListener(mockModelSupplier, mockRequestFactory, fakeSignalHandlers, mockXmlStream, errPrintStream);
    Request request = Request.classWithoutSuiteMethod(PassingTest.class);
    Description suiteDescription = request.getRunner().getDescription();
    when(mockModelSupplier.get()).thenReturn(mockModel);
    listener.testRunStarted(suiteDescription);
    assertEquals(1, fakeSignalHandlers.handlers.size());
    fakeSignalHandlers.handlers.get(0).handle(new Signal("TERM"));
    String errOutput = errStream.toString(CHARSET);
    assertTrue("expected signal name in stderr", errOutput.contains("SIGTERM"));
    assertTrue("expected message in stderr", errOutput.contains("Done writing test XML"));
    InOrder inOrder = inOrder(mockRequestFactory, mockModel);
    inOrder.verify(mockRequestFactory).cancelRun();
    inOrder.verify(mockModel).testRunInterrupted();
    inOrder.verify(mockModel).writeAsXml(mockXmlStream);
}
Also used : Signal(sun.misc.Signal) Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) TestSuiteModel(com.google.testing.junit.runner.model.TestSuiteModel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Request(org.junit.runner.Request) Test(org.junit.Test)

Example 3 with Signal

use of sun.misc.Signal in project bazel by bazelbuild.

the class JUnit4TestXmlListener method testRunStarted.

@Override
public void testRunStarted(Description description) throws Exception {
    model = modelSupplier.get();
    /*
     * At this point, command line filtering has been applied. Mark all remaining tests as
     * "pending"; any other tests will be considered "filtered".
     */
    model.testRunStarted(description);
    signalHandlers.installHandler(new Signal("TERM"), new WriteXmlSignalHandler());
}
Also used : Signal(sun.misc.Signal)

Example 4 with Signal

use of sun.misc.Signal in project bazel by bazelbuild.

the class SignalHandlers method installHandler.

/**
   * Adds the given signal handler to the existing ones.
   *
   * <p>Signal handlers are responsible to catch any exception if the following
   * handlers need to be executed when a handler throws an exception.
   *
   * @param signal The signal to handle.
   * @param signalHandler The handler to install.
   */
public void installHandler(Signal signal, final SignalHandler signalHandler) {
    final AtomicReference<SignalHandler> previousHandlerReference = new AtomicReference<>();
    previousHandlerReference.set(handlerInstaller.install(signal, new SignalHandler() {

        @Override
        public void handle(Signal signal) {
            signalHandler.handle(signal);
            SignalHandler previousHandler = previousHandlerReference.get();
            if (previousHandler != null) {
                previousHandler.handle(signal);
            }
        }
    }));
}
Also used : Signal(sun.misc.Signal) SignalHandler(sun.misc.SignalHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 5 with Signal

use of sun.misc.Signal in project questdb by bluestreak01.

the class BootstrapMain method main.

public static void main(String[] args) throws Exception {
    System.err.printf("QuestDB HTTP Server %s%nCopyright (C) Appsicle 2014-2018, all rights reserved.%n%n", getVersion());
    if (args.length < 1) {
        System.err.println("Root directory name expected");
        return;
    }
    if (Os.type == Os._32Bit) {
        System.err.println("QuestDB requires 64-bit JVM");
        return;
    }
    final CharSequenceObjHashMap<String> optHash = hashArgs(args);
    // expected flags:
    // -d <root dir> = sets root directory
    // -f = forces copy of site to root directory even if site exists
    // -n = disables handling of HUP signal
    String dir = optHash.get("-d");
    extractSite(dir, optHash.get("-f") != null);
    File conf = new File(dir, "conf/questdb.conf");
    if (!conf.exists()) {
        System.err.println("Configuration file does not exist: " + conf);
        return;
    }
    BootstrapEnv env = new BootstrapEnv();
    // main configuration
    env.configuration = new ServerConfiguration(conf);
    configureLoggers(env.configuration);
    env.dateFormatFactory = new DateFormatFactory();
    env.dateLocaleFactory = DateLocaleFactory.INSTANCE;
    env.typeProbeCollection = new TypeProbeCollection(new File(dir, "conf/date.formats").getAbsolutePath(), env.dateFormatFactory, env.dateLocaleFactory);
    // reader/writer factory and cache
    env.factory = new Factory(env.configuration.getDbPath().getAbsolutePath(), env.configuration.getDbPoolIdleTimeout(), env.configuration.getDbReaderPoolSize(), env.configuration.getDbPoolIdleCheckInterval());
    // URL matcher configuration
    env.matcher = new SimpleUrlMatcher();
    env.matcher.put("/imp", new ImportHandler(env));
    env.matcher.put("/exec", new QueryHandler(env));
    env.matcher.put("/exp", new CsvHandler(env));
    env.matcher.put("/chk", new ExistenceCheckHandler(env));
    env.matcher.setDefaultHandler(new StaticContentHandler(env));
    // server configuration
    // add all other jobs to server as it will be scheduling workers to do them
    final HttpServer server = new HttpServer(env);
    // monitoring setup
    final FactoryEventLogger factoryEventLogger = new FactoryEventLogger(env.factory, 10000000, 5000, MicrosecondClockImpl.INSTANCE);
    ObjHashSet<Job> jobs = server.getJobs();
    jobs.addAll(LogFactory.INSTANCE.getJobs());
    jobs.add(factoryEventLogger);
    env.factory.exportJobs(jobs);
    // welcome message
    CharSink welcome = Misc.getThreadLocalBuilder();
    if (!server.start()) {
        welcome.put("Could not bind socket ").put(env.configuration.getHttpIP()).put(':').put(env.configuration.getHttpPort());
        welcome.put(". Already running?");
        System.err.println(welcome);
        System.out.println(new Date() + " QuestDB failed to start");
    } else {
        welcome.put("Listening on ").put(env.configuration.getHttpIP()).put(':').put(env.configuration.getHttpPort());
        if (env.configuration.getSslConfig().isSecure()) {
            welcome.put(" [HTTPS]");
        } else {
            welcome.put(" [HTTP plain]");
        }
        System.err.println(welcome);
        System.out.println(new Date() + " QuestDB is running");
        if (Os.type != Os.WINDOWS && optHash.get("-n") == null) {
            // suppress HUP signal
            Signal.handle(new Signal("HUP"), signal -> {
            });
        }
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println(new Date() + " QuestDB is shutting down");
            server.halt();
            factoryEventLogger.close();
            env.factory.close();
        }));
    }
}
Also used : CharSink(com.questdb.std.str.CharSink) DateFormatFactory(com.questdb.std.time.DateFormatFactory) Factory(com.questdb.store.factory.Factory) LogFactory(com.questdb.log.LogFactory) DateFormatFactory(com.questdb.std.time.DateFormatFactory) DateLocaleFactory(com.questdb.std.time.DateLocaleFactory) Date(java.util.Date) Signal(sun.misc.Signal) TypeProbeCollection(com.questdb.parser.typeprobe.TypeProbeCollection) HttpServer(com.questdb.net.http.HttpServer) SimpleUrlMatcher(com.questdb.net.http.SimpleUrlMatcher) Job(com.questdb.mp.Job) File(java.io.File)

Aggregations

Signal (sun.misc.Signal)29 SignalHandler (sun.misc.SignalHandler)14 IOException (java.io.IOException)4 Test (org.junit.Test)3 ReporterConfiguration (com.uber.jaeger.Configuration.ReporterConfiguration)2 SamplerConfiguration (com.uber.jaeger.Configuration.SamplerConfiguration)2 ConstSampler (com.uber.jaeger.samplers.ConstSampler)2 LongtimeJavaJob (com.vip.saturn.it.job.LongtimeJavaJob)2 JobConfiguration (com.vip.saturn.job.internal.config.JobConfiguration)2 ActiveSpan (io.opentracing.ActiveSpan)2 GlobalTracer (io.opentracing.util.GlobalTracer)2 BufferedReader (java.io.BufferedReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 Paths (java.nio.file.Paths)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2