Search in sources :

Example 16 with SignalHandler

use of sun.misc.SignalHandler in project jdepth by Crab2died.

the class SignalCatch method main.

public static void main(String... args) throws IOException {
    SignalHandler handler = new SignalCatch();
    handler.handle(new Signal("TERM"));
    handler.handle(new Signal("SEGV"));
    handler.handle(new Signal("ILL"));
    handler.handle(new Signal("FPE"));
    handler.handle(new Signal("ABRT"));
    handler.handle(new Signal("INT"));
    handler.handle(new Signal("BREAK"));
}
Also used : Signal(sun.misc.Signal) SignalHandler(sun.misc.SignalHandler)

Example 17 with SignalHandler

use of sun.misc.SignalHandler in project orientdb by orientechnologies.

the class OSignalHandler method listenTo.

public void listenTo(final String name, final SignalHandler iListener) {
    Signal signal = new Signal(name);
    SignalHandler redefinedHandler = Signal.handle(signal, iListener);
    if (redefinedHandler != null) {
        redefinedHandlers.put(signal, redefinedHandler);
    }
}
Also used : Signal(sun.misc.Signal) SignalHandler(sun.misc.SignalHandler)

Example 18 with SignalHandler

use of sun.misc.SignalHandler in project batfish by batfish.

the class Driver method mainRunWorkService.

private static void mainRunWorkService() {
    if (_mainSettings.getTracingEnable() && !GlobalTracer.isRegistered()) {
        initTracer();
    }
    String protocol = _mainSettings.getSslDisable() ? "http" : "https";
    String baseUrl = String.format("%s://%s", protocol, _mainSettings.getServiceBindHost());
    URI baseUri = UriBuilder.fromUri(baseUrl).port(_mainSettings.getServicePort()).build();
    _mainLogger.debug(String.format("Starting server at %s\n", baseUri));
    ResourceConfig rc = new ResourceConfig(Service.class).register(new JettisonFeature());
    if (_mainSettings.getTracingEnable()) {
        rc.register(ServerTracingDynamicFeature.class);
    }
    try {
        if (_mainSettings.getSslDisable()) {
            GrizzlyHttpServerFactory.createHttpServer(baseUri, rc);
        } else {
            CommonUtil.startSslServer(rc, baseUri, _mainSettings.getSslKeystoreFile(), _mainSettings.getSslKeystorePassword(), _mainSettings.getSslTrustAllCerts(), _mainSettings.getSslTruststoreFile(), _mainSettings.getSslTruststorePassword(), ConfigurationLocator.class, Driver.class);
        }
        if (_mainSettings.getCoordinatorRegister()) {
            // this function does not return until registration succeeds
            registerWithCoordinatorPersistent();
        }
        if (_mainSettings.getParentPid() > 0) {
            if (SystemUtils.IS_OS_WINDOWS) {
                _mainLogger.errorf("Parent process monitoring is not supported on Windows. We'll live without it.");
            } else {
                Executors.newScheduledThreadPool(1).scheduleAtFixedRate(new CheckParentProcessTask(_mainSettings.getParentPid()), 0, PARENT_CHECK_INTERVAL_MS, TimeUnit.MILLISECONDS);
                SignalHandler handler = signal -> _mainLogger.infof("BFS: Ignoring signal %s\n", signal);
                Signal.handle(new Signal("INT"), handler);
            }
        }
        // sleep indefinitely, check for parent pid and coordinator each time
        while (true) {
            Thread.sleep(COORDINATOR_CHECK_INTERVAL_MS);
            /*
         * every time we wake up, we check if the coordinator has polled us recently
         * if not, re-register the service. the coordinator might have died and come back.
         */
            if (_mainSettings.getCoordinatorRegister() && new Date().getTime() - _lastPollFromCoordinator.getTime() > COORDINATOR_POLL_TIMEOUT_MS) {
                // this function does not return until registration succeeds
                registerWithCoordinatorPersistent();
            }
        }
    } catch (ProcessingException e) {
        String msg = "FATAL ERROR: " + e.getMessage() + "\n";
        _mainLogger.error(msg);
        System.exit(1);
    } catch (Exception ex) {
        String stackTrace = ExceptionUtils.getStackTrace(ex);
        _mainLogger.error(stackTrace);
        System.exit(1);
    }
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) ConfigurationLocator(org.batfish.config.ConfigurationLocator) LRUMap(org.apache.commons.collections4.map.LRUMap) BfConsts(org.batfish.common.BfConsts) MediaType(javax.ws.rs.core.MediaType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReporterConfiguration(com.uber.jaeger.Configuration.ReporterConfiguration) References(io.opentracing.References) Answer(org.batfish.datamodel.answers.Answer) Map(java.util.Map) RoutesByVrf(org.batfish.datamodel.collections.RoutesByVrf) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Signal(sun.misc.Signal) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) RuntimeMXBean(java.lang.management.RuntimeMXBean) DataPlane(org.batfish.datamodel.DataPlane) Redirect(java.lang.ProcessBuilder.Redirect) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) TaskStatus(org.batfish.common.BfConsts.TaskStatus) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Logger(java.util.logging.Logger) EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings) Task(org.batfish.common.Task) Executors(java.util.concurrent.Executors) Settings(org.batfish.config.Settings) List(java.util.List) Response(javax.ws.rs.core.Response) JettisonFeature(org.glassfish.jersey.jettison.JettisonFeature) ConstSampler(com.uber.jaeger.samplers.ConstSampler) CoordConsts(org.batfish.common.CoordConsts) ProcessingException(javax.ws.rs.ProcessingException) CacheBuilder(com.google.common.cache.CacheBuilder) SortedMap(java.util.SortedMap) QuestionException(org.batfish.common.QuestionException) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) BatfishLogger(org.batfish.common.BatfishLogger) SignalHandler(sun.misc.SignalHandler) SamplerConfiguration(com.uber.jaeger.Configuration.SamplerConfiguration) ServerTracingDynamicFeature(io.opentracing.contrib.jaxrs2.server.ServerTracingDynamicFeature) ForwardingAnalysis(org.batfish.datamodel.ForwardingAnalysis) CommonUtil(org.batfish.common.util.CommonUtil) Client(javax.ws.rs.client.Client) HashMap(java.util.HashMap) BatfishException(org.batfish.common.BatfishException) ConcurrentMap(java.util.concurrent.ConcurrentMap) Level(java.util.logging.Level) TestrigSettings(org.batfish.config.Settings.TestrigSettings) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf) ImmutableList(com.google.common.collect.ImmutableList) Version(org.batfish.common.Version) Configuration(org.batfish.datamodel.Configuration) ManagementFactory(java.lang.management.ManagementFactory) Nullable(javax.annotation.Nullable) SystemUtils(org.apache.commons.lang3.SystemUtils) GlobalTracer(io.opentracing.util.GlobalTracer) IOException(java.io.IOException) JSONArray(org.codehaus.jettison.json.JSONArray) InputStreamReader(java.io.InputStreamReader) AnswerStatus(org.batfish.datamodel.answers.AnswerStatus) SpanContext(io.opentracing.SpanContext) TimeUnit(java.util.concurrent.TimeUnit) Batch(org.batfish.common.Task.Batch) CleanBatfishException(org.batfish.common.CleanBatfishException) Paths(java.nio.file.Paths) Snapshot(org.batfish.common.Snapshot) ActiveSpan(io.opentracing.ActiveSpan) GrizzlyHttpServerFactory(org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory) BufferedReader(java.io.BufferedReader) WebTarget(javax.ws.rs.client.WebTarget) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) Signal(sun.misc.Signal) SignalHandler(sun.misc.SignalHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) JettisonFeature(org.glassfish.jersey.jettison.JettisonFeature) URI(java.net.URI) Date(java.util.Date) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ProcessingException(javax.ws.rs.ProcessingException) QuestionException(org.batfish.common.QuestionException) BatfishException(org.batfish.common.BatfishException) IOException(java.io.IOException) CleanBatfishException(org.batfish.common.CleanBatfishException) ProcessingException(javax.ws.rs.ProcessingException)

Example 19 with SignalHandler

use of sun.misc.SignalHandler in project batfish by batfish.

the class Client method runInteractive.

private void runInteractive() {
    SignalHandler handler = signal -> _logger.debugf("Client: Ignoring signal: %s\n", signal);
    Signal.handle(new Signal("INT"), handler);
    try {
        while (!_exit) {
            try {
                String rawLine = _reader.readLine("batfish> ");
                if (rawLine == null) {
                    break;
                }
                processCommand(rawLine);
            } catch (UserInterruptException e) {
                continue;
            }
        }
    } catch (EndOfFileException e) {
    // ignored
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        try {
            _reader.getHistory().save();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : Arrays(java.util.Arrays) RunMode(org.batfish.client.config.Settings.RunMode) BfConsts(org.batfish.common.BfConsts) Duration(java.time.Duration) Map(java.util.Map) Signal(sun.misc.Signal) JsonNode(com.fasterxml.jackson.databind.JsonNode) Settings(org.batfish.client.config.Settings) Pair(org.batfish.common.Pair) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) PrintWriter(java.io.PrintWriter) InstanceData(org.batfish.datamodel.questions.Question.InstanceData) LineReader(org.jline.reader.LineReader) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) FileVisitResult(java.nio.file.FileVisitResult) WorkItemBuilder(org.batfish.common.util.WorkItemBuilder) EndOfFileException(org.jline.reader.EndOfFileException) Question(org.batfish.datamodel.questions.Question) CoordConsts(org.batfish.common.CoordConsts) AnswerElement(org.batfish.datamodel.answers.AnswerElement) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) SignalHandler(sun.misc.SignalHandler) Capability(org.jline.utils.InfoCmp.Capability) CommonUtil(org.batfish.common.util.CommonUtil) TreeSet(java.util.TreeSet) Protocol(org.batfish.datamodel.Protocol) AbstractClient(org.batfish.common.plugin.AbstractClient) Nullable(javax.annotation.Nullable) Terminal(org.jline.terminal.Terminal) WorkItem(org.batfish.common.WorkItem) Files(java.nio.file.Files) FOLLOW_LINKS(java.nio.file.FileVisitOption.FOLLOW_LINKS) JSONObject(org.codehaus.jettison.json.JSONObject) IOException(java.io.IOException) JSONArray(org.codehaus.jettison.json.JSONArray) InputStreamReader(java.io.InputStreamReader) ArgumentCompleter(org.jline.reader.impl.completer.ArgumentCompleter) File(java.io.File) AnswerStatus(org.batfish.datamodel.answers.AnswerStatus) TerminalBuilder(org.jline.terminal.TerminalBuilder) TreeMap(java.util.TreeMap) Paths(java.nio.file.Paths) JSONException(org.codehaus.jettison.json.JSONException) UserInterruptException(org.jline.reader.UserInterruptException) ActiveSpan(io.opentracing.ActiveSpan) BufferedReader(java.io.BufferedReader) Container(org.batfish.common.Container) UnzipUtility(org.batfish.common.util.UnzipUtility) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) IpProtocol(org.batfish.datamodel.IpProtocol) SortedSet(java.util.SortedSet) LineReaderBuilder(org.jline.reader.LineReaderBuilder) IClient(org.batfish.common.plugin.IClient) Edge(org.batfish.datamodel.Edge) TestComparisonMode(org.batfish.client.Command.TestComparisonMode) LoadQuestionAnswerElement(org.batfish.client.answer.LoadQuestionAnswerElement) HashMultimap(com.google.common.collect.HashMultimap) ReporterConfiguration(com.uber.jaeger.Configuration.ReporterConfiguration) Answer(org.batfish.datamodel.answers.Answer) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) PatternSyntaxException(java.util.regex.PatternSyntaxException) NullCompleter(org.jline.reader.impl.completer.NullCompleter) UUID(java.util.UUID) Task(org.batfish.common.Task) Sets(com.google.common.collect.Sets) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) Variable(org.batfish.datamodel.questions.Question.InstanceData.Variable) ConstSampler(com.uber.jaeger.samplers.ConstSampler) Entry(java.util.Map.Entry) JSONTokener(org.codehaus.jettison.json.JSONTokener) WorkStatusCode(org.batfish.common.CoordConsts.WorkStatusCode) JsonSchemaGenerator(com.kjetland.jackson.jsonSchema.JsonSchemaGenerator) Pattern(java.util.regex.Pattern) IpWildcard(org.batfish.datamodel.IpWildcard) BatfishLogger(org.batfish.common.BatfishLogger) Ip(org.batfish.datamodel.Ip) SamplerConfiguration(com.uber.jaeger.Configuration.SamplerConfiguration) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) HashMap(java.util.HashMap) BatfishException(org.batfish.common.BatfishException) Multimap(com.google.common.collect.Multimap) HashSet(java.util.HashSet) WorkStatus(org.batfish.datamodel.pojo.WorkStatus) Version(org.batfish.common.Version) BatfishObjectMapper(org.batfish.common.util.BatfishObjectMapper) SubRange(org.batfish.datamodel.SubRange) Configuration(org.batfish.datamodel.Configuration) LinkedList(java.util.LinkedList) Backoff(org.batfish.common.util.Backoff) InitEnvironmentParams(org.batfish.client.params.InitEnvironmentParams) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) ZipUtility(org.batfish.common.util.ZipUtility) PrefixRange(org.batfish.datamodel.PrefixRange) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) GlobalTracer(io.opentracing.util.GlobalTracer) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Batch(org.batfish.common.Task.Batch) Option(org.jline.reader.LineReader.Option) FileReader(java.io.FileReader) Prefix(org.batfish.datamodel.Prefix) Signal(sun.misc.Signal) EndOfFileException(org.jline.reader.EndOfFileException) SignalHandler(sun.misc.SignalHandler) IOException(java.io.IOException) UserInterruptException(org.jline.reader.UserInterruptException)

Example 20 with SignalHandler

use of sun.misc.SignalHandler in project presto by prestodb.

the class QueryPreprocessor method preprocessQuery.

public static String preprocessQuery(Optional<String> catalog, Optional<String> schema, String query, List<String> preprocessorCommand, Duration timeout) throws QueryPreprocessorException {
    Thread clientThread = Thread.currentThread();
    SignalHandler oldHandler = Signal.handle(SIGINT, signal -> clientThread.interrupt());
    try {
        if (REAL_TERMINAL) {
            System.out.print(PREPROCESSING_QUERY_MESSAGE);
            System.out.flush();
        }
        return preprocessQueryInternal(catalog, schema, query, preprocessorCommand, timeout);
    } finally {
        if (REAL_TERMINAL) {
            System.out.print("\r" + Strings.repeat(" ", PREPROCESSING_QUERY_MESSAGE.length()) + "\r");
            System.out.flush();
        }
        Signal.handle(SIGINT, oldHandler);
        // clear interrupt status
        Thread.interrupted();
    }
}
Also used : SignalHandler(sun.misc.SignalHandler)

Aggregations

SignalHandler (sun.misc.SignalHandler)20 Signal (sun.misc.Signal)15 ReporterConfiguration (com.uber.jaeger.Configuration.ReporterConfiguration)2 SamplerConfiguration (com.uber.jaeger.Configuration.SamplerConfiguration)2 ConstSampler (com.uber.jaeger.samplers.ConstSampler)2 ActiveSpan (io.opentracing.ActiveSpan)2 GlobalTracer (io.opentracing.util.GlobalTracer)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Nullable (javax.annotation.Nullable)2 ExceptionUtils (org.apache.commons.lang3.exception.ExceptionUtils)2 BatfishException (org.batfish.common.BatfishException)2