Search in sources :

Example 1 with Delegate

use of javax.decorator.Delegate in project indy by Commonjava.

the class IndexingContentManagerDecorator method retrieve.

@Override
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.trace("Looking for indexed path: {} in: {}", path, store.getKey());
    Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD);
    if (transfer != null) {
        logger.debug("Found indexed transfer: {}. Returning.", transfer);
        return transfer;
    }
    StoreType type = store.getKey().getType();
    if (StoreType.group == type) {
        ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
        if (nfc.isMissing(resource)) {
            logger.debug("{} is marked as missing. Returning null.", resource);
            return null;
        }
        logger.debug("No group index hits. Devolving to member store indexes.");
        KeyedLocation location = LocationUtils.toLocation(store);
        SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(location, path, store.getPackageType());
        if (specialPathInfo == null || !specialPathInfo.isMergable()) {
            transfer = getIndexedMemberTransfer((Group) store, path, TransferOperation.DOWNLOAD, (member) -> {
                try {
                    return delegate.retrieve(member, path);
                } catch (IndyWorkflowException e) {
                    logger.error(String.format("Failed to retrieve() for member path: %s:%s. Reason: %s", member.getKey(), path, e.getMessage()), e);
                }
                return null;
            });
            if (transfer != null) {
                nfc.clearMissing(resource);
                return transfer;
            }
            logger.debug("No index hits. Delegating to main content manager for: {} in: {}", path, store);
        } else {
            logger.debug("Merged content. Delegating to main content manager for: {} in: {}", path, store);
            transfer = delegate.retrieve(store, path, eventMetadata);
            if (transfer == null) {
                nfc.addMissing(resource);
            }
            return transfer;
        }
    }
    transfer = delegate.retrieve(store, path, eventMetadata);
    if (transfer != null) {
        logger.debug("Got transfer from delegate: {} (will index)", transfer);
        indexManager.indexTransferIn(transfer, store.getKey());
    }
    logger.debug("Returning transfer: {}", transfer);
    return transfer;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Delegate(javax.decorator.Delegate) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LoggerFactory(org.slf4j.LoggerFactory) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) Any(javax.enterprise.inject.Any) Decorator(javax.decorator.Decorator) StoreKey(org.commonjava.indy.model.core.StoreKey) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) ContentManager(org.commonjava.indy.content.ContentManager) Objects(java.util.Objects) List(java.util.List) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) Group(org.commonjava.indy.model.core.Group) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger)

Aggregations

InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Decorator (javax.decorator.Decorator)1 Delegate (javax.decorator.Delegate)1 Any (javax.enterprise.inject.Any)1 Inject (javax.inject.Inject)1 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 ContentManager (org.commonjava.indy.content.ContentManager)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 StoreDataManager (org.commonjava.indy.data.StoreDataManager)1 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)1 Group (org.commonjava.indy.model.core.Group)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 StoreType (org.commonjava.indy.model.core.StoreType)1 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)1 LocationUtils (org.commonjava.indy.util.LocationUtils)1