use of org.commonjava.maven.galley.event.FileErrorEvent in project galley by Commonjava.
the class TransferManagerImpl method retrieve.
@Override
public Transfer retrieve(final ConcreteResource resource, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
// logger.info( "Attempting to resolve: {}", resource );
// TODO: Handle the case where storage isn't allowed?
// NOTE: This would expand the notion out from simply:
// "don't allow storing new stuff"
// to:
// "don't ever cache this stuff"
Transfer target = null;
try {
// TODO: (see above re:storing) Handle things like local archives that really don't need to be cached...
target = getCacheReference(resource);
if (target.exists()) {
logger.debug("Using cached copy of: {}", target);
return target;
}
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(resource, eventMetadata.getPackageType());
if (!resource.allowsDownloading() || (specialPathInfo != null && !specialPathInfo.isRetrievable())) {
logger.debug("Download not allowed for: {}. Returning null transfer.", resource);
return null;
}
final Transfer retrieved = downloader.download(resource, target, getTimeoutSeconds(resource), getTransport(resource), suppressFailures, eventMetadata);
if (retrieved != null && retrieved.exists() && !target.equals(retrieved)) {
if (specialPathInfo == null || specialPathInfo.isCachable()) {
cacheProvider.createAlias(retrieved.getResource(), target.getResource());
}
}
if (target.exists()) {
logger.debug("DOWNLOADED: {}", resource);
return target;
} else {
logger.debug("NOT DOWNLOADED: {}", resource);
return null;
}
} catch (final TransferException e) {
fileEventManager.fire(new FileErrorEvent(target, e, eventMetadata));
throw e;
} catch (final IOException e) {
final TransferException error = new TransferException("Failed to download: {}. Reason: {}", e, resource, e.getMessage());
fileEventManager.fire(new FileErrorEvent(target, error, eventMetadata));
throw error;
}
}
use of org.commonjava.maven.galley.event.FileErrorEvent in project galley by Commonjava.
the class Transfer method openOutputStream.
public OutputStream openOutputStream(final TransferOperation accessType, final boolean fireEvents, final EventMetadata eventMetadata) throws IOException {
provider.waitForWriteUnlock(resource);
try {
provider.lockWrite(resource);
OutputStream stream = provider.openOutputStream(resource);
if (stream == null) {
return null;
}
final TransferUnlocker unlocker = new TransferUnlocker(resource, provider);
if (fireEvents) {
logger.info("Wrapping output stream to: {} using event metadata: {}", this, eventMetadata);
stream = new TransferOutputStream(stream, unlocker, new FileStorageEvent(accessType, this, eventMetadata), fileEventManager);
} else {
logger.info("Wrapping output stream to: {} WITHOUT event metadata", this);
stream = new TransferOutputStream(stream, unlocker);
}
stream = decorator == null ? stream : decorator.decorateWrite(stream, this, accessType, eventMetadata);
return stream;
} catch (final IOException e) {
if (fireEvents) {
fileEventManager.fire(new FileErrorEvent(this, e, eventMetadata));
}
throw e;
}
}
use of org.commonjava.maven.galley.event.FileErrorEvent in project galley by Commonjava.
the class Transfer method delete.
public boolean delete(final boolean fireEvents, final EventMetadata eventMetadata) throws IOException {
provider.waitForWriteUnlock(resource);
try {
if (decorator != null) {
decorator.decorateDelete(this, eventMetadata);
}
Logger contentLogger = LoggerFactory.getLogger(DELETE_CONTENT_LOG);
if (contentLogger.isTraceEnabled()) {
contentLogger.trace("Starting delete of: {} ({}) from:\n ", resource, eventMetadata, join(Thread.currentThread().getStackTrace(), "\n "));
} else {
contentLogger.info("Starting delete of: {} ({})", resource, eventMetadata);
}
final boolean deleted = provider.delete(resource);
if (deleted) {
contentLogger.info("Finished delete of: {}", resource);
if (fireEvents) {
fileEventManager.fire(new FileDeletionEvent(this, eventMetadata));
}
} else {
contentLogger.info("Failed to delete: {}", resource);
}
return deleted;
} catch (final IOException e) {
if (fireEvents) {
fileEventManager.fire(new FileErrorEvent(this, e, eventMetadata));
}
throw e;
}
}
use of org.commonjava.maven.galley.event.FileErrorEvent in project galley by Commonjava.
the class Transfer method openInputStream.
public InputStream openInputStream(final boolean fireEvents, final EventMetadata eventMetadata) throws IOException {
provider.waitForReadUnlock(resource);
try {
InputStream stream = provider.openInputStream(resource);
if (stream == null) {
return null;
}
if (fireEvents) {
stream = new TransferInputStream(stream, new FileAccessEvent(this, eventMetadata), fileEventManager);
}
stream = decorator == null ? stream : decorator.decorateRead(stream, this, eventMetadata);
logger.trace("Returning stream: {} for transfer: {}", stream.getClass().getName(), this);
return stream;
} catch (final IOException e) {
if (fireEvents) {
fileEventManager.fire(new FileErrorEvent(this, e, eventMetadata));
}
throw e;
}
}
Aggregations