You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/01/04 19:27:31 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/cache ObjectCacheDefaultImpl.java CacheDistributor.java
arminw 2004/01/04 10:27:31
Modified: src/test/org/apache/ojb repository_database.xml
src/java/org/apache/ojb/broker/cache
ObjectCacheDefaultImpl.java CacheDistributor.java
Log:
- fix bug in CacheDestributor, we can't use a static map for caches, because
we need to held caches for each PB instance separate
- fix typo in repository_database.xml
- allow timeout attribute set to a infinite lifetime of cached objects
Revision Changes Path
1.19 +2 -2 db-ojb/src/test/org/apache/ojb/repository_database.xml
Index: repository_database.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_database.xml,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- repository_database.xml 4 Jan 2004 02:34:37 -0000 1.18
+++ repository_database.xml 4 Jan 2004 18:27:31 -0000 1.19
@@ -33,7 +33,7 @@
<object-cache class="org.apache.ojb.broker.cache.ObjectCacheDefaultImpl">
<attribute attribute-name="timeout" attribute-value="900"/>
- <attribute attribute-name="useAutoSync" attribute-value="true"/>
+ <attribute attribute-name="autoSync" attribute-value="true"/>
</object-cache>
<connection-pool
1.18 +23 -9 db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java
Index: ObjectCacheDefaultImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ObjectCacheDefaultImpl.java 4 Jan 2004 02:34:37 -0000 1.17
+++ ObjectCacheDefaultImpl.java 4 Jan 2004 18:27:31 -0000 1.18
@@ -101,7 +101,8 @@
* Lifetime of the cached objects in seconds.
* If expired the cached object was not returned
* on lookup call (and removed from cache). Default timeout
- * value is 900 seconds.
+ * value is 900 seconds. When set to <tt>-1</tt> the lifetime of
+ * the cached object depends only on GC and do never get timed out.
* <p>
* NOTE: Objects internal cached via {@link SoftReference}, so
* lifetime of cached object is limited by the GC too.
@@ -138,6 +139,8 @@
*/
public class ObjectCacheDefaultImpl implements ObjectCache, PBStateListener
{
+ public static final String TIMEOUT_PROP = "timeout";
+ public static final String AUTOSYNC_PROP = "autoSync";
/**
* static Map held all cached objects
*/
@@ -160,10 +163,11 @@
*/
public ObjectCacheDefaultImpl(PersistenceBroker broker, Properties prop)
{
- timeout = prop == null ? timeout : ( Long.parseLong( prop.getProperty( "timeout", "" + timeout ) ) *1000);
+ this.broker = broker;
+ timeout = prop == null ? timeout : ( Long.parseLong( prop.getProperty(TIMEOUT_PROP, "" + (60 * 15) ) ) *1000);
useAutoSync = prop == null ?
- false : ( Boolean.valueOf((prop.getProperty( "autoSync", "false")).trim())).booleanValue();
+ false : ( Boolean.valueOf((prop.getProperty(AUTOSYNC_PROP, "false")).trim())).booleanValue();
if(useAutoSync && broker != null)
{
// we add this instance as a permanent PBStateListener
@@ -172,11 +176,9 @@
if(useAutoSync && broker == null)
{
LoggerFactory.getDefaultLogger().info("[" + ObjectCacheDefaultImpl.class.getName() +
- "] Can't enable 'useAutoSync', because given PB instance is null");
+ "] Can't enable " + AUTOSYNC_PROP + ", because given PB instance is null");
}
-
identitiesInWork = new ArrayList();
- this.broker = broker;
}
/**
@@ -228,6 +230,10 @@
}
else
{
+ /*
+ TODO: Not sure if this makes sense, could help to avoid corrupted objects
+ when changed in tx but not stored.
+ */
traceIdentity(oid);
}
}
@@ -268,7 +274,7 @@
private void traceIdentity(Identity oid)
{
- if(useAutoSync && broker != null && broker.isInTransaction())
+ if(useAutoSync && (broker != null) && broker.isInTransaction())
{
identitiesInWork.add(oid);
}
@@ -334,7 +340,15 @@
public CacheEntry(Object object)
{
this.ref = new SoftReference(object);
- lifetime = System.currentTimeMillis() + timeout;
+ // if timeout is negative, lifetime of object never expire
+ if(timeout < 0)
+ {
+ lifetime = Long.MAX_VALUE;
+ }
+ else
+ {
+ lifetime = System.currentTimeMillis() + timeout;
+ }
}
}
1.4 +5 -5 db-ojb/src/java/org/apache/ojb/broker/cache/CacheDistributor.java
Index: CacheDistributor.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/CacheDistributor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CacheDistributor.java 3 Oct 2003 14:31:25 -0000 1.3
+++ CacheDistributor.java 4 Jan 2004 18:27:31 -0000 1.4
@@ -95,9 +95,9 @@
private static final String DESCRIPTOR_BASED_CACHES = "descriptorBasedCaches";
/**
- * global map, represents cache implementations
+ * map, represents used cache implementations
*/
- private static Map caches = new HashMap();
+ private Map caches = new HashMap();
private ObjectCache defaultCache;
private PersistenceBroker broker;
@@ -121,7 +121,7 @@
logger.info("Use property 'descriptorBasedCaches' is set '"+descriptorBasedCaches+"'");
}
- private synchronized static ObjectCache prepareAndAddCache(PersistenceBroker broker,
+ private ObjectCache prepareAndAddCache(PersistenceBroker broker,
ObjectCacheDescriptor ocd, Object key)
{
ObjectCache cache;
@@ -141,7 +141,7 @@
return cache;
}
- private static ObjectCache createObjectCache(PersistenceBroker broker, ObjectCacheDescriptor ocd)
+ private ObjectCache createObjectCache(PersistenceBroker broker, ObjectCacheDescriptor ocd)
{
ObjectCache cache = null;
try
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org