protected boolean processReader(Environment environment)
throws ProcessingException {
try {
boolean usedCache = false;
OutputStream outputStream = null;
SourceValidity readerValidity = null;
PipelineCacheKey pcKey = null;
// test if reader is cacheable
Serializable readerKey = null;
boolean isCacheableProcessingComponent = false;
if (super.reader instanceof CacheableProcessingComponent) {
readerKey = ((CacheableProcessingComponent)super.reader).getKey();
isCacheableProcessingComponent = true;
} else if (super.reader instanceof Cacheable) {
readerKey = new Long(((Cacheable)super.reader).generateKey());
}
if ( readerKey != null) {
// response is cacheable, build the key
pcKey = new PipelineCacheKey();
pcKey.addKey(new ComponentCacheKey(ComponentCacheKey.ComponentType_Reader,
this.readerRole,
readerKey)
);
// now we have the key to get the cached object
CachedResponse cachedObject = this.cache.get( pcKey );
if (cachedObject != null) {
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug(
"Found cached response for '" +
environment.getURI() + "' using key: " + pcKey);
}
SourceValidity[] validities = cachedObject.getValidityObjects();
if (validities == null || validities.length != 1) {
// to avoid getting here again and again, we delete it
this.cache.remove( pcKey );
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug(
"Cached response for '" +
environment.getURI() + "' using key: " +
pcKey + " is invalid.");
}
cachedResponse = null;
} else {
SourceValidity cachedValidity = validities[0];
int result = cachedValidity.isValid();
boolean valid = false;
if ( result == 0 ) {
// get reader validity and compare
if (isCacheableProcessingComponent) {
readerValidity = ((CacheableProcessingComponent)super.reader).getValidity();
} else {
CacheValidity cv = ((Cacheable)super.reader).generateValidity();
if ( cv != null ) {
readerValidity = CacheValidityToSourceValidity.createValidity( cv );
}
}
if (readerValidity != null) {
result = cachedValidity.isValid(readerValidity);
if ( result == 0 ) {
readerValidity = null;
} else {
valid = (result == 1);
}