[jboss-cvs] JBossAS SVN: r95780 - in projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann: repository and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 29 15:23:55 EDT 2009
Author: alesj
Date: 2009-10-29 15:23:54 -0400 (Thu, 29 Oct 2009)
New Revision: 95780
Added:
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/AbstractGroupingStrategy.java
Modified:
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/GroupingStrategy.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultAnnotationRepository.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java
Log:
Add cache key.
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/GroupingStrategy.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/GroupingStrategy.java 2009-10-29 19:02:00 UTC (rev 95779)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/GroupingStrategy.java 2009-10-29 19:23:54 UTC (rev 95780)
@@ -39,6 +39,18 @@
T group(AnnotationRepository repository);
/**
+ * Get cache key.
+ *
+ * Note: we use weak keys, so make sure this
+ * is something that's not gc-ed immediately.
+ *
+ * By default we use instance's class.
+ *
+ * @return cache key
+ */
+ Object cacheKey();
+
+ /**
* Should we used cached results.
*
* @return true if we should used cached results
Copied: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/AbstractGroupingStrategy.java (from rev 95769, projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java)
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/AbstractGroupingStrategy.java (rev 0)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/AbstractGroupingStrategy.java 2009-10-29 19:23:54 UTC (rev 95780)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mcann.repository;
+
+import org.jboss.mcann.GroupingStrategy;
+
+/**
+ * Abstract grouping strategy.
+ *
+ * @param <T> exact rturn type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractGroupingStrategy<T> implements GroupingStrategy<T>
+{
+ private boolean useCache;
+ private boolean putToCache;
+
+ protected AbstractGroupingStrategy()
+ {
+ }
+
+ protected AbstractGroupingStrategy(boolean useCache, boolean putToCache)
+ {
+ this.useCache = useCache;
+ this.putToCache = putToCache;
+ }
+
+ public Object cacheKey()
+ {
+ return getClass();
+ }
+
+ public boolean useCache()
+ {
+ return useCache;
+ }
+
+ public boolean putToCache()
+ {
+ return putToCache;
+ }
+}
\ No newline at end of file
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultAnnotationRepository.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultAnnotationRepository.java 2009-10-29 19:02:00 UTC (rev 95779)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultAnnotationRepository.java 2009-10-29 19:23:54 UTC (rev 95780)
@@ -57,7 +57,7 @@
/** Should we keep the annotation */
private boolean keepAnnotations;
/** The grouping cache */
- private Map<Class<?>, Object> grouping = new ConcurrentReferenceHashMap<Class<?>, Object>();
+ private Map<Object, Object> grouping = new ConcurrentReferenceHashMap<Object, Object>();
public DefaultAnnotationRepository(ClassLoader classLoader)
{
@@ -112,7 +112,7 @@
if (strategy.useCache())
{
- Object cached = grouping.get(strategy.getClass());
+ Object cached = grouping.get(strategy.cacheKey());
if (cached != null)
return strategy.wrap(cached);
}
@@ -120,7 +120,7 @@
T result = strategy.group(this);
if (result != null && strategy.putToCache())
- grouping.put(strategy.getClass(), result);
+ grouping.put(strategy.cacheKey(), result);
return result;
}
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java 2009-10-29 19:02:00 UTC (rev 95779)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java 2009-10-29 19:23:54 UTC (rev 95780)
@@ -23,18 +23,17 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
-import java.util.Set;
import java.util.Map;
+import java.util.Set;
import org.jboss.mcann.AnnotationRepository;
-import org.jboss.mcann.GroupingStrategy;
/**
* Merge repositories.
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public class MergeGroupingStrategy implements GroupingStrategy<Void>
+public class MergeGroupingStrategy extends AbstractGroupingStrategy<Void>
{
private DefaultAnnotationRepository repository;
@@ -70,16 +69,6 @@
return null;
}
- public boolean useCache()
- {
- return false;
- }
-
- public boolean putToCache()
- {
- return false;
- }
-
public Void wrap(Object result)
{
return null;
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java 2009-10-29 19:02:00 UTC (rev 95779)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java 2009-10-29 19:23:54 UTC (rev 95780)
@@ -24,31 +24,26 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.net.URL;
+import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import java.util.HashMap;
import org.jboss.mcann.AnnotationRepository;
-import org.jboss.mcann.GroupingStrategy;
/**
* Group per source location.
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public class SourceLocationGroupingStrategy implements GroupingStrategy<Map<URL, AnnotationRepository>>
+public class SourceLocationGroupingStrategy extends AbstractGroupingStrategy<Map<URL, AnnotationRepository>>
{
- private boolean useCache;
- private boolean putToCache;
-
public SourceLocationGroupingStrategy()
{
}
public SourceLocationGroupingStrategy(boolean useCache, boolean putToCache)
{
- this.useCache = useCache;
- this.putToCache = putToCache;
+ super(useCache, putToCache);
}
public Map<URL, AnnotationRepository> group(AnnotationRepository current)
@@ -73,16 +68,6 @@
return map;
}
- public boolean useCache()
- {
- return useCache;
- }
-
- public boolean putToCache()
- {
- return putToCache;
- }
-
@SuppressWarnings("unchecked")
public Map<URL, AnnotationRepository> wrap(Object result)
{
More information about the jboss-cvs-commits
mailing list