[jbosstools-commits] JBoss Tools SVN: r43527 - in trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi: internal/core/impl and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Sep 7 16:22:42 EDT 2012


Author: scabanovich
Date: 2012-09-07 16:22:42 -0400 (Fri, 07 Sep 2012)
New Revision: 43527

Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICorePlugin.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDICache.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
Log:
JBIDE-12446
https://issues.jboss.org/browse/JBIDE-12446


Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICorePlugin.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICorePlugin.java	2012-09-07 20:20:45 UTC (rev 43526)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICorePlugin.java	2012-09-07 20:22:42 UTC (rev 43527)
@@ -21,10 +21,12 @@
 import org.eclipse.core.resources.IResourceDelta;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.jboss.tools.cdi.internal.core.event.CDIProjectChangeEvent;
 import org.jboss.tools.cdi.internal.core.event.ICDIProjectChangeListener;
 import org.jboss.tools.common.log.BaseUIPlugin;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -189,4 +191,38 @@
 		}
 	}
 
+	boolean cacheIsLoaded = false;
+	ICDICache cache;
+
+	public ICDICache getDBCache() {
+		if(!cacheIsLoaded) {
+			synchronized (this) {
+				if(!cacheIsLoaded) {
+					try {
+						Bundle b = Platform.getBundle("org.jboss.tools.cdi.db");
+						if(b != null) {
+							try {
+								Class c = b.loadClass("org.jboss.tools.cdi.db.CDIDataBase");
+								if(c != null) {
+									cache = (ICDICache)c.newInstance();
+								}
+							} catch (ClassNotFoundException e) {
+								logError(e);
+							} catch (InstantiationException e) {
+								logError(e);
+							} catch (IllegalAccessException e) {
+								logError(e);
+							}
+						}
+					} catch (Throwable t) {
+						logError(t);
+					} finally {
+						cacheIsLoaded = true;
+					}
+				}				
+			}
+		}		
+		return cache;
+	}
+
 }
\ No newline at end of file

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDICache.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDICache.java	2012-09-07 20:20:45 UTC (rev 43526)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDICache.java	2012-09-07 20:22:42 UTC (rev 43527)
@@ -63,16 +63,24 @@
 
 	private Map<String, Set<IInjectionPoint>> injectionPointsByType = new HashMap<String, Set<IInjectionPoint>>();
 
-	private static int BEANS_BY_TYPE_SIZE = 367;
+	private int beansByTypeSize;
+	private int objectIndex;
 
 	public CDICache() {
-		for (int i = 0; i < BEANS_BY_TYPE_SIZE; i++) beansByTypes.add(new HashSet<IBean>());
+		setBeansByTypeSize(21);
 	}
 
-	private static int OBJECT_INDEX = Math.abs("java.lang.Object".hashCode()) % BEANS_BY_TYPE_SIZE;
+	public synchronized void setBeansByTypeSize(int beansByTypeSize) {
+		List<Set<IBean>> beansByTypes = new ArrayList<Set<IBean>>();
+		for (int i = 0; i < beansByTypeSize; i++) beansByTypes.add(new HashSet<IBean>());
+		this.beansByTypes = beansByTypes;
+		this.beansByTypeSize = beansByTypeSize;
+		objectIndex = Math.abs("java.lang.Object".hashCode()) % beansByTypeSize;
+	}
+
 	
-	private static int toTypeIndex(IType type) {
-		return Math.abs(type.getFullyQualifiedName().hashCode()) % BEANS_BY_TYPE_SIZE;
+	private int toTypeIndex(IType type) {
+		return Math.abs(type.getFullyQualifiedName().hashCode()) % beansByTypeSize;
 	}
 
 	public synchronized IBean[] getBeans() {
@@ -87,13 +95,11 @@
 		return new ArrayList<IBean>(declaredBeans);
 	}
 
-	public IBean[] getBeansByLegalType(IParametedType type) {
+	public synchronized IBean[] getBeansByLegalType(IParametedType type) {
 		if(type.getType() == null) return new IBean[0];
 		int index = toTypeIndex(type.getType());
-		Collection<IBean> bs = index == OBJECT_INDEX ? allBeans : beansByTypes.get(index);
-		synchronized (this) {
-			return bs.toArray(new IBean[bs.size()]);
-		}
+		Collection<IBean> bs = index == objectIndex ? allBeans : beansByTypes.get(index);
+		return bs.toArray(new IBean[bs.size()]);
 	}
 
 	public synchronized IQualifier[] getQualifiers() {
@@ -183,7 +189,7 @@
 		p.allBeans.addAll(beans);
 
 		p.beansByTypes = new ArrayList<Set<IBean>>();
-		for (int i = 0; i < BEANS_BY_TYPE_SIZE; i++) {
+		for (int i = 0; i < beansByTypeSize; i++) {
 			Set<IBean> bs = new HashSet<IBean>(beansByTypes.get(i));
 			bs.removeAll(oldBeans);
 			bs.addAll(beans);
@@ -313,7 +319,7 @@
 		for (IParametedType t: bean.getLegalTypes()) {
 			if(t.getType() != null && t.getType().exists()) {
 				int index = toTypeIndex(t.getType());
-				if(index != OBJECT_INDEX) {
+				if(index != objectIndex) {
 					beansByTypes.get(index).add(bean);
 				}
 			}
@@ -346,7 +352,7 @@
 		declaredBeans.clear();
 		injectionPointsByType.clear();
 		
-		for (int i = 0; i < BEANS_BY_TYPE_SIZE; i++) beansByTypes.get(i).clear();
+		for (int i = 0; i < beansByTypeSize; i++) beansByTypes.get(i).clear();
 	}
 
 	public synchronized void cleanAnnotations() {

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java	2012-09-07 20:20:45 UTC (rev 43526)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java	2012-09-07 20:22:42 UTC (rev 43527)
@@ -92,7 +92,7 @@
 	BeansXMLData projectBeansXMLData = new BeansXMLData();
 
 	public CDIProject() {
-		//TODO create dbCache instance
+		dbCache = CDICorePlugin.getDefault().getDBCache();
 	}
 
 	public CDIProject getModifiedCopy(IFile file, Collection<IBean> beans) {
@@ -1276,6 +1276,13 @@
 
 		cache.clean();
 
+		//Variable size of beans-by-type cache.
+		int beansByTypeSize = typeDefinitions.size() / 10;
+		if(beansByTypeSize < 10) beansByTypeSize = 10;
+		if(beansByTypeSize > 367) beansByTypeSize = 367;
+
+		cache.setBeansByTypeSize(beansByTypeSize);
+
 		cache.classBeans = newClassBeans;
 		cache.definitionToClassbeans = newDefinitionToClassbeans;
 		cache.allTypes = newAllTypes;
@@ -1284,7 +1291,7 @@
 		}
 	
 	}
-
+	
 	/**
 	 * Compares sets this.allTypes and newAllTypes
 	 * Returns 



More information about the jbosstools-commits mailing list