Skip to content

Commit

Permalink
at least make it run
Browse files Browse the repository at this point in the history
- config file needs to be on the classpath 
- cannot nullify cache in dispose


git-svn-id: https://svn.apache.org/repos/asf/cocoon/trunk@27543 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Unico Hommes committed Mar 4, 2004
1 parent 47f92a8 commit 25e9d77
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 63 deletions.
Expand Up @@ -50,17 +50,15 @@ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
*/
package org.apache.cocoon.components.store;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Enumeration;

import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;

import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.excalibur.store.Store;
import org.apache.excalibur.store.impl.AbstractReadWriteStore;
import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;

/**
* TODO - This store implementation should be moved to excalibur store
Expand All @@ -84,9 +82,8 @@ public abstract class AbstractJCSStore
/**The group name as used by JCS getGroupKeys*/
private String m_group;



public void setup(final File configFile,
public void setup(final String configFile,
final String regionName,
final String groupName)
throws IOException, CacheException {
Expand All @@ -95,28 +92,18 @@ public void setup(final File configFile,
this.m_group = groupName;

if ( this.getLogger().isDebugEnabled() ) {
if ( configFile != null ) {
getLogger().debug("CEM Loading config: '" + configFile.getAbsolutePath() + "'");
}
getLogger().debug("CEM Loading config: '" + configFile + "'");
getLogger().debug("CEM Loading region: '" + this.m_region + "'");
getLogger().debug("CEM Loading group: '" + this.m_group + "'");
}

if ( configFile != null ) {
/* Does config exist? */
// if (this.m_JCSConfigFile.exists())
// {
getLogger().debug("CEM Setting full path: " + configFile.getAbsolutePath());

JCS.setConfigFilename( configFile.getAbsolutePath() );
// } else {
// throw new IOException( "Error reading JCS Config '" + this.m_JCSConfigFile.getAbsolutePath() + "'. File not found." );
// }
}
JCS.setConfigFilename( configFile );

try {
m_JCS = JCS.getInstance( m_region );
System.out.println("m_JCS" + m_JCS);
} catch (CacheException ce) {
ce.printStackTrace();
throw new CacheException( "Error initialising JCS with region: " + this.m_region );
}

Expand Down Expand Up @@ -297,6 +284,4 @@ protected int doGetSize()
return 0;
}



}
Expand Up @@ -51,7 +51,9 @@ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
package org.apache.cocoon.components.store;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.jcs.access.exception.CacheException;

Expand Down Expand Up @@ -88,9 +90,6 @@ public class JCSPersistentStore extends AbstractJCSStore
protected ServiceManager manager;


/* (non-Javadoc)
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service(ServiceManager manager) throws ServiceException {
this.manager = manager;
}
Expand All @@ -111,45 +110,16 @@ public void service(ServiceManager manager) throws ServiceException {
*/
public void parameterize(Parameters params) throws ParameterException {
// TODO - These are only values for testing:
final String configFileName = params.getParameter("config-file", "context://WEB-INF/TestDiskCache.ccf");
final String regionName = params.getParameter("region-name", "indexedRegion1");
final String groupName = params.getParameter("group-name", "indexedDiskCache");

SourceResolver resolver = null;
Source source = null;
final String configFile = params.getParameter("config-file", "/TestDiskCache.ccf");
final String regionName = params.getParameter("region-name", "indexedRegion1");
final String groupName = params.getParameter("group-name", "indexedDiskCache");

try {
File configFile = null;

if ( configFileName != null ) {
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
source = resolver.resolveURI(configFileName);

// get the config file to use
configFile = SourceUtil.getFile(source);

//if(!configFile.exists()){
// throw new ParameterException(
// "JCS Config file does not exist: " + configFileName
// );
//}
}

try {
this.setup(configFile, regionName, groupName);
} catch (CacheException ce) {
throw new ParameterException(
"JCS unable to run setup with region: " + regionName
);
}
} catch (ServiceException se) {
throw new ParameterException("Unable to get source resolver.", se);
this.setup(configFile, regionName, groupName);
} catch (CacheException ce) {
throw new ParameterException("JCS unable to run setup with region: " + regionName);
} catch (IOException ioe) {
throw new ParameterException("Unable to get handle on JCS Config file: " + configFileName , ioe);
} finally {
if ( resolver != null ) {
resolver.release(source);
this.manager.release(resolver);
}
throw new ParameterException("Unable to get handle on JCS Config file: " + configFile , ioe);
}

}
Expand All @@ -161,7 +131,7 @@ public void dispose() {

if (super.m_JCS != null) {

super.m_JCS = null;
//super.m_JCS = null;
//protected - what is the best way to do this?
//super.m_JCS.dispose();
}
Expand Down

0 comments on commit 25e9d77

Please sign in to comment.