Example usage for com.amazonaws.services.cloudfront.model Paths Paths

List of usage examples for com.amazonaws.services.cloudfront.model Paths Paths

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudfront.model Paths Paths.

Prototype

Paths

Source Link

Usage

From source file:ch.cyberduck.core.cloudfront.CloudFrontDistributionConfiguration.java

License:Open Source License

/**
 * You can make any number of invalidation requests, but you can have only three invalidation requests
 * in progress at one time. Each request can contain up to 1,000 objects to invalidate. If you
 * exceed these limits, you get an error message.
 * <p>//  www . j a  v  a  2  s  .  c om
 * It usually takes 10 to 15 minutes to complete your invalidation request, depending on
 * the size of your request.
 */
@Override
public void invalidate(final Path container, final Distribution.Method method, final List<Path> files,
        final LoginCallback prompt) throws BackgroundException {
    try {
        final Distribution d = this.read(container, method, prompt);
        final List<String> keys = new ArrayList<String>();
        for (Path file : files) {
            if (containerService.isContainer(file)) {
                // To invalidate all of the objects in a distribution
                keys.add(String.format("%s*", String.valueOf(Path.DELIMITER)));
            } else {
                if (file.isDirectory()) {
                    // The *, which replaces 0 or more characters, must be the last character in the invalidation path
                    keys.add(String.format("/%s*", containerService.getKey(file)));
                } else {
                    keys.add(String.format("/%s", containerService.getKey(file)));
                }
            }
        }
        if (keys.isEmpty()) {
            log.warn("No keys selected for invalidation");
        } else {
            final AmazonCloudFront client = client(container);
            client.createInvalidation(new CreateInvalidationRequest(d.getId(),
                    new InvalidationBatch(new Paths().withItems(keys).withQuantity(keys.size()),
                            new AlphanumericRandomStringService().random())));
        }
    } catch (AmazonClientException e) {
        throw new AmazonServiceExceptionMappingService().map("Cannot write CDN configuration", e);
    }
}