Author: andreas
Date: Thu Feb 12 01:42:26 2009
New Revision: 743588
URL: http://svn.apache.org/viewvc?rev=743588&view=rev
Log:
Adding cache declaration.
Added:
lenya/trunk/org.apache.lenya.core.cache/src/main/resources/
lenya/trunk/org.apache.lenya.core.cache/src/main/resources/META-INF/
lenya/trunk/org.apache.lenya.core.cache/src/main/resources/META-INF/cocoon/
lenya/trunk/org.apache.lenya.core.cache/src/main/resources/META-INF/cocoon/spring/
lenya/trunk/org.apache.lenya.core.cache/src/main/resources/META-INF/cocoon/spring/lenya-core-cache-components.xml
Modified:
lenya/trunk/org.apache.lenya.core.cache/src/main/java/org/apache/lenya/ac/cache/SourceCacheImpl.java
Modified: lenya/trunk/org.apache.lenya.core.cache/src/main/java/org/apache/lenya/ac/cache/SourceCacheImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.cache/src/main/java/org/apache/lenya/ac/cache/SourceCacheImpl.java?rev=743588&r1=743587&r2=743588&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.cache/src/main/java/org/apache/lenya/ac/cache/SourceCacheImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.cache/src/main/java/org/apache/lenya/ac/cache/SourceCacheImpl.java Thu Feb 12 01:42:26 2009
@@ -22,11 +22,6 @@
import java.io.InputStream;
import java.net.MalformedURLException;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.util.AbstractLogEnabled;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceNotFoundException;
@@ -38,32 +33,9 @@
* Basic implementation of a source cache.
* @version $Id$
*/
-public class SourceCacheImpl
- extends AbstractLogEnabled
- implements SourceCache, Serviceable, Disposable, ThreadSafe {
-
- /**
- * Returns the service manager.
- * @return A service manager.
- */
- public ServiceManager getManager() {
- return this.manager;
- }
-
- /**
- * Returns the source resolver.
- * @return A source resolver.
- */
- public SourceResolver getResolver() {
- return this.resolver;
- }
-
- /**
- * Ctor.
- */
- public SourceCacheImpl() {
- }
+public class SourceCacheImpl extends AbstractLogEnabled implements SourceCache {
+ private SourceResolver sourceResolver;
protected static final int CAPACITY = 1000;
private CacheMap cache;
@@ -79,9 +51,11 @@
}
/**
- * @see org.apache.lenya.ac.cache.SourceCache#get(java.lang.String, org.apache.lenya.ac.cache.InputStreamBuilder)
+ * @see org.apache.lenya.ac.cache.SourceCache#get(java.lang.String,
+ * org.apache.lenya.ac.cache.InputStreamBuilder)
*/
- public synchronized Object get(String sourceUri, InputStreamBuilder builder) throws CachingException {
+ public synchronized Object get(String sourceUri, InputStreamBuilder builder)
+ throws CachingException {
String key = sourceUri;
Object value = null;
@@ -92,8 +66,8 @@
try {
if (cachedObject != null) {
- if (getLogger().isDebugEnabled()){
- getLogger().debug("Found cached object [" + cachedObject + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Found cached object [" + cachedObject + "]");
}
SourceValidity cachedValidity = cachedObject.getValidityObject();
@@ -119,15 +93,15 @@
if (valid) {
if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug(
- "Using valid cached source for '" + sourceUri + "'.");
+ this.getLogger()
+ .debug("Using valid cached source for '" + sourceUri + "'.");
}
usedCache = true;
value = cachedObject.getValue();
} else {
if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug(
- "Cached content is invalid for '" + sourceUri + "'.");
+ this.getLogger()
+ .debug("Cached content is invalid for '" + sourceUri + "'.");
}
// remove invalid cached object
getCache().remove(key);
@@ -161,11 +135,8 @@
if (key != null) {
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug(
- "Caching object ["
- + value
- + "] for further requests of ["
- + sourceUri
- + "].");
+ "Caching object [" + value + "] for further requests of ["
+ + sourceUri + "].");
}
getCache().put(key, new CachedObject(sourceValidity, value));
}
@@ -194,18 +165,18 @@
* @throws BuildException if an error occurs.
*/
protected synchronized Object buildObject(String sourceUri, InputStreamBuilder builder)
- throws MalformedURLException, IOException, SourceNotFoundException, BuildException {
+ throws MalformedURLException, IOException, SourceNotFoundException, BuildException {
Object value = null;
Source source = null;
try {
- source = getResolver().resolveURI(sourceUri);
+ source = this.sourceResolver.resolveURI(sourceUri);
if (source.exists()) {
InputStream stream = source.getInputStream();
value = builder.build(stream);
}
} finally {
if (source != null) {
- getResolver().release(source);
+ this.sourceResolver.release(source);
}
}
return value;
@@ -219,38 +190,22 @@
* @throws IOException when an error occurs.
*/
protected synchronized SourceValidity getSourceValidity(String sourceUri)
- throws MalformedURLException, IOException {
+ throws MalformedURLException, IOException {
SourceValidity sourceValidity;
Source source = null;
try {
- source = getResolver().resolveURI(sourceUri);
+ source = this.sourceResolver.resolveURI(sourceUri);
sourceValidity = source.getValidity();
} finally {
if (source != null) {
- getResolver().release(source);
+ this.sourceResolver.release(source);
}
}
return sourceValidity;
}
- private ServiceManager manager;
- private SourceResolver resolver;
-
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager _manager) throws ServiceException {
- this.manager = _manager;
- this.resolver = (SourceResolver) _manager.lookup(SourceResolver.ROLE);
- }
-
- /**
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
- */
- public void dispose() {
- if (getResolver() != null) {
- getManager().release(getResolver());
- }
+ public void setSourceResolver(SourceResolver sourceResolver) {
+ this.sourceResolver = sourceResolver;
}
}
Added: lenya/trunk/org.apache.lenya.core.cache/src/main/resources/META-INF/cocoon/spring/lenya-core-cache-components.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.cache/src/main/resources/META-INF/cocoon/spring/lenya-core-cache-components.xml?rev=743588&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.cache/src/main/resources/META-INF/cocoon/spring/lenya-core-cache-components.xml (added)
+++ lenya/trunk/org.apache.lenya.core.cache/src/main/resources/META-INF/cocoon/spring/lenya-core-cache-components.xml Thu Feb 12 01:42:26 2009
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+ <bean name="org.apache.lenya.ac.cache.SourceCache"
+ class="org.apache.lenya.ac.cache.SourceCacheImpl">
+ <property name="sourceResolver" ref="org.apache.excalibur.source.SourceResolver"/>
+ </bean>
+
+</beans>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.