Example usage for java.util.concurrent CancellationException getMessage

List of usage examples for java.util.concurrent CancellationException getMessage

Introduction

In this page you can find the example usage for java.util.concurrent CancellationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:c3.ops.priam.utils.RetryableCallable.java

public T call() throws Exception {
    int retry = 0;
    int logCounter = 0;
    while (true) {
        try {/*from   ww w.  ja  v  a2s .  c  om*/
            return retriableCall();
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e) {
            retry++;
            if (retry == retrys) {
                throw e;
            }
            logger.error(String.format("Retry #%d for: %s", retry, e.getMessage()));

            if (++logCounter == 1)
                logger.error("Exception --> " + ExceptionUtils.getStackTrace(e));
            Thread.sleep(waitTime);
        } finally {
            forEachExecution();
        }
    }
}

From source file:com.netflix.dynomitemanager.sidecore.utils.RetryableCallable.java

public T call() throws Exception {
    int retry = 0;
    int logCounter = 0;
    while (true) {
        try {/*from w  w w.  j ava  2s .com*/
            return retriableCall();
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e) {
            retry++;
            if (retry == retrys) {
                throw e;
            }
            logger.error(String.format("Retry #%d for: %s", retry, e.getMessage()));

            if (++logCounter == 1)
                logger.error("Exception --> " + ExceptionUtils.getFullStackTrace(e));
            Thread.sleep(waitTime);
        } finally {
            forEachExecution();
        }
    }
}

From source file:c3.ops.priam.utils.BoundedExponentialRetryCallable.java

public T call() throws Exception {
    long delay = min;// ms
    int retry = 0;
    int logCounter = 0;
    while (true) {
        try {//from  w ww  .  j a  v a 2  s.co  m
            return retriableCall();
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e) {
            retry++;

            if (delay < max && retry <= maxRetries) {
                delay *= 2;
                logger.error(String.format("Retry #%d for: %s", retry, e.getMessage()));
                if (++logCounter == 1)
                    logger.info("Exception --> " + ExceptionUtils.getStackTrace(e));
                sleeper.sleep(delay);
            } else if (delay >= max && retry <= maxRetries) {
                logger.error(String.format("Retry #%d for: %s", retry, ExceptionUtils.getStackTrace(e)));
                sleeper.sleep(max);
            } else {
                throw e;
            }
        } finally {
            forEachExecution();
        }
    }
}

From source file:com.netflix.priam.utils.BoundedExponentialRetryCallable.java

public T call() throws Exception {
    long delay = min;// ms
    int retry = 0;
    int logCounter = 0;
    while (true) {
        try {//from  w w w. ja va  2 s .c  om
            return retriableCall();
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e) {
            retry++;

            if (delay < max && retry <= maxRetries) {
                delay *= 2;
                logger.error(String.format("Retry #%d for: %s", retry, e.getMessage()));
                if (++logCounter == 1)
                    logger.info("Exception --> " + ExceptionUtils.getFullStackTrace(e));
                sleeper.sleep(delay);
            } else if (delay >= max && retry <= maxRetries) {
                logger.error(String.format("Retry #%d for: %s", retry, ExceptionUtils.getFullStackTrace(e)));
                sleeper.sleep(max);
            } else {
                throw e;
            }
        } finally {
            forEachExecution();
        }
    }
}

From source file:com.netflix.dynomitemanager.sidecore.utils.BoundedExponentialRetryCallable.java

public T call() throws Exception {
    long delay = min;// ms
    int retry = 0;

    while (true) {
        try {//from w w  w  .  j a  v a2 s .c  o m
            return retriableCall();
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e) {
            retry++;

            if (delay < max && retry <= maxRetries) {
                delay *= 2;
                logger.error(String.format("Retry #%d for: %s", retry, e.getMessage()));
                sleeper.sleep(delay);
            } else if (delay >= max && retry <= maxRetries) {
                logger.error(String.format("Retry #%d for: %s", retry, ExceptionUtils.getFullStackTrace(e)));
                sleeper.sleep(max);
            } else {
                logger.info("Exception --> " + ExceptionUtils.getFullStackTrace(e));
                throw e;
            }
        } finally {
            forEachExecution();
        }
    }
}

From source file:com.diversityarrays.kdxplore.specgroup.SpecimenGroupEditor.java

private void doImportFile(File file) {
    BackgroundTask<List<Specimen>, Void> task = new BackgroundTask<List<Specimen>, Void>(
            "Loading " + file.getName(), true) {

        @Override/*from w  w w .  ja v a  2 s .c om*/
        public List<Specimen> generateResult(Closure<Void> arg) throws Exception {
            return importFile(file);
        }

        @Override
        public void onCancel(CancellationException e) {
            MsgBox.info(SpecimenGroupEditor.this, e.getMessage(), title);
        }

        @Override
        public void onException(Throwable e) {
            MsgBox.error(SpecimenGroupEditor.this, e, title);
        }

        @Override
        public void onTaskComplete(List<Specimen> specs) {
            specimenTableModel.setData(specs);
        }
    };
    backgroundRunner.runBackgroundTask(task);
}

From source file:com.amazonaws.services.simpleworkflow.flow.worker.SynchronousActivityTaskPoller.java

protected void execute(final ActivityTask task) throws Exception {
    String output = null;// w w  w  .jav  a 2 s  . c o  m
    ActivityType activityType = task.getActivityType();
    try {
        ActivityExecutionContext context = new ActivityExecutionContextImpl(service, domain, task);
        ActivityImplementation activityImplementation = activityImplementationFactory
                .getActivityImplementation(activityType);
        if (activityImplementation == null) {
            throw new ActivityFailureException("Unknown activity type: " + activityType);
        }
        output = activityImplementation.execute(context);
        if (!activityImplementation.getExecutionOptions().isManualActivityCompletion()) {
            respondActivityTaskCompletedWithRetry(task.getTaskToken(), output);
        }
    } catch (CancellationException e) {
        respondActivityTaskCanceledWithRetry(task.getTaskToken(), null);
        return;
    } catch (ActivityFailureException e) {
        if (log.isErrorEnabled()) {
            log.error("Failure processing activity task with taskId=" + task.getStartedEventId()
                    + ", workflowGenerationId=" + task.getWorkflowExecution().getWorkflowId() + ", activity="
                    + activityType + ", activityInstanceId=" + task.getActivityId(), e);
        }
        respondActivityTaskFailedWithRetry(task.getTaskToken(), e.getReason(), e.getDetails());
    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error("Failure processing activity task with taskId=" + task.getStartedEventId()
                    + ", workflowGenerationId=" + task.getWorkflowExecution().getWorkflowId() + ", activity="
                    + activityType + ", activityInstanceId=" + task.getActivityId(), e);
        }
        String reason = e.getMessage();
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String details = sw.toString();
        respondActivityTaskFailedWithRetry(task.getTaskToken(), reason, details);
    }
}

From source file:com.diversityarrays.kdxplore.trials.SampleGroupExportDialog.java

private void handleExportAction(boolean closeWhenDone) {

    String filename = filepathText.getText().trim();

    OmittedEntities entities = exportExclusionBox.createOmittedObject(this.excludeThesePlotIds,
            this.excludeTheseTraitIds, this.excludeTheseSampleIds);

    this.excludeTheseTraitIds = entities.omittedTraits;

    final Integer maxDatabaseVersionForWorkPackage = kdsmartVersion3option.isSelected()
            ? WorkPackageFactory.MAX_DBVERSION_FOR_KDSMART_2
            : MIN_DB_VERSION_FOR_KDSMART_3;

    BackgroundTask<File, Void> task = new BackgroundTask<File, Void>("Exporting...", true) {

        @Override/*ww  w  . j a va2s  . co  m*/
        public File generateResult(Closure<Void> publishPartial) throws Exception {

            if (!haveCollectedSamples) {

                // Need the KdxSamples into the sampleGroup
                TrialItemVisitor<Sample> visitor = new TrialItemVisitor<Sample>() {

                    @Override
                    public void setExpectedItemCount(int count) {
                    }

                    @Override
                    public boolean consumeItem(Sample s) throws IOException {
                        if (s instanceof KdxSample) {
                            boolean suppressed = ((KdxSample) s).isSuppressed();
                            if (suppressed) {
                                excludeTheseSampleIds.add(s.getSampleId());
                                return true;
                            }

                            if (!excludeTheseTraitIds.contains(s.getTraitId())
                                    && !excludeThesePlotIds.contains(s.getPlotId())) {
                                sampleGroup.addSample((KdxSample) s);

                            }
                        }
                        return true;
                    }
                };

                kdxploreDatabase.getKDXploreKSmartDatabase().visitSamplesForTrial(
                        SampleGroupChoice.create(sampleGroup.getSampleGroupId()), sampleGroup.getTrialId(),
                        SampleOrder.ALL_UNORDERED, visitor);

                haveCollectedSamples = true;
            }

            return doExport(filename, maxDatabaseVersionForWorkPackage, entities);
        }

        @Override
        public void onCancel(CancellationException e) {
        }

        @Override
        public void onException(Throwable cause) {
            GuiUtil.errorMessage(SampleGroupExportDialog.this, cause, getTitle());
        }

        @Override
        public void onTaskComplete(File result) {
            if (result != null) {
                int answer = JOptionPane.showConfirmDialog(SampleGroupExportDialog.this,
                        "Saved: " + result.getPath() + "\nOpen containing directory?", getTitle(),
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

                if (answer == JOptionPane.YES_OPTION) {
                    try {
                        net.pearcan.util.Util.openFile(result.getParentFile());
                    } catch (IOException e) {
                        GuiUtil.errorMessage(SampleGroupExportDialog.this, e.getMessage(),
                                "Failed: " + getTitle());
                    }
                }

                if (closeWhenDone) {
                    dispose();
                }
            }
        }
    };

    backgroundRunner.runBackgroundTask(task);

}

From source file:org.esxx.Main.java

public static void main(String[] args) {
    // (Try to) Load embedded H2 database JDBC driver into memory
    try {//w  ww.j  a  va 2 s . c  o m
        Class.forName("org.h2.Driver");
    } catch (ClassNotFoundException ignored) {
    }

    Options opt = new Options();
    OptionGroup mode_opt = new OptionGroup();

    // (Remember: -u/--user, -p/--pidfile and -j/jvmargs are used by the wrapper script)
    mode_opt.addOption(new Option("b", "bind", true, ("Listen for FastCGI requests on " + "this <port>")));
    mode_opt.addOption(new Option("A", "ajp", true, ("Listen for AJP13 requests on " + "this <port>")));
    mode_opt.addOption(new Option("H", "http", true, ("Listen for HTTP requests on " + "this <port>")));
    mode_opt.addOption(new Option("s", "script", false, "Force script mode."));
    mode_opt.addOption(new Option("S", "shell", false, "Enter ESXX shell mode."));
    mode_opt.addOption(new Option(null, "db-console", false, "Open H2's database console."));
    mode_opt.addOption(new Option(null, "version", false, "Display version and exit"));

    opt.addOptionGroup(mode_opt);
    opt.addOption("n", "no-handler", true, "FCGI requests are direct, without extra handler");
    opt.addOption("r", "http-root", true, "Set AJP/FCGI/HTTP root directory (or file)");
    //     opt.addOption("d", "enable-debugger", false, "Enable esxx.debug()");
    //     opt.addOption("D", "start-debugger",  false, "Start debugger");
    opt.addOption("?", "help", false, "Show help");

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(opt, args, false);

        int fastcgi_port = -1;
        int ajp_port = -1;
        int http_port = -1;
        boolean run_shell = false;
        String[] script = null;

        if (cmd.hasOption('?')) {
            usage(opt, null, 0);
        }

        if (cmd.hasOption('b')) {
            fastcgi_port = Integer.parseInt(cmd.getOptionValue('b'));
        } else if (cmd.hasOption('A')) {
            ajp_port = Integer.parseInt(cmd.getOptionValue('A'));
        } else if (cmd.hasOption('H')) {
            http_port = Integer.parseInt(cmd.getOptionValue('H'));
        } else if (cmd.hasOption('s')) {
            script = cmd.getArgs();
        } else if (cmd.hasOption('S')) {
            run_shell = true;
        } else if (cmd.hasOption("db-console")) {
            org.h2.tools.Console.main(cmd.getArgs());
            return;
        } else if (cmd.hasOption("version")) {
            Properties p = new Properties();
            p.loadFromXML(Main.class.getResourceAsStream("/rsrc/esxx.properties"));
            System.err.println(p.getProperty("version"));
            return;
        } else {
            // Guess execution mode by looking at FCGI_PORT 
            String fcgi_port = System.getenv("FCGI_PORT");

            if (fcgi_port != null) {
                fastcgi_port = Integer.parseInt(fcgi_port);
            } else {
                // Default mode is to execute a JS script
                script = cmd.getArgs();
            }
        }

        if (script != null) {
            Properties p = System.getProperties();
            String forever = Long.toString(3600 * 24 * 365 * 10 /* 10 years */);

            // "Never" unload Applications in script mode
            p.setProperty("esxx.cache.apps.max_age", forever);

            // Kill process immediately on Ctrl-C
            p.setProperty("esxx.app.clean_shutdown", "false");
        }

        ESXX esxx = ESXX.initInstance(System.getProperties(), null);

        if (script != null || run_shell) {
            // Lower default log level a bit
            esxx.getLogger().setLevel(java.util.logging.Level.INFO);
        }

        esxx.setNoHandlerMode(cmd.getOptionValue('n', "lighttpd.*"));

        // Install our ResponseCache implementation
        //       java.net.ResponseCache.setDefault(new org.esxx.cache.DBResponseCache("/tmp/ESXX.WebCache", 
        //                               Integer.MAX_VALUE,
        //                               Long.MAX_VALUE, 
        //                               Long.MAX_VALUE));

        // Default is to serve the current directory
        URI fs_root_uri = ESXX.createFSRootURI(cmd.getOptionValue('r', ""));

        if (fastcgi_port != -1 && !cmd.hasOption('r')) {
            // If not provided in FastCGI mode, use ${PATH_TRANSLATED}
            fs_root_uri = null;
        }

        if (fastcgi_port != -1) {
            FCGIRequest.runServer(fastcgi_port, fs_root_uri);
        } else if (ajp_port != -1) {
            Jetty.runJettyServer(-1, ajp_port, fs_root_uri);
        } else if (http_port != -1) {
            Jetty.runJettyServer(http_port, -1, fs_root_uri);
        } else if (run_shell) {
            ShellRequest sr = new ShellRequest();
            sr.initRequest();

            ESXX.Workload wl = esxx.addRequest(sr, sr, -1 /* no timeout for the shell */);

            try {
                System.exit((Integer) wl.getResult());
            } catch (java.util.concurrent.CancellationException ex) {
                ex.printStackTrace();
                System.exit(5);
            }
        } else if (script != null && script.length != 0) {
            File file = new File(script[0]);

            ScriptRequest sr = new ScriptRequest();
            sr.initRequest(file.toURI(), script);
            ESXX.Workload wl = esxx.addRequest(sr, sr, -1 /* no timeout for scripts */);

            try {
                System.exit((Integer) wl.getResult());
            } catch (java.util.concurrent.CancellationException ex) {
                ex.printStackTrace();
                System.exit(5);
            }
        } else {
            usage(opt, "Required argument missing", 10);
        }
    } catch (ParseException ex) {
        usage(opt, ex.getMessage(), 10);
    } catch (IOException ex) {
        System.err.println("I/O error: " + ex.getMessage());
        System.exit(20);
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(20);
    }

    System.exit(0);
}