mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 15:08:28 +00:00
removed static field-based state sharing when looking up delegate methods
This commit is contained in:
parent
bd59b3e25f
commit
38f8f98b16
@ -20,6 +20,7 @@ package org.jclouds.rest.config;
|
|||||||
|
|
||||||
import static org.jclouds.Constants.PROPERTY_TIMEOUTS_PREFIX;
|
import static org.jclouds.Constants.PROPERTY_TIMEOUTS_PREFIX;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
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.binders.BindToJsonPayloadWrappedWith;
|
||||||
import org.jclouds.rest.internal.AsyncRestClientProxy;
|
import org.jclouds.rest.internal.AsyncRestClientProxy;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
|
import org.jclouds.rest.internal.RestAnnotationProcessor.MethodKey;
|
||||||
import org.jclouds.rest.internal.SeedAnnotationCache;
|
import org.jclouds.rest.internal.SeedAnnotationCache;
|
||||||
import org.jclouds.util.Maps2;
|
import org.jclouds.util.Maps2;
|
||||||
import org.jclouds.util.Predicates2;
|
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.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
@ -107,7 +110,19 @@ public class RestModule extends AbstractModule {
|
|||||||
}).to(FilterStringsBoundToInjectorByName.class);
|
}).to(FilterStringsBoundToInjectorByName.class);
|
||||||
installLocations();
|
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
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named("TIMEOUTS")
|
@Named("TIMEOUTS")
|
||||||
|
@ -146,6 +146,7 @@ import com.google.common.base.Predicate;
|
|||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
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>>> methodToIndexOfParamToPartParamAnnotations = createMethodToIndexOfParamToAnnotation(PartParam.class);
|
||||||
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToParamParserAnnotations = createMethodToIndexOfParamToAnnotation(ParamParser.class);
|
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToParamParserAnnotations = createMethodToIndexOfParamToAnnotation(ParamParser.class);
|
||||||
|
|
||||||
/**
|
final Cache<MethodKey, Method> delegationMap;
|
||||||
* 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();
|
|
||||||
|
|
||||||
static LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> createMethodToIndexOfParamToAnnotation(
|
static LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> createMethodToIndexOfParamToAnnotation(
|
||||||
final Class<? extends Annotation> annotation) {
|
final Class<? extends Annotation> annotation) {
|
||||||
@ -331,7 +322,7 @@ public class RestAnnotationProcessor<T> {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Inject
|
@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,
|
@ApiVersion String apiVersion, @BuildVersion String buildVersion, ParseSax.Factory parserFactory,
|
||||||
HttpUtils utils, ContentMetadataCodec contentMetadataCodec, TypeLiteral<T> typeLiteral) throws ExecutionException {
|
HttpUtils utils, ContentMetadataCodec contentMetadataCodec, TypeLiteral<T> typeLiteral) throws ExecutionException {
|
||||||
this.declaring = (Class<T>) typeLiteral.getRawType();
|
this.declaring = (Class<T>) typeLiteral.getRawType();
|
||||||
@ -342,6 +333,7 @@ public class RestAnnotationProcessor<T> {
|
|||||||
this.uriBuilderProvider = injector.getProvider(UriBuilder.class);
|
this.uriBuilderProvider = injector.getProvider(UriBuilder.class);
|
||||||
this.seedAnnotationCache = seedAnnotationCache;
|
this.seedAnnotationCache = seedAnnotationCache;
|
||||||
seedAnnotationCache.get(declaring);
|
seedAnnotationCache.get(declaring);
|
||||||
|
this.delegationMap = delegationMap;
|
||||||
if (declaring.isAnnotationPresent(SkipEncoding.class)) {
|
if (declaring.isAnnotationPresent(SkipEncoding.class)) {
|
||||||
skips = declaring.getAnnotation(SkipEncoding.class).value();
|
skips = declaring.getAnnotation(SkipEncoding.class).value();
|
||||||
} else {
|
} else {
|
||||||
@ -351,8 +343,9 @@ public class RestAnnotationProcessor<T> {
|
|||||||
this.buildVersion = buildVersion;
|
this.buildVersion = buildVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Method getDelegateOrNull(Method in) {
|
public Method getDelegateOrNull(Method in) {
|
||||||
return delegationMap.get(new MethodKey(in));
|
return delegationMap.getIfPresent(new MethodKey(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MethodKey {
|
public static class MethodKey {
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
package org.jclouds.rest.internal;
|
package org.jclouds.rest.internal;
|
||||||
|
|
||||||
import static com.google.common.collect.Sets.difference;
|
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.getHttpMethods;
|
||||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToBinderParamAnnotation;
|
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToBinderParamAnnotation;
|
||||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToEndpointAnnotations;
|
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.annotations.Delegate;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor.MethodKey;
|
import org.jclouds.rest.internal.RestAnnotationProcessor.MethodKey;
|
||||||
|
|
||||||
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@ -68,10 +68,12 @@ public class SeedAnnotationCache extends CacheLoader<Class<?>, Boolean> {
|
|||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
protected final Injector injector;
|
protected final Injector injector;
|
||||||
|
protected final Cache<MethodKey, Method> delegationMap;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SeedAnnotationCache(Injector injector) {
|
public SeedAnnotationCache(Injector injector, Cache<MethodKey, Method> delegationMap) {
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
|
this.delegationMap = delegationMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user