diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/CacheStore.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/CacheStore.java index bd56a882f..a10d4c313 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/CacheStore.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/CacheStore.java @@ -15,7 +15,7 @@ */ package br.com.caelum.vraptor.cache; -import java.util.concurrent.Callable; +import com.google.common.base.Supplier; /** * @@ -51,6 +51,6 @@ public interface CacheStore { * @param valueProvider * @return the stored or the new value for the provided key. */ - public V fetch(K key, Callable valueProvider); + public V fetch(K key, Supplier valueProvider); } diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/DefaultCacheStore.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/DefaultCacheStore.java index 0dbf878df..e5f5d8fff 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/DefaultCacheStore.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/DefaultCacheStore.java @@ -17,13 +17,14 @@ import static com.google.common.base.Throwables.propagateIfPossible; -import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import javax.enterprise.context.Dependent; import javax.enterprise.inject.Default; +import com.google.common.base.Supplier; + @Default @Dependent public class DefaultCacheStore implements CacheStore { @@ -31,10 +32,10 @@ public class DefaultCacheStore implements CacheStore { private final ConcurrentMap cache = new ConcurrentHashMap<>(); @Override - public V fetch(K key, Callable valueProvider) { + public V fetch(K key, Supplier valueProvider) { if (!cache.containsKey(key)){ try { - V value = valueProvider.call(); + V value = valueProvider.get(); cache.put(key, value); return value; } catch (Exception e) { diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/LRUCacheStore.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/LRUCacheStore.java index d0d84ecd3..9b1333f76 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/LRUCacheStore.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/cache/LRUCacheStore.java @@ -20,10 +20,11 @@ import java.util.LinkedHashMap; import java.util.Map; -import java.util.concurrent.Callable; import javax.enterprise.inject.Vetoed; +import com.google.common.base.Supplier; + /** * A LRU cache based on LinkedHashMap. * @@ -47,10 +48,10 @@ protected boolean removeEldestEntry(Map.Entry eldest) { } @Override - public V fetch(K key, Callable valueProvider) { + public V fetch(K key, Supplier valueProvider) { if (!this.containsKey(key)){ try { - V value = valueProvider.call(); + V value = valueProvider.get(); put(key, value); return value; } catch (Exception e) { diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/core/DefaultConverters.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/core/DefaultConverters.java index afb240515..732b1faf6 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/core/DefaultConverters.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/core/DefaultConverters.java @@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkState; import java.util.LinkedList; -import java.util.concurrent.Callable; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; @@ -36,6 +35,7 @@ import br.com.caelum.vraptor.ioc.Container; import com.google.common.base.Predicate; +import com.google.common.base.Supplier; import com.google.common.collect.FluentIterable; @ApplicationScoped @@ -81,9 +81,9 @@ public Converter to(Class clazz) { } private Class> findConverterType(final Class clazz) { - return cache.fetch(clazz, new Callable>>() { + return cache.fetch(clazz, new Supplier>>() { @Override - public Class> call() throws Exception { + public Class> get() { return FluentIterable.from(classes).filter(matchConverter(clazz)) .first().or(NullConverter.class); } diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/core/DefaultInterceptorHandlerFactory.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/core/DefaultInterceptorHandlerFactory.java index 5c1fa24c0..957df1fda 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/core/DefaultInterceptorHandlerFactory.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/core/DefaultInterceptorHandlerFactory.java @@ -15,8 +15,6 @@ */ package br.com.caelum.vraptor.core; -import java.util.concurrent.Callable; - import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; @@ -30,6 +28,8 @@ import br.com.caelum.vraptor.interceptor.StepInvoker; import br.com.caelum.vraptor.ioc.Container; +import com.google.common.base.Supplier; + /** * @author Lucas Cavalcanti * @author Alberto Souza @@ -67,9 +67,9 @@ public DefaultInterceptorHandlerFactory(Container container, StepInvoker stepInv @Override public InterceptorHandler handlerFor(final Class type) { - return cachedHandlers.fetch(type, new Callable() { + return cachedHandlers.fetch(type, new Supplier() { @Override - public InterceptorHandler call() throws Exception { + public InterceptorHandler get() { if(type.isAnnotationPresent(Intercepts.class) && !Interceptor.class.isAssignableFrom(type)){ return new AspectStyleInterceptorHandler(type, stepInvoker, container, customAcceptsExecutor, acceptsExecutor, interceptorExecutor); diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/http/route/DefaultRouter.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/http/route/DefaultRouter.java index 5b84f63e2..20edb460b 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/http/route/DefaultRouter.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/http/route/DefaultRouter.java @@ -26,7 +26,6 @@ import java.util.EnumSet; import java.util.Iterator; import java.util.List; -import java.util.concurrent.Callable; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; @@ -44,6 +43,7 @@ import br.com.caelum.vraptor.proxy.Proxifier; import com.google.common.base.Predicate; +import com.google.common.base.Supplier; import com.google.common.collect.FluentIterable; /** @@ -162,9 +162,9 @@ public String urlFor(final Class type, final Method method, Object... par final Class rawtype = proxifier.isProxyType(type) ? type.getSuperclass() : type; final Invocation invocation = new Invocation(rawtype, method); - Route route = cache.fetch(invocation, new Callable() { + Route route = cache.fetch(invocation, new Supplier() { @Override - public Route call() throws Exception { + public Route get() { return FluentIterable.from(routes).filter(canHandle(rawtype, method)) .first().or(NULL); } diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultAcceptHeaderToFormat.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultAcceptHeaderToFormat.java index 3f6b9701f..9c9c0afd8 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultAcceptHeaderToFormat.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultAcceptHeaderToFormat.java @@ -19,7 +19,6 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -31,6 +30,7 @@ import br.com.caelum.vraptor.cache.LRU; import com.google.common.base.Function; +import com.google.common.base.Supplier; import com.google.common.collect.FluentIterable; /** @@ -78,9 +78,9 @@ public String getFormat(final String acceptHeader) { return DEFAULT_FORMAT; } - return acceptToFormatCache.fetch(acceptHeader, new Callable() { + return acceptToFormatCache.fetch(acceptHeader, new Supplier() { @Override - public String call() throws Exception { + public String get() { return chooseMimeType(acceptHeader); } });