Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Path put(Path path, String eTag, InputStream content) throws IOException
Files.createDirectories(cachePath.getParent());
Files.copy(content, cachePath, StandardCopyOption.REPLACE_EXISTING);

// TODO: cleanup older/other entries?
// NOPMD - TODO: cleanup older/other entries?

return cachePath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings({"PMD.TooManyMethods", "PMD.GodClass"})
public class BlobStoreImpl extends AbstractVolatileComposedPolling
implements BlobStore, BlobWriterReader {

Expand Down Expand Up @@ -90,50 +91,54 @@ public void start() {

List<StoreSource> sources = findSources();

Lists.reverse(sources)
.forEach(
source -> {
Optional<BlobStoreDriver> blobStoreDriver = findDriver(source, true);

blobStoreDriver.ifPresent(
driver -> {
try {
addSubComponent(driver, source);

BlobSource blobSource = driver.init(source, contentType);

blobReaders.add(blobSource);

boolean writable = false;
if (source.isWritable() && blobSource.canWrite()) {
blobWriters.add(blobSource);
writable = true;
}

if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"{}{} for {} ready{}",
contentType.getLabel(),
source.getPrefix().isPresent()
? " of type " + source.getPrefix().get()
: "",
source.getLabel(),
writable ? " and writable" : "");
}
} catch (Throwable e) {
LogContext.error(
LOGGER,
e,
"{} for {} could not be loaded",
contentType.getLabel(),
source.getLabel());
}
});
});
Lists.reverse(sources).forEach(this::initializeSource);

onVolatileStarted();
}

private void initializeSource(StoreSource source) {
Optional<BlobStoreDriver> blobStoreDriver = findDriver(source, true);

blobStoreDriver.ifPresent(driver -> processDriver(driver, source));
}

private void processDriver(BlobStoreDriver driver, StoreSource source) {
try {
addSubComponent(driver, source);

BlobSource blobSource = driver.init(source, contentType);

blobReaders.add(blobSource);

boolean writable = addWriterIfPossible(source, blobSource);

logSourceReady(source, writable);
} catch (Throwable e) {
LogContext.error(
LOGGER, e, "{} for {} could not be loaded", contentType.getLabel(), source.getLabel());
}
}

private boolean addWriterIfPossible(StoreSource source, BlobSource blobSource) {
boolean writable = false;
if (source.isWritable() && blobSource.canWrite()) {
blobWriters.add(blobSource);
writable = true;
}
return writable;
}

private void logSourceReady(StoreSource source, boolean writable) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"{}{} for {} ready{}",
contentType.getLabel(),
source.getPrefix().isPresent() ? " of type " + source.getPrefix().get() : "",
source.getLabel(),
writable ? " and writable" : "");
}
}

private void addSubComponent(BlobStoreDriver driver, StoreSource source) {
addSubcomponent(
new AbstractVolatilePolling(volatileRegistry) {
Expand Down Expand Up @@ -182,7 +187,7 @@ private Optional<BlobStoreDriver> findDriver(StoreSource storeSource, boolean wa
.filter(
d -> {
if (!d.isAvailable(storeSource)) {
if (warn) {
if (warn && LOGGER.isWarnEnabled()) {
LOGGER.warn(
"{} for {} are not available.",
contentType.getLabel(),
Expand All @@ -195,7 +200,7 @@ private Optional<BlobStoreDriver> findDriver(StoreSource storeSource, boolean wa
})
.findFirst();

if (driver.isEmpty() && !foundUnavailable[0]) {
if (driver.isEmpty() && !foundUnavailable[0] && LOGGER.isErrorEnabled()) {
LOGGER.error("No blob driver found for source {}.", storeSource.getLabel());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public String contentType() {
return precomputedContentType()
.orElseGet(
() -> {
// TODO: URLConnection content-type guessing doesn't seem to work well, maybe try
// NOTE: URLConnection content-type guessing doesn't seem to work well, maybe try
// Apache Tika
String contentType =
URLConnection.guessContentTypeFromName(path().getFileName().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.function.BiPredicate;
import java.util.stream.Stream;

@SuppressWarnings("PMD.TooManyMethods")
public interface ResourceStore
extends BlobReader, BlobWriter, BlobLocals, Volatile2, VolatileRegistered {

Expand All @@ -35,15 +36,14 @@ default ResourceStore writableWith(String type, String... path) {
}

default ResourceStore writableWith(boolean writable, String type, String... path) {
ResourceStore delegate = this;
Path prefix = Path.of(type, path);

if (!(delegate instanceof BlobWriterReader)) {
if (!(this instanceof BlobWriterReader)) {
throw new IllegalStateException();
}

Path prefix = Path.of(type, path);
BlobWriterReader delegateWriter = (BlobWriterReader) this;

return new PrefixedResourceStore(delegate, prefix, delegateWriter, writable);
return new PrefixedResourceStore(this, prefix, delegateWriter, writable);
}

class PrefixedResourceStore implements ResourceStore, BlobWriterReader {
Expand Down
Loading