jakarta-jcs-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jorge Medina" <jmed...@e-dialog.com>
Subject RE: Using JCS from many libraries
Date Thu, 01 May 2008 22:04:09 GMT

In other words, is there any way to configure the default element attributes for a region
programmatically?

-Jorge

-----Original Message-----
From: Jorge Medina [mailto:jmedina@e-dialog.com] 
Sent: Thursday, May 01, 2008 5:54 PM
To: jcs-users@jakarta.apache.org
Subject: Using JCS from many libraries

Hi, 
	Here is what I have run into:

	A group in the company has created a java library, component1.jar, which extensively uses
JCS and bundles cache.ccf within the jar file. It has been unit tested and it works fine.
	A second group develops another java library, component2.jar, which also uses JCS and bundles
cache.ccf within the jar file. It has been unit tested and it works fine.

	An application requires to use component1.jar and component2.jar but now there are two cache.ccf
and only one is being loaded.
	The regions used by the second component are created with the default cache and element attributes
found in the first cache.ccf. Only the first call to JCS.setConfigFilename( file ) has effect.


	Extracting cache.ccf from the jars and creating a single file is not a viable solution if
JCS is used in many more components or subsystems. For example, another application may make
use of component2.jar and component5.jar ...besides, there is no way to guarantee that anyone
knows all places where JCS is used - and loaded from the same class loader .

	What have you do to go around this? Has anybody have had the same problem?

	I have tried to create a CacheFactory but the JCS class allows to specify the cache attributes
on the getInstance( regionName, ICacheAtributes) method, but it does not allow to specify
the default element attributes for this region. The default elements attributes are applied
but from the first config file.( jcs.properties file in my code)

	Any help is appreciated.

-Jorge


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

import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;
import org.apache.jcs.engine.CompositeCacheAttributes;
import org.apache.jcs.engine.ElementAttributes;
import org.apache.jcs.config.PropertySetter;

public class CacheFactory {


	private CacheFactory() {

	}

	// clazz is used to find the the location of jcs.properties (instead of /cache.ccf ) for
the region. 
      // Each developer would use a class in their own package. (for practical purposes, the
class caching the objects )

	public static JCS createCache(Class clazz, String region) {
		String pkg = clazz.getPackage().getName();
		pkg = pkg.replace(".", "/");
		String file = "/" + pkg + "/jcs.properties";

		Properties props = new Properties();
		CompositeCacheAttributes cca = new CompositeCacheAttributes();
		ElementAttributes eca = new ElementAttributes();

		try {
			props.load( clazz.getResourceAsStream("jcs.properties") );
			PropertySetter.setProperties(cca,props, "jcs.region." + region + ".cacheattributes.");
			PropertySetter.setProperties(eca,props, "jcs.region." + region + ".elementattributes.");
		} catch (IOException e1) {
		}
		JCS resp = null;
		try {
			JCS.setConfigFilename( file );
			resp = JCS.getInstance(region, cca);  // ← No way to specify default element attributes
for this cache
		} catch (CacheException e) {
			throw new RuntimeException("Unable to set initialize JCS cache for region name [" +
						region +"]",e);
		}
		return resp;
	}
}


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Mime
View raw message