Search in sources :

Example 1 with RHostedFacet

use of org.sonatype.nexus.repository.r.RHostedFacet in project nexus-repository-r by sonatype-nexus-community.

the class RPackagesBuilderFacetImpl method on.

/**
 * Listen for invalidation of the metadata, wait a configured time and then rebuild. The waiting allows throwing away
 * of subsequent events to reduce the number of rebuilds if multiple archives are being uploaded. This method must NOT
 * be allowed to process concurrent events as race conditions may result when rebuilding the data.
 */
@Subscribe
public void on(final RMetadataInvalidationEvent event) {
    if (getRepository().getName().equals(event.getRepositoryName())) {
        try {
            waiting = true;
            Thread.sleep(interval);
        } catch (InterruptedException e) {
            log.warn("R invalidation thread interrupted on repository {}, proceeding with invalidation", getRepository().getName());
            Thread.currentThread().interrupt();
        }
        waiting = false;
        log.info("Rebuilding R PACKAGES.gz metadata for repository {}", getRepository().getName());
        UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
        try {
            RHostedFacet hostedFacet = getRepository().facet(RHostedFacet.class);
            hostedFacet.buildAndPutPackagesGz(event.getBasePath());
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        } finally {
            UnitOfWork.end();
        }
    }
}
Also used : RHostedFacet(org.sonatype.nexus.repository.r.RHostedFacet) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 RHostedFacet (org.sonatype.nexus.repository.r.RHostedFacet)1