Example usage for java.lang RuntimeException addSuppressed

List of usage examples for java.lang RuntimeException addSuppressed

Introduction

In this page you can find the example usage for java.lang RuntimeException addSuppressed.

Prototype

public final synchronized void addSuppressed(Throwable exception) 

Source Link

Document

Appends the specified exception to the exceptions that were suppressed in order to deliver this exception.

Usage

From source file:no.digipost.api.useragreements.client.response.ResponseUtils.java

public static Optional<Duration> parseDelayDurationOfRetryAfterHeader(HttpResponse response, Clock clock) {
    return getValueOfFirstHeader(response, Headers.Retry_After).map(retryAfterValue -> {
        try {//w w w . java 2s  .  c  o  m
            long parsedSeconds = Long.parseLong(retryAfterValue);
            return Duration.ofSeconds(parsedSeconds);
        } catch (NumberFormatException secondsNotParseable) {
            try {
                Instant parsedInstant = RFC_1123_DATE_TIME.parse(retryAfterValue, Instant::from);
                return Duration.between(clock.instant(), parsedInstant);
            } catch (RuntimeException e) {
                e.addSuppressed(secondsNotParseable);
                throw e;
            }
        }
    });
}

From source file:com.addthis.hydra.kafka.consumer.ConsumerUtils.java

public static Map<String, TopicMetadata> getTopicsMetadata(CuratorFramework zkClient, int seedBrokers,
        List<String> topics) {
    Iterator<Node> brokers = KafkaUtils.getSeedKafkaBrokers(zkClient, seedBrokers).values().iterator();
    Map<String, TopicMetadata> metadata = null;
    RuntimeException exception = new RuntimeException();
    // try to get metadata while we havent yet succeeded and still have more brokers to try
    while ((metadata == null) && brokers.hasNext()) {
        try {//from ww  w . j av  a2 s .co m
            Node broker = brokers.next();
            metadata = getTopicsMetadataFromBroker(broker.host(), broker.port(), topics);
        } catch (Exception e) {
            exception.addSuppressed(e);
        }
    }
    if (metadata != null) {
        return metadata;
    }
    throw exception;
}

From source file:no.digipost.api.useragreements.client.ApiService.java

public StreamingRateLimitedResponse<UserId> getAgreementOwners(final SenderId senderId,
        final AgreementType agreementType, final Boolean smsNotificationsEnabled,
        final String requestTrackingId) {
    URIBuilder uriBuilder = new URIBuilder(serviceEndpoint)
            .setPath(userAgreementsPath(senderId) + "/agreement-owners")
            .setParameter(AgreementType.QUERY_PARAM_NAME, agreementType.getType());
    if (smsNotificationsEnabled != null) {
        uriBuilder.setParameter("invoice-sms-notification", smsNotificationsEnabled.toString());
    }/* w w w.  j av  a 2s. co m*/

    HttpGet request = newGetRequest(uriBuilder, requestTrackingId);
    request.setHeader(X_Digipost_UserId, brokerId.serialize());
    CloseableHttpResponse response = null;
    try {
        response = httpClient.execute(request);
        return new StreamingRateLimitedResponse<>(
                mapOkResponseOrThrowException(response, r -> unmarshallEntities(r, AgreementOwners.class)),
                AgreementOwners::getIdsAsStream);
    } catch (IOException ioe) {
        throw new RuntimeIOException(ioe.getMessage(), ioe);
    } catch (RuntimeException rte) {
        if (response != null) {
            try {
                response.close();
            } catch (IOException e) {
                rte.addSuppressed(e);
            }
        }
        throw rte;
    }
}

From source file:org.amplafi.flow.impl.FlowDefinitionsManagerImpl.java

/**
 *
 *///from   w w  w .  j av  a 2 s.c  om
public void initializeService() {
    RuntimeException storedExceptions = null;
    for (String fileName : getFlowsFilenames()) {
        try {
            XmlDefinitionSource definitionSource = new XmlDefinitionSource(fileName);
            addDefinitions(definitionSource);
        } catch (IllegalArgumentException e) {
            if (storedExceptions == null) {
                storedExceptions = e;
            } else {
                storedExceptions.addSuppressed(e);
            }
            getLog().error("Problem reading flow definitions in file '" + fileName + "'", e);
        }
    }
    if (storedExceptions != null) {
        throw storedExceptions;
    }
}

From source file:org.apache.druid.indexer.updater.HadoopConverterJob.java

public static void cleanup(Job job) throws IOException {
    final Path jobDir = getJobPath(job.getJobID(), job.getWorkingDirectory());
    final FileSystem fs = jobDir.getFileSystem(job.getConfiguration());
    RuntimeException e = null;
    try {/*  w w w  .j a va  2s  .c o  m*/
        JobHelper.deleteWithRetry(fs, jobDir, true);
    } catch (RuntimeException ex) {
        e = ex;
    }
    try {
        JobHelper.deleteWithRetry(fs, getJobClassPathDir(job.getJobName(), job.getWorkingDirectory()), true);
    } catch (RuntimeException ex) {
        if (e == null) {
            e = ex;
        } else {
            e.addSuppressed(ex);
        }
    }
    if (e != null) {
        throw e;
    }
}

From source file:org.livespark.test.BaseIntegrationTest.java

protected void runAssertions(final Runnable assertions, int attempts, final long delayInMs,
        final long initDelayInMs) {
    try {//  w  ww  .  ja  v a  2  s .c  o m
        if (initDelayInMs > 0) {
            Thread.sleep(initDelayInMs);
        }
    } catch (Exception e) {
        final RuntimeException wrapper = new RuntimeException(
                "There was an error while trying to sleep before running assertions.", e);
        wrapper.addSuppressed(e);
        throw wrapper;
    }

    do {
        try {
            assertions.run();
            return;
        } catch (AssertionError e) {
            if (--attempts <= 0) {
                throw e;
            } else {
                try {
                    Thread.sleep(delayInMs);
                } catch (Exception ex) {
                    final RuntimeException wrapper = new RuntimeException(
                            "There was an error while trying to sleep between running assertions.", ex);
                    wrapper.addSuppressed(e);
                    throw wrapper;
                }
            }
        }
    } while (true);
}

From source file:org.nuxeo.ecm.core.cache.CacheRegistry.java

public void start() {
    RuntimeException errors = new RuntimeException("Cannot start caches, check suppressed error");
    for (CacheDescriptor desc : caches.values()) {
        try {/*from   w  w  w  . j a  v  a2  s  .co m*/
            desc.start();
        } catch (RuntimeException cause) {
            errors.addSuppressed(cause);
        }
    }
    if (errors.getSuppressed().length > 0) {
        throw errors;
    }
}

From source file:org.nuxeo.ecm.core.cache.CacheRegistry.java

public void stop() {
    RuntimeException errors = new RuntimeException("Cannot stop caches, check suppressed error");
    for (CacheDescriptor desc : caches.values()) {
        try {//from w  w  w.ja  va 2  s  . co  m
            desc.stop();
        } catch (RuntimeException cause) {
            errors.addSuppressed(cause);
        }
    }
    if (errors.getSuppressed().length > 0) {
        throw errors;
    }
}

From source file:org.nuxeo.ecm.core.schema.SchemaManagerImpl.java

protected void recomputeSchemas() {
    schemas.clear();/*from w w w .ja v  a  2s. c om*/
    uriToSchema.clear();
    prefixToSchema.clear();
    RuntimeException errors = new RuntimeException("Cannot load schemas");
    for (SchemaBindingDescriptor sd : allSchemas) {
        try {
            copySchema(sd);
        } catch (Exception error) {
            if (error instanceof InterruptedException) {
                // restore interrupted status
                Thread.currentThread().interrupt();
            }
            errors.addSuppressed(error);
        }
    }
    for (SchemaBindingDescriptor sd : allSchemas) {
        try {
            loadSchema(sd);
        } catch (Exception error) {
            if (error instanceof InterruptedException) {
                // restore interrupted status
                Thread.currentThread().interrupt();
            }
            errors.addSuppressed(error);
        }
    }
    if (errors.getSuppressed().length > 0) {
        throw errors;
    }
}

From source file:org.nuxeo.runtime.jtajca.NuxeoContainer.java

public static synchronized void resetConnectionManager() {
    RuntimeException errors = new RuntimeException("Cannot reset connection managers");
    for (ConnectionManagerWrapper wrapper : connectionManagers.values()) {
        try {/*from   w w  w . j  av a 2s  .c o  m*/
            wrapper.reset();
        } catch (RuntimeException cause) {
            errors.addSuppressed(cause);
        }
    }
    if (errors.getSuppressed().length > 0) {
        throw errors;
    }
}