Skip to content

Commit

Permalink
ProjectCache should be queried only when the resource is expected to …
Browse files Browse the repository at this point in the history
…contain a project
  • Loading branch information
gastaldi committed Mar 24, 2014
1 parent 36628ae commit ad2e495
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package org.jboss.forge.addon.projects.impl;

import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;

import javax.inject.Singleton;

Expand All @@ -18,13 +18,13 @@

/**
* A simple in-memory {@link ProjectCache}.
*
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
@Singleton
public class InMemoryProjectCache implements ProjectCache
{
private final Map<String, Project> projects = new WeakHashMap<>();
private final Map<String, Project> projects = new ConcurrentHashMap<>();

@Override
public Project get(Resource<?> root)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,31 +189,40 @@ private Project findProjectInDirectory(Resource<?> target, ProjectProvider proje
{
Project result = null;

Iterator<ProjectCache> cacheIterator = caches.iterator();
while (cacheIterator.hasNext())
if (projectProvider.containsProject(target))
{
ProjectCache cache = cacheIterator.next();
try
boolean cached = false;
Iterator<ProjectCache> cacheIterator = caches.iterator();
while (cacheIterator.hasNext())
{
result = cache.get(target);
if (result != null && !filter.accept(result))
result = null;
if (result != null)
break;
ProjectCache cache = cacheIterator.next();
try
{
result = cache.get(target);
if (result != null && !filter.accept(result))
{
result = null;
}
if (result != null)
{
cached = true;
break;
}
}
finally
{
caches.release(cache);
}
}
finally
if (result == null)
{
caches.release(cache);
result = projectProvider.createProject(target);
}
}

if (result == null && projectProvider.containsProject(target))
{
result = projectProvider.createProject(target);
if (result != null && !filter.accept(result))
{
result = null;

if (result != null)
}
if (result != null && !cached)
{
registerAvailableFacets(result);
cacheProject(result);
Expand Down

0 comments on commit ad2e495

Please sign in to comment.