Search in sources :

Example 1 with ExistenceJob

use of org.commonjava.maven.galley.spi.transport.ExistenceJob in project galley by Commonjava.

the class ExistenceHandler method exists.

public boolean exists(final ConcreteResource resource, final Transfer transfer, final int timeoutSeconds, final Transport transport, final boolean suppressFailures) throws TransferException {
    if (nfc.isMissing(resource)) {
        logger.debug("NFC: Already marked as missing: {}", resource);
        return false;
    }
    if (transport == null) {
        logger.warn("No transports available to handle: {} with location type: {}", resource, resource.getLocation().getClass().getSimpleName());
        return false;
    }
    logger.debug("EXISTS {}", resource);
    final ExistenceJob job = transport.createExistenceJob(resource, transfer, timeoutSeconds);
    // TODO: execute this stuff in a thread just like downloads/publishes. Requires cache storage...
    try {
        final Boolean result = job.call();
        if (job.getError() != null) {
            logger.debug("NFC: Download error. Marking as missing: {}", resource);
            nfc.addMissing(resource);
            if (!suppressFailures) {
                throw job.getError();
            }
        } else if (result == null) {
            logger.debug("NFC: Download did not complete. Marking as missing: {}", resource);
            nfc.addMissing(resource);
        } else if (!result) {
            logger.debug("NFC: Existence check returned false. Marking as missing: {}", resource);
            nfc.addMissing(resource);
        }
        return result;
    } catch (final TimeoutException e) {
        if (!suppressFailures) {
            throw new TransferTimeoutException(transfer, "Timed-out existence check: {}. Reason: {}", e, resource, e.getMessage());
        }
    } catch (final TransferException e) {
        if (!suppressFailures) {
            throw e;
        }
    } catch (final Exception e) {
        if (!suppressFailures) {
            throw new TransferException("Failed existence check: {}. Reason: {}", e, resource, e.getMessage());
        }
    }
    return false;
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TransferException(org.commonjava.maven.galley.TransferException) ExistenceJob(org.commonjava.maven.galley.spi.transport.ExistenceJob) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) TransferException(org.commonjava.maven.galley.TransferException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

TimeoutException (java.util.concurrent.TimeoutException)1 TransferException (org.commonjava.maven.galley.TransferException)1 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)1 ExistenceJob (org.commonjava.maven.galley.spi.transport.ExistenceJob)1