[jboss-cvs] JBossCache/src/org/jboss/cache/pojo/impl ...
Manik Surtani
manik at jboss.org
Wed May 23 06:28:49 EDT 2007
User: msurtani
Date: 07/05/23 06:28:49
Modified: src/org/jboss/cache/pojo/impl PojoCacheImpl.java
CollectionClassHandler.java
SerializableObjectHandler.java
PojoCacheDelegate.java ObjectGraphHandler.java
AdvisedPojoHandler.java InternalHelper.java
Log:
Initiated a bunch of performance fixes, including replacing CopyOnWriteArraySets with org.jboss.cache.util.concurrent.ConcurrentHashSet.
Also ran an imports optimiser on the code base - there were a lot of unused imports floating about.
Revision Changes Path
1.8 +31 -26 JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoCacheImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- PojoCacheImpl.java 16 May 2007 18:29:18 -0000 1.7
+++ PojoCacheImpl.java 23 May 2007 10:28:49 -0000 1.8
@@ -7,14 +7,6 @@
package org.jboss.cache.pojo.impl;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.WeakHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.aop.Advised;
@@ -38,12 +30,20 @@
import org.jboss.cache.pojo.notification.DetachNotification;
import org.jboss.cache.pojo.notification.Notification;
import org.jboss.cache.pojo.notification.NotificationContext;
+import org.jboss.cache.util.concurrent.ConcurrentHashSet;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
/**
* Implementation class for PojoCache interface
*
* @author Ben Wang
- * @version $Id: PojoCacheImpl.java,v 1.7 2007/05/16 18:29:18 jgreene Exp $
+ * @version $Id: PojoCacheImpl.java,v 1.8 2007/05/23 10:28:49 msurtani Exp $
*/
public class PojoCacheImpl implements PojoCache
{
@@ -60,7 +60,9 @@
*
* @see #addListener
*/
- private final Set listeners = new CopyOnWriteArraySet();
+ // CopyOnWriteArraySet is hugely inefficient when there are several writes to it. I've implemented a ConcurrentHashSet,
+ // similar to a ConcurrentHashMap, which uses lock striping and is more performant. - Manik
+ private final Set listeners = new ConcurrentHashSet();
/**
* True if listeners are initialized.
*/
@@ -372,13 +374,16 @@
}
}
- /********************************************************************************
+ /**
+ * *****************************************************************************
* Internal API for event notification
- ********************************************************************************/
+ * ******************************************************************************
+ */
private NotificationContext makeContext()
{
- return new NotificationContext() {
+ return new NotificationContext()
+ {
public PojoCache getPojoCache()
{
return PojoCacheImpl.this;
1.2 +42 -34 JBossCache/src/org/jboss/cache/pojo/impl/CollectionClassHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CollectionClassHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/CollectionClassHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- CollectionClassHandler.java 13 Jan 2007 15:55:06 -0000 1.1
+++ CollectionClassHandler.java 23 May 2007 10:28:49 -0000 1.2
@@ -12,15 +12,14 @@
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.proxy.ClassProxy;
import org.jboss.cache.CacheException;
-import org.jboss.cache.Fqn;
import org.jboss.cache.CacheSPI;
-import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
-import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
-import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
-import org.jboss.cache.pojo.PojoTreeCache;
+import org.jboss.cache.Fqn;
import org.jboss.cache.pojo.CachedType;
-import org.jboss.cache.pojo.PojoInstance;
import org.jboss.cache.pojo.PojoCacheException;
+import org.jboss.cache.pojo.PojoInstance;
+import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
+import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
+import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
import java.util.Iterator;
import java.util.List;
@@ -32,7 +31,7 @@
*
* @author Ben Wang
* Date: Aug 4, 2005
- * @version $Id: CollectionClassHandler.java,v 1.1 2007/01/13 15:55:06 bwang Exp $
+ * @version $Id: CollectionClassHandler.java,v 1.2 2007/05/23 10:28:49 msurtani Exp $
*/
class CollectionClassHandler
{
@@ -44,7 +43,7 @@
public CollectionClassHandler(PojoCacheImpl pCache, InternalHelper internal)
{
pCache_ = pCache;
- cache_ = (CacheSPI)pCache_.getCache();
+ cache_ = (CacheSPI) pCache_.getCache();
internal_ = internal;
}
@@ -58,16 +57,19 @@
{
Object map = clazz.newInstance();
obj = CollectionInterceptorUtil.createMapProxy(pCache_, fqn, clazz, (Map) map);
- } else if (List.class.isAssignableFrom(clazz))
+ }
+ else if (List.class.isAssignableFrom(clazz))
{
Object list = clazz.newInstance();
obj = CollectionInterceptorUtil.createListProxy(pCache_, fqn, clazz, (List) list);
- } else if (Set.class.isAssignableFrom(clazz))
+ }
+ else if (Set.class.isAssignableFrom(clazz))
{
Object set = clazz.newInstance();
obj = CollectionInterceptorUtil.createSetProxy(pCache_, fqn, clazz, (Set) set);
}
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new CacheException("failure creating proxy", e);
}
@@ -82,13 +84,14 @@
CachedType type = null;
if (obj instanceof ClassProxy)
{
- throw new IllegalStateException("CollectionClassHandler.put(): obj is an ClassProxy instance "+ obj);
+ throw new IllegalStateException("CollectionClassHandler.put(): obj is an ClassProxy instance " + obj);
}
type = pCache_.getCachedType(obj.getClass());
//JBCACHE-760: for collection - put initialized aopInstance in fqn
- if (!(obj instanceof Map || obj instanceof List || obj instanceof Set)) {
+ if (!(obj instanceof Map || obj instanceof List || obj instanceof Set))
+ {
return;
}
@@ -113,7 +116,8 @@
try
{
obj = CollectionInterceptorUtil.createMapProxy(pCache_, fqn, clazz, (Map) obj);
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new CacheException("failure creating proxy", e);
}
@@ -129,7 +133,8 @@
((Map) obj).put(entry.getKey(), entry.getValue());
}
- } else if (obj instanceof List)
+ }
+ else if (obj instanceof List)
{
if (log.isDebugEnabled())
{
@@ -146,7 +151,8 @@
try
{
obj = CollectionInterceptorUtil.createListProxy(pCache_, fqn, clazz, (List) obj);
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new CacheException("failure creating proxy", e);
}
@@ -161,7 +167,8 @@
((List) obj).add(i.next());
}
- } else if (obj instanceof Set)
+ }
+ else if (obj instanceof Set)
{
if (log.isDebugEnabled())
{
@@ -178,7 +185,8 @@
try
{
obj = CollectionInterceptorUtil.createSetProxy(pCache_, fqn, clazz, (Set) obj);
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new CacheException("failure creating proxy", e);
}
@@ -208,10 +216,10 @@
private void checkListRecursion(List list, Object obj)
{
- while(true)
+ while (true)
{
int i = list.indexOf(list); // check for recursion
- if(i == -1) break;
+ if (i == -1) break;
list.remove(list);
list.add(i, obj);
@@ -220,12 +228,12 @@
private void checkSetRecursion(Set set, Object obj)
{
- if(set.remove(set))
+ if (set.remove(set))
{
set.add(obj); // replace with proxy
throw new PojoCacheException("CollectionClassHandler.checkSetRecursion(): " +
"detect a recursive set (e.g., set inside the same set). This will fail to " +
- "replicate even outside of PojoCache with HashSet. " +set);
+ "replicate even outside of PojoCache with HashSet. " + set);
}
}
@@ -233,20 +241,20 @@
{
Map m = java.util.Collections.unmodifiableMap(map);
- for( Object k : m.keySet() )
+ for (Object k : m.keySet())
{
- if( m == k)
+ if (m == k)
{
throw new PojoCacheException("CollectionClassHandler.checkMapRecursion(): " +
- " Can't handle the recursion map where it is nested in a constant key " +map);
+ " Can't handle the recursion map where it is nested in a constant key " + map);
}
Object v = m.get(k);
- if( v == map )
+ if (v == map)
{
throw new PojoCacheException("CollectionClassHandler.checkMapRecursion(): " +
"detect a recursive map (e.g., map inside the same map). This will fail to " +
- "replicate even outside of PojoCache with HashMap because of hashCode. " +map);
+ "replicate even outside of PojoCache with HashMap because of hashCode. " + map);
// recursion here, replace it with proxy
// map.put(k, obj);
}
1.2 +15 -16 JBossCache/src/org/jboss/cache/pojo/impl/SerializableObjectHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SerializableObjectHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/SerializableObjectHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- SerializableObjectHandler.java 13 Jan 2007 15:55:06 -0000 1.1
+++ SerializableObjectHandler.java 23 May 2007 10:28:49 -0000 1.2
@@ -10,11 +10,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
-import org.jboss.cache.Fqn;
import org.jboss.cache.CacheSPI;
-import org.jboss.cache.pojo.PojoTreeCache;
-import org.jboss.cache.pojo.PojoInstance;
+import org.jboss.cache.Fqn;
import org.jboss.cache.pojo.InternalConstant;
+import org.jboss.cache.pojo.PojoInstance;
import java.util.HashMap;
import java.util.Map;
@@ -23,7 +22,7 @@
* Handle Serializable object cache management.
*
* @author Ben Wang
- * @version $Id: SerializableObjectHandler.java,v 1.1 2007/01/13 15:55:06 bwang Exp $
+ * @version $Id: SerializableObjectHandler.java,v 1.2 2007/05/23 10:28:49 msurtani Exp $
*/
class SerializableObjectHandler
{
@@ -35,7 +34,7 @@
public SerializableObjectHandler(PojoCacheImpl cache, InternalHelper internal)
{
pCache_ = cache;
- cache_ = (CacheSPI)pCache_.getCache();
+ cache_ = (CacheSPI) pCache_.getCache();
internal_ = internal;
}
1.7 +11 -13 JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoCacheDelegate.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheDelegate.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- PojoCacheDelegate.java 16 May 2007 18:29:18 -0000 1.6
+++ PojoCacheDelegate.java 23 May 2007 10:28:49 -0000 1.7
@@ -6,15 +6,6 @@
*/
package org.jboss.cache.pojo.impl;
-import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Observer;
-import java.util.Set;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.aop.Advised;
@@ -26,7 +17,6 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import org.jboss.cache.NodeSPI;
import org.jboss.cache.pojo.CachedType;
import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.PojoInstance;
@@ -38,6 +28,14 @@
import org.jboss.cache.pojo.memory.FieldPersistentReference;
import org.jboss.cache.pojo.util.AopUtil;
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* Delegate class for PojoCache, the real implementation code happens here.
*
1.4 +15 -16 JBossCache/src/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ObjectGraphHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/ObjectGraphHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ObjectGraphHandler.java 16 May 2007 18:29:18 -0000 1.3
+++ ObjectGraphHandler.java 23 May 2007 10:28:49 -0000 1.4
@@ -11,27 +11,25 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.aop.Advised;
import org.jboss.aop.InstanceAdvisor;
-import org.jboss.aop.proxy.ClassProxy;
import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.proxy.ClassProxy;
import org.jboss.cache.CacheException;
-import org.jboss.cache.Fqn;
import org.jboss.cache.CacheSPI;
-import org.jboss.cache.pojo.util.AopUtil;
-import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
-import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
-import org.jboss.cache.pojo.PojoTreeCache;
+import org.jboss.cache.Fqn;
import org.jboss.cache.pojo.CachedType;
+import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.PojoInstance;
import org.jboss.cache.pojo.PojoReference;
-import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.collection.CollectionInterceptorUtil;
+import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
+import org.jboss.cache.pojo.util.AopUtil;
/**
* Handle the object graph management.
*
* @author Ben Wang
* Date: Aug 4, 2005
- * @version $Id: ObjectGraphHandler.java,v 1.3 2007/05/16 18:29:18 jgreene Exp $
+ * @version $Id: ObjectGraphHandler.java,v 1.4 2007/05/23 10:28:49 msurtani Exp $
*/
class ObjectGraphHandler
{
@@ -43,7 +41,7 @@
public ObjectGraphHandler(PojoCacheImpl cache, InternalHelper internal)
{
pCache_ = cache;
- cache_ = (CacheSPI)pCache_.getCache();
+ cache_ = (CacheSPI) pCache_.getCache();
internal_ = internal;
}
@@ -67,14 +65,15 @@
InstanceAdvisor advisor = null;
Interceptor interceptor = null;
- if(obj instanceof Advised)
+ if (obj instanceof Advised)
{
advisor = ((Advised) obj)._getInstanceAdvisor();
if (advisor == null)
throw new PojoCacheException("put(): InstanceAdvisor is null for: " + obj);
// Step Check for cross references
interceptor = AopUtil.findCacheInterceptor(advisor);
- } else
+ }
+ else
{
advisor = ((ClassProxy) obj)._getInstanceAdvisor();
if (advisor == null)
@@ -103,7 +102,8 @@
try
{
pojoInstance = internal_.getAopInstance(internalFqn);
- } catch (CacheException e)
+ }
+ catch (CacheException e)
{
throw new PojoCacheException("Exception in isMultipleReferenced", e);
}
@@ -125,7 +125,6 @@
/**
* Remove the object from the the reference fqn, meaning just decrement the ref counter.
- *
*/
private void removeFromReference(Fqn referencingFqn, Fqn originalFqn) throws CacheException
{
1.5 +14 -14 JBossCache/src/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AdvisedPojoHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- AdvisedPojoHandler.java 16 May 2007 18:29:18 -0000 1.4
+++ AdvisedPojoHandler.java 23 May 2007 10:28:49 -0000 1.5
@@ -7,13 +7,6 @@
package org.jboss.cache.pojo.impl;
-import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.aop.Advised;
@@ -31,12 +24,19 @@
import org.jboss.cache.pojo.memory.FieldPersistentReference;
import org.jboss.cache.pojo.util.AopUtil;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* Handling the advised pojo operations. No consideration of object graph here.
*
* @author Ben Wang
* Date: Aug 4, 2005
- * @version $Id: AdvisedPojoHandler.java,v 1.4 2007/05/16 18:29:18 jgreene Exp $
+ * @version $Id: AdvisedPojoHandler.java,v 1.5 2007/05/23 10:28:49 msurtani Exp $
*/
class AdvisedPojoHandler
{
1.3 +7 -7 JBossCache/src/org/jboss/cache/pojo/impl/InternalHelper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InternalHelper.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/InternalHelper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- InternalHelper.java 16 May 2007 18:29:18 -0000 1.2
+++ InternalHelper.java 23 May 2007 10:28:49 -0000 1.3
@@ -13,9 +13,9 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Option;
import org.jboss.cache.pojo.InternalConstant;
+import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.PojoInstance;
import org.jboss.cache.pojo.PojoReference;
-import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.util.ObjectUtil;
import java.util.Map;
More information about the jboss-cvs-commits
mailing list