mirror of https://github.com/apache/jclouds.git
removed static field-based state sharing when looking up delegate methods
This commit is contained in:
parent
f00a4284c9
commit
c9baf20082
|
@ -20,6 +20,7 @@ package org.jclouds.rest.config;
|
|||
|
||||
import static org.jclouds.Constants.PROPERTY_TIMEOUTS_PREFIX;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
@ -46,6 +47,7 @@ import org.jclouds.rest.HttpClient;
|
|||
import org.jclouds.rest.binders.BindToJsonPayloadWrappedWith;
|
||||
import org.jclouds.rest.internal.AsyncRestClientProxy;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor.MethodKey;
|
||||
import org.jclouds.rest.internal.SeedAnnotationCache;
|
||||
import org.jclouds.util.Maps2;
|
||||
import org.jclouds.util.Predicates2;
|
||||
|
@ -53,6 +55,7 @@ import org.jclouds.util.Predicates2;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
@ -108,6 +111,18 @@ public class RestModule extends AbstractModule {
|
|||
installLocations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared for all types of rest clients. this is read-only in this class, and
|
||||
* currently populated only by {@link SeedAnnotationCache}
|
||||
*
|
||||
* @see SeedAnnotationCache
|
||||
*/
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Cache<MethodKey, Method> delegationMap(){
|
||||
return CacheBuilder.newBuilder().build();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("TIMEOUTS")
|
||||
|
|
|
@ -146,6 +146,7 @@ import com.google.common.base.Predicate;
|
|||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
@ -192,17 +193,7 @@ public class RestAnnotationProcessor<T> {
|
|||
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToPartParamAnnotations = createMethodToIndexOfParamToAnnotation(PartParam.class);
|
||||
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToParamParserAnnotations = createMethodToIndexOfParamToAnnotation(ParamParser.class);
|
||||
|
||||
/**
|
||||
* Shared for all types of rest clients. this is read-only in this class, and
|
||||
* currently populated only by {@link SeedAnnotationCache}
|
||||
*
|
||||
* @see SeedAnnotationCache
|
||||
*/
|
||||
// TODO: change this to a private final LoadingCache<MethodKey, Method>
|
||||
// supplied by guice. The CacheLoader<MethodKey, Method> can be refactored
|
||||
// out from SeedAnnotationCache. Potentially, preseed the cache, but only if
|
||||
// this is uncomplicated.
|
||||
static final Map<MethodKey, Method> delegationMap = newHashMap();
|
||||
final Cache<MethodKey, Method> delegationMap;
|
||||
|
||||
static LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> createMethodToIndexOfParamToAnnotation(
|
||||
final Class<? extends Annotation> annotation) {
|
||||
|
@ -331,7 +322,7 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Inject
|
||||
public RestAnnotationProcessor(Injector injector, LoadingCache<Class<?>, Boolean> seedAnnotationCache,
|
||||
public RestAnnotationProcessor(Injector injector, LoadingCache<Class<?>, Boolean> seedAnnotationCache, Cache<MethodKey, Method> delegationMap,
|
||||
@ApiVersion String apiVersion, @BuildVersion String buildVersion, ParseSax.Factory parserFactory,
|
||||
HttpUtils utils, ContentMetadataCodec contentMetadataCodec, TypeLiteral<T> typeLiteral) throws ExecutionException {
|
||||
this.declaring = (Class<T>) typeLiteral.getRawType();
|
||||
|
@ -342,6 +333,7 @@ public class RestAnnotationProcessor<T> {
|
|||
this.uriBuilderProvider = injector.getProvider(UriBuilder.class);
|
||||
this.seedAnnotationCache = seedAnnotationCache;
|
||||
seedAnnotationCache.get(declaring);
|
||||
this.delegationMap = delegationMap;
|
||||
if (declaring.isAnnotationPresent(SkipEncoding.class)) {
|
||||
skips = declaring.getAnnotation(SkipEncoding.class).value();
|
||||
} else {
|
||||
|
@ -351,8 +343,9 @@ public class RestAnnotationProcessor<T> {
|
|||
this.buildVersion = buildVersion;
|
||||
}
|
||||
|
||||
|
||||
public Method getDelegateOrNull(Method in) {
|
||||
return delegationMap.get(new MethodKey(in));
|
||||
return delegationMap.getIfPresent(new MethodKey(in));
|
||||
}
|
||||
|
||||
public static class MethodKey {
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.rest.internal;
|
||||
|
||||
import static com.google.common.collect.Sets.difference;
|
||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.delegationMap;
|
||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.getHttpMethods;
|
||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToBinderParamAnnotation;
|
||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToEndpointAnnotations;
|
||||
|
@ -48,6 +47,7 @@ import org.jclouds.rest.RestContext;
|
|||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor.MethodKey;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Inject;
|
||||
|
@ -68,10 +68,12 @@ public class SeedAnnotationCache extends CacheLoader<Class<?>, Boolean> {
|
|||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected final Injector injector;
|
||||
protected final Cache<MethodKey, Method> delegationMap;
|
||||
|
||||
@Inject
|
||||
public SeedAnnotationCache(Injector injector) {
|
||||
public SeedAnnotationCache(Injector injector, Cache<MethodKey, Method> delegationMap) {
|
||||
this.injector = injector;
|
||||
this.delegationMap = delegationMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue