Example usage for java.util.concurrent ExecutionException getLocalizedMessage

List of usage examples for java.util.concurrent ExecutionException getLocalizedMessage

Introduction

In this page you can find the example usage for java.util.concurrent ExecutionException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:be.roots.taconic.pricingguide.respository.TemplateRepositoryImpl.java

@Override
public byte[] findOne(String templateUrl) {
    try {//  w w  w  . j  a va 2 s . c  o m
        return templateLoadingCache.get(templateUrl);
    } catch (ExecutionException e) {
        LOGGER.error(e.getLocalizedMessage(), e);
    }
    return null;
}

From source file:it.geosolutions.tools.io.CopyTreeTest.java

@Test
public void copyTreeTest() throws Exception {
    LOGGER.info("START: CopyTreeTest");
    File srcMount = TestData.file(this, ".");
    CopyTree act = new CopyTree(
            FileFilterUtils.or(FileFilterUtils.directoryFileFilter(), FileFilterUtils.fileFileFilter()), cs,
            srcMount, destMount);/*  w w w . j ava  2  s. c  o  m*/
    act.addCollectingListener(new DefaultProgress("COLLECTING"));
    act.addCopyListener(new DefaultProgress("COPY"));
    int workSize = act.copy();
    try {
        while (workSize-- > 0) {
            Future<File> future = cs.take();
            try {
                LOGGER.info("copied file: " + future.get());
            } catch (ExecutionException e) {
                LOGGER.info(e.getLocalizedMessage(), e);
                Assert.fail();
            }
        }
    } catch (InterruptedException e) {
        LOGGER.info(e.getLocalizedMessage(), e);
        Assert.fail();
    }
    LOGGER.info("STOP: CopyTreeTest");
}

From source file:org.apache.sling.maven.slingstart.run.StartMojo.java

/**
 * @see org.apache.maven.plugin.Mojo#execute()
 *//*from   w  ww .  j a v a2  s .  co  m*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (this.skipLaunchpad) {
        this.getLog().info("Executing of the start launchpad mojo is disabled by configuration.");
        return;
    }

    // delete properties
    if (systemPropertiesFile != null && systemPropertiesFile.exists()) {
        FileUtils.deleteQuietly(this.systemPropertiesFile);
    }

    // get configurations
    final Collection<ServerConfiguration> configurations = getLaunchpadConfigurations();

    // create the common environment
    final LaunchpadEnvironment env = new LaunchpadEnvironment(this.findLaunchpadJar(),
            this.cleanWorkingDirectory, !this.keepLaunchpadRunning, this.launchpadReadyTimeOutSec, this.debug);

    // create callables
    final Collection<LauncherCallable> tasks = new LinkedList<LauncherCallable>();

    for (final ServerConfiguration launchpadConfiguration : configurations) {
        validateConfiguration(launchpadConfiguration);

        tasks.add(createTask(launchpadConfiguration, env));
    }

    // create the launchpad runner properties
    this.createLaunchpadRunnerProperties(configurations);

    if (parallelExecution) {
        // ExecutorService for starting launchpad instances in parallel
        final ExecutorService executor = Executors.newCachedThreadPool();
        try {
            final List<Future<ProcessDescription>> resultsCollector = executor.invokeAll(tasks);
            for (final Future<ProcessDescription> future : resultsCollector) {
                try {
                    if (null == future.get()) {
                        throw new MojoExecutionException("Cannot start all the instances");
                    }
                } catch (final ExecutionException e) {
                    throw new MojoExecutionException(e.getLocalizedMessage(), e);
                }
            }
        } catch (final InterruptedException e) {
            throw new MojoExecutionException(e.getLocalizedMessage(), e);
        }
    } else {
        for (final LauncherCallable task : tasks) {
            try {
                if (null == task.call()) {
                    throw new MojoExecutionException("Cannot start all the instances");
                }
            } catch (final Exception e) {
                throw new MojoExecutionException(e.getLocalizedMessage(), e);
            }
        }
    }
    if (this.keepLaunchpadRunning) {
        getLog().info("Press CTRL-C to stop launchpad instance(s)...");
        while (true && this.isRunning(tasks)) {
            try {
                Thread.sleep(5000);
            } catch (final InterruptedException ie) {
                break;
            }
        }
    }
}

From source file:org.eclipse.smarthome.binding.openweathermap.internal.connection.OpenWeatherMapConnection.java

private String getResponse(String url) {
    try {//  ww  w.  j  a  v  a  2  s .c om
        if (logger.isTraceEnabled()) {
            logger.trace("OpenWeatherMap request: URL = '{}'", uglifyApikey(url));
        }
        ContentResponse contentResponse = httpClient.newRequest(url).method(GET).timeout(10, TimeUnit.SECONDS)
                .send();
        int httpStatus = contentResponse.getStatus();
        String content = contentResponse.getContentAsString();
        String errorMessage = StringUtils.EMPTY;
        logger.trace("OpenWeatherMap response: status = {}, content = '{}'", httpStatus, content);
        switch (httpStatus) {
        case OK_200:
            return content;
        case BAD_REQUEST_400:
        case UNAUTHORIZED_401:
        case NOT_FOUND_404:
            errorMessage = getErrorMessage(content);
            logger.debug("OpenWeatherMap server responded with status code {}: {}", httpStatus, errorMessage);
            throw new OpenWeatherMapConfigurationException(errorMessage);
        case TOO_MANY_REQUESTS_429:
            // TODO disable refresh job temporarily (see https://openweathermap.org/appid#Accesslimitation)
        default:
            errorMessage = getErrorMessage(content);
            logger.debug("OpenWeatherMap server responded with status code {}: {}", httpStatus, errorMessage);
            throw new OpenWeatherMapCommunicationException(errorMessage);
        }
    } catch (ExecutionException e) {
        String errorMessage = e.getLocalizedMessage();
        logger.trace("Exception occurred during execution: {}", errorMessage, e);
        if (e.getCause() instanceof HttpResponseException) {
            logger.debug("OpenWeatherMap server responded with status code {}: Invalid API key.",
                    UNAUTHORIZED_401);
            throw new OpenWeatherMapConfigurationException("@text/offline.conf-error-invalid-apikey",
                    e.getCause());
        } else {
            throw new OpenWeatherMapCommunicationException(errorMessage, e.getCause());
        }
    } catch (InterruptedException | TimeoutException e) {
        logger.debug("Exception occurred during execution: {}", e.getLocalizedMessage(), e);
        throw new OpenWeatherMapCommunicationException(e.getLocalizedMessage(), e.getCause());
    }
}

From source file:org.geoserver.bkprst.RestoreTask.java

@Override
public void run() {

    // If previous' backup info cannot be read, aborts the restore
    // Writes info about backup in a file
    BackupTask backupInfo = this.readBackupInfo(this.path);
    if (backupInfo == null) {
        LOGGER.severe("Backup data info were not written properly, the restore will not start");
        this.state = BrTaskState.FAILED;
        return;/*  w w w  .ja v a2 s  . com*/
    }

    // Sets up the filter to exclude some directories according to the previous backup info
    IOFileFilter excludeFilter = this.getExcludeFilter(backupInfo.includeData, backupInfo.includeGwc,
            backupInfo.includeLog);

    // Sets up source and destination
    File srcMount = new File(this.path);
    File trgMount = this.dataRoot.root();

    // Sets transaction
    this.trans = new RestoreTransaction(this, srcMount, trgMount, excludeFilter);

    try {
        // Start transanction
        this.trans.start();
        if (checkForHalt()) {
            return;
        }

        // Sets up the copy task
        ExecutorService ex = Executors.newFixedThreadPool(2);
        if (ex == null || ex.isTerminated()) {
            throw new IllegalArgumentException(
                    "Unable to run asynchronously using a terminated or null ThreadPoolExecutor");
        }
        ExecutorCompletionService<File> cs = new ExecutorCompletionService<File>(ex);

        this.act = new CopyTree(excludeFilter, cs, srcMount, trgMount);
        this.act.addCopyListener(new DefaultProgress(this.id.toString()) {
            public void onUpdateProgress(float percent) {
                super.onUpdateProgress(percent);
                progress = percent;
            }
        });

        // Starts restore
        int workSize = this.act.copy();
        LOGGER.info("Restore " + this.id + " has started");
        this.startTime = new Date();
        this.state = BrTaskState.RUNNING;

        // This is to keep track af restore advancement
        while (workSize-- > 0) {
            Future<File> future = cs.take();
            try {
                LOGGER.info("copied file: " + future.get());
            } catch (ExecutionException e) {

                LOGGER.log(Level.INFO, e.getLocalizedMessage(), e);
            }
            if (checkForHalt()) {
                ex.shutdown();
                if (!ex.awaitTermination(5, TimeUnit.SECONDS)) {
                    throw new RuntimeException("Unable to stop backup task");
                }
                return;
            }
        }

        // Restore completed
        this.trans.commit();

        // reload the config from disk
        getGeoServer().reload();
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);

        // In case of errors, rollback
        this.trans.rollback();
    } finally {
        haltSemaphore.release();
    }
}

From source file:org.openhab.binding.darksky.internal.connection.DarkSkyConnection.java

private String getResponse(String url) {
    try {/*  w w w  .j a va2 s  .  c  om*/
        if (logger.isTraceEnabled()) {
            logger.trace("Dark Sky request: URL = '{}'", uglifyApikey(url));
        }
        ContentResponse contentResponse = httpClient.newRequest(url).method(GET).timeout(10, TimeUnit.SECONDS)
                .send();
        int httpStatus = contentResponse.getStatus();
        String content = contentResponse.getContentAsString();
        logger.trace("Dark Sky response: status = {}, content = '{}'", httpStatus, content);
        switch (httpStatus) {
        case OK_200:
            return content;
        case BAD_REQUEST_400:
        case UNAUTHORIZED_401:
        case NOT_FOUND_404:
            logger.debug("Dark Sky server responded with status code {}: {}", httpStatus, content);
            throw new DarkSkyConfigurationException(content);
        default:
            logger.debug("Dark Sky server responded with status code {}: {}", httpStatus, content);
            throw new DarkSkyCommunicationException(content);
        }
    } catch (ExecutionException e) {
        String errorMessage = e.getLocalizedMessage();
        logger.trace("Exception occurred during execution: {}", errorMessage, e);
        if (e.getCause() instanceof HttpResponseException) {
            logger.debug("Dark Sky server responded with status code {}: Invalid API key.", UNAUTHORIZED_401);
            throw new DarkSkyConfigurationException("@text/offline.conf-error-invalid-apikey", e.getCause());
        } else {
            throw new DarkSkyCommunicationException(errorMessage, e.getCause());
        }
    } catch (InterruptedException | TimeoutException e) {
        logger.debug("Exception occurred during execution: {}", e.getLocalizedMessage(), e);
        throw new DarkSkyCommunicationException(e.getLocalizedMessage(), e.getCause());
    }
}