use of org.springframework.beans.factory.BeanFactory in project spring-cloud-sleuth by spring-cloud.
the class ExecutorMethodInterceptor method createThreadPoolTaskExecutorProxy.
Object createThreadPoolTaskExecutorProxy(Object bean, boolean cglibProxy, ThreadPoolTaskExecutor executor) {
ProxyFactoryBean factory = new ProxyFactoryBean();
factory.setProxyTargetClass(cglibProxy);
factory.addAdvice(new ExecutorMethodInterceptor<ThreadPoolTaskExecutor>(executor, this.beanFactory) {
@Override
Executor executor(BeanFactory beanFactory, ThreadPoolTaskExecutor executor) {
return new LazyTraceThreadPoolTaskExecutor(beanFactory, executor);
}
});
factory.setTarget(bean);
return factory.getObject();
}
use of org.springframework.beans.factory.BeanFactory in project bucket4j-spring-boot-starter by MarcGiffing.
the class Bucket4JBaseConfiguration method buildFilterConfig.
public FilterConfiguration buildFilterConfig(Bucket4JConfiguration config, CacheManager cacheManager, ExpressionParser expressionParser, BeanFactory beanFactory) {
FilterConfiguration filterConfig = new FilterConfiguration();
filterConfig.setUrl(config.getUrl());
filterConfig.setOrder(config.getFilterOrder());
filterConfig.setStrategy(config.getStrategy());
filterConfig.setHttpResponseBody(config.getHttpResponseBody());
ProxyManager<String> buckets = Bucket4j.extension(JCache.class).proxyManagerForCache(jCache(config.getCacheName(), cacheManager));
config.getRateLimits().forEach(rl -> {
ConfigurationBuilder<?> configBuilder = Bucket4j.configurationBuilder();
for (BandWidthConfig bandWidth : rl.getBandwidths()) {
configBuilder = configBuilder.addLimit(Bandwidth.simple(bandWidth.getCapacity(), Duration.of(bandWidth.getTime(), bandWidth.getUnit())));
}
;
final ConfigurationBuilder<?> configBuilderToUse = configBuilder;
RateLimitCheck rlc = (servletRequest) -> {
boolean skipRateLimit = false;
if (rl.getSkipCondition() != null) {
skipRateLimit = skipCondition(rl, expressionParser, beanFactory).evalute(servletRequest);
}
if (rl.getExecuteCondition() != null && !skipRateLimit) {
skipRateLimit = !executeCondition(rl, expressionParser, beanFactory).evalute(servletRequest);
}
if (!skipRateLimit) {
String key = getKeyFilter(filterConfig.getUrl(), rl, expressionParser, beanFactory).key(servletRequest);
Bucket bucket = buckets.getProxy(key, () -> configBuilderToUse.buildConfiguration());
ConsumptionProbe probe = bucket.tryConsumeAndReturnRemaining(1);
return probe;
}
return null;
};
filterConfig.getRateLimitChecks().add(rlc);
});
return filterConfig;
}
use of org.springframework.beans.factory.BeanFactory in project bucket4j-spring-boot-starter by MarcGiffing.
the class Bucket4JBaseConfiguration method getKeyFilter.
/**
* Creates the key filter lambda which is responsible to decide how the rate limit will be performed. The key
* is the unique identifier like an IP address or a username.
*
* @param url is used to generated a unique cache key
* @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
* @param expressionParser is used to evaluate the expression if the filter key type is EXPRESSION.
* @param beanFactory used to get full access to all java beans in the SpEl
* @return should not been null. If no filter key type is matching a plain 1 is returned so that all requests uses the same key.
*/
public KeyFilter getKeyFilter(String url, RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
switch(rateLimit.getFilterKeyType()) {
case IP:
return (request) -> url + "-" + request.getRemoteAddr();
case EXPRESSION:
String expression = rateLimit.getExpression();
if (StringUtils.isEmpty(expression)) {
throw new MissingKeyFilterExpressionException();
}
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new BeanFactoryResolver(beanFactory));
return (request) -> {
// TODO performance problem - how can the request object reused in the expression without setting it as a rootObject
Expression expr = expressionParser.parseExpression(rateLimit.getExpression());
final String value = expr.getValue(context, request, String.class);
return url + "-" + value;
};
}
return (request) -> url + "-" + "1";
}
use of org.springframework.beans.factory.BeanFactory in project mule by mulesoft.
the class DefaultListableBeanFactory method setAutowireCandidateResolver.
/**
* Set a custom autowire candidate resolver for this BeanFactory to use when deciding whether a bean definition should be
* considered as a candidate for autowiring.
*/
public void setAutowireCandidateResolver(final AutowireCandidateResolver autowireCandidateResolver) {
Assert.notNull(autowireCandidateResolver, "AutowireCandidateResolver must not be null");
if (autowireCandidateResolver instanceof BeanFactoryAware) {
if (System.getSecurityManager() != null) {
final BeanFactory target = this;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(target);
return null;
}
}, getAccessControlContext());
} else {
((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(this);
}
}
this.autowireCandidateResolver = autowireCandidateResolver;
}
use of org.springframework.beans.factory.BeanFactory in project grails-core by grails.
the class ClosureClassIgnoringComponentScanBeanDefinitionParser method createScanner.
@Override
protected ClassPathBeanDefinitionScanner createScanner(XmlReaderContext readerContext, boolean useDefaultFilters) {
final ClassPathBeanDefinitionScanner scanner = super.createScanner(readerContext, useDefaultFilters);
BeanDefinitionRegistry beanDefinitionRegistry = readerContext.getRegistry();
GrailsPluginManager pluginManager = null;
if (beanDefinitionRegistry instanceof HierarchicalBeanFactory) {
HierarchicalBeanFactory beanFactory = (HierarchicalBeanFactory) beanDefinitionRegistry;
BeanFactory parent = beanFactory.getParentBeanFactory();
if (parent != null && parent.containsBean(GrailsPluginManager.BEAN_NAME)) {
pluginManager = parent.getBean(GrailsPluginManager.BEAN_NAME, GrailsPluginManager.class);
}
}
if (pluginManager != null) {
List<TypeFilter> typeFilters = pluginManager.getTypeFilters();
for (TypeFilter typeFilter : typeFilters) {
scanner.addIncludeFilter(typeFilter);
}
}
return scanner;
}
Aggregations