Skip to content

Commit

Permalink
Issue ReactiveX#537: Resilience4j Aspects should be only available wh…
Browse files Browse the repository at this point in the history
…en AspectJ is on classpath
  • Loading branch information
RobWin authored Jul 26, 2019
1 parent 176eb21 commit f4577dc
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@

import io.github.resilience4j.bulkhead.BulkheadRegistry;
import io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry;
import io.github.resilience4j.bulkhead.configure.BulkheadAspect;
import io.github.resilience4j.bulkhead.configure.BulkheadAspectExt;
import io.github.resilience4j.bulkhead.configure.BulkheadConfiguration;
import io.github.resilience4j.bulkhead.configure.BulkheadConfigurationProperties;
import io.github.resilience4j.bulkhead.configure.ReactorBulkheadAspectExt;
import io.github.resilience4j.bulkhead.configure.RxJava2BulkheadAspectExt;
import io.github.resilience4j.bulkhead.configure.*;
import io.github.resilience4j.bulkhead.configure.threadpool.ThreadPoolBulkheadConfiguration;
import io.github.resilience4j.bulkhead.event.BulkheadEvent;
import io.github.resilience4j.common.bulkhead.configuration.ThreadPoolBulkheadConfigurationProperties;
import io.github.resilience4j.consumer.EventConsumerRegistry;
import io.github.resilience4j.fallback.FallbackDecorators;
import io.github.resilience4j.fallback.autoconfigure.FallbackConfigurationOnMissingBean;
import io.github.resilience4j.utils.AspectJOnClasspathCondition;
import io.github.resilience4j.utils.ReactorOnClasspathCondition;
import io.github.resilience4j.utils.RxJava2OnClasspathCondition;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -64,6 +60,7 @@ public BulkheadRegistry bulkheadRegistry(BulkheadConfigurationProperties bulkhea
}

@Bean
@Conditional(value = {AspectJOnClasspathCondition.class})
@ConditionalOnMissingBean
public BulkheadAspect bulkheadAspect(BulkheadConfigurationProperties bulkheadConfigurationProperties, ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry,
BulkheadRegistry bulkheadRegistry, @Autowired(required = false) List<BulkheadAspectExt> bulkHeadAspectExtList,
Expand All @@ -72,14 +69,14 @@ public BulkheadAspect bulkheadAspect(BulkheadConfigurationProperties bulkheadCon
}

@Bean
@Conditional(value = {RxJava2OnClasspathCondition.class})
@Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class})
@ConditionalOnMissingBean
public RxJava2BulkheadAspectExt rxJava2BulkHeadAspectExt() {
return bulkheadConfiguration.rxJava2BulkHeadAspectExt();
}

@Bean
@Conditional(value = {ReactorOnClasspathCondition.class})
@Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class})
@ConditionalOnMissingBean
public ReactorBulkheadAspectExt reactorBulkHeadAspectExt() {
return bulkheadConfiguration.reactorBulkHeadAspectExt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.github.resilience4j.consumer.EventConsumerRegistry;
import io.github.resilience4j.fallback.FallbackDecorators;
import io.github.resilience4j.fallback.autoconfigure.FallbackConfigurationOnMissingBean;
import io.github.resilience4j.utils.AspectJOnClasspathCondition;
import io.github.resilience4j.utils.ReactorOnClasspathCondition;
import io.github.resilience4j.utils.RxJava2OnClasspathCondition;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -67,21 +68,22 @@ public CircuitBreakerRegistry circuitBreakerRegistry(EventConsumerRegistry<Circu

@Bean
@ConditionalOnMissingBean
@Conditional(value = {AspectJOnClasspathCondition.class})
public CircuitBreakerAspect circuitBreakerAspect(CircuitBreakerRegistry circuitBreakerRegistry,
@Autowired(required = false) List<CircuitBreakerAspectExt> circuitBreakerAspectExtList,
FallbackDecorators fallbackDecorators) {
return circuitBreakerConfiguration.circuitBreakerAspect(circuitBreakerRegistry, circuitBreakerAspectExtList, fallbackDecorators);
}

@Bean
@Conditional(value = {RxJava2OnClasspathCondition.class})
@Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class})
@ConditionalOnMissingBean
public RxJava2CircuitBreakerAspectExt rxJava2CircuitBreakerAspect() {
return circuitBreakerConfiguration.rxJava2CircuitBreakerAspect();
}

@Bean
@Conditional(value = {ReactorOnClasspathCondition.class})
@Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class})
@ConditionalOnMissingBean
public ReactorCircuitBreakerAspectExt reactorCircuitBreakerAspect() {
return circuitBreakerConfiguration.reactorCircuitBreakerAspect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,23 @@
*/
package io.github.resilience4j.ratelimiter.autoconfigure;

import java.util.List;

import io.github.resilience4j.consumer.EventConsumerRegistry;
import io.github.resilience4j.fallback.FallbackDecorators;
import io.github.resilience4j.fallback.autoconfigure.FallbackConfigurationOnMissingBean;
import io.github.resilience4j.ratelimiter.RateLimiterRegistry;
import io.github.resilience4j.ratelimiter.configure.*;
import io.github.resilience4j.ratelimiter.event.RateLimiterEvent;
import io.github.resilience4j.utils.AspectJOnClasspathCondition;
import io.github.resilience4j.utils.ReactorOnClasspathCondition;
import io.github.resilience4j.utils.RxJava2OnClasspathCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import io.github.resilience4j.consumer.EventConsumerRegistry;
import io.github.resilience4j.ratelimiter.RateLimiterRegistry;
import io.github.resilience4j.ratelimiter.configure.RateLimiterAspect;
import io.github.resilience4j.ratelimiter.configure.RateLimiterAspectExt;
import io.github.resilience4j.ratelimiter.configure.RateLimiterConfiguration;
import io.github.resilience4j.ratelimiter.configure.RateLimiterConfigurationProperties;
import io.github.resilience4j.ratelimiter.configure.ReactorRateLimiterAspectExt;
import io.github.resilience4j.ratelimiter.configure.RxJava2RateLimiterAspectExt;
import io.github.resilience4j.ratelimiter.event.RateLimiterEvent;
import io.github.resilience4j.fallback.FallbackDecorators;
import io.github.resilience4j.fallback.autoconfigure.FallbackConfigurationOnMissingBean;
import io.github.resilience4j.utils.ReactorOnClasspathCondition;
import io.github.resilience4j.utils.RxJava2OnClasspathCondition;
import java.util.List;

@Configuration
@Import(FallbackConfigurationOnMissingBean.class)
Expand All @@ -55,20 +50,21 @@ public RateLimiterRegistry rateLimiterRegistry(RateLimiterConfigurationPropertie
}

@Bean
@Conditional(value = {AspectJOnClasspathCondition.class})
@ConditionalOnMissingBean
public RateLimiterAspect rateLimiterAspect(RateLimiterConfigurationProperties rateLimiterProperties, RateLimiterRegistry rateLimiterRegistry, @Autowired(required = false) List<RateLimiterAspectExt> rateLimiterAspectExtList, FallbackDecorators fallbackDecorators) {
return rateLimiterConfiguration.rateLimiterAspect(rateLimiterProperties, rateLimiterRegistry, rateLimiterAspectExtList, fallbackDecorators);
}

@Bean
@Conditional(value = {RxJava2OnClasspathCondition.class})
@Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class})
@ConditionalOnMissingBean
public RxJava2RateLimiterAspectExt rxJava2RateLimterAspectExt() {
return rateLimiterConfiguration.rxJava2RateLimterAspectExt();
public RxJava2RateLimiterAspectExt rxJava2RateLimiterAspectExt() {
return rateLimiterConfiguration.rxJava2RateLimiterAspectExt();
}

@Bean
@Conditional(value = {ReactorOnClasspathCondition.class})
@Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class})
@ConditionalOnMissingBean
public ReactorRateLimiterAspectExt reactorRateLimiterAspectExt() {
return rateLimiterConfiguration.reactorRateLimiterAspectExt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,23 @@
*/
package io.github.resilience4j.retry.autoconfigure;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import io.github.resilience4j.consumer.EventConsumerRegistry;
import io.github.resilience4j.fallback.FallbackDecorators;
import io.github.resilience4j.fallback.autoconfigure.FallbackConfigurationOnMissingBean;
import io.github.resilience4j.retry.RetryRegistry;
import io.github.resilience4j.retry.configure.ReactorRetryAspectExt;
import io.github.resilience4j.retry.configure.RetryAspect;
import io.github.resilience4j.retry.configure.RetryAspectExt;
import io.github.resilience4j.retry.configure.RetryConfiguration;
import io.github.resilience4j.retry.configure.RetryConfigurationProperties;
import io.github.resilience4j.retry.configure.RxJava2RetryAspectExt;
import io.github.resilience4j.retry.configure.*;
import io.github.resilience4j.retry.event.RetryEvent;
import io.github.resilience4j.utils.AspectJOnClasspathCondition;
import io.github.resilience4j.utils.ReactorOnClasspathCondition;
import io.github.resilience4j.utils.RxJava2OnClasspathCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import java.util.List;

/**
* {@link Configuration
Expand Down Expand Up @@ -69,6 +64,7 @@ public RetryRegistry retryRegistry(RetryConfigurationProperties retryConfigurati
* @return the spring retry AOP aspect
*/
@Bean
@Conditional(value = {AspectJOnClasspathCondition.class})
@ConditionalOnMissingBean
public RetryAspect retryAspect(RetryConfigurationProperties retryConfigurationProperties,
RetryRegistry retryRegistry, @Autowired(required = false) List<RetryAspectExt> retryAspectExtList,
Expand All @@ -77,14 +73,14 @@ public RetryAspect retryAspect(RetryConfigurationProperties retryConfigurationPr
}

@Bean
@Conditional(value = {RxJava2OnClasspathCondition.class})
@Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class})
@ConditionalOnMissingBean
public RxJava2RetryAspectExt rxJava2RetryAspectExt() {
return retryConfiguration.rxJava2RetryAspectExt();
}

@Bean
@Conditional(value = {ReactorOnClasspathCondition.class})
@Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class})
@ConditionalOnMissingBean
public ReactorRetryAspectExt reactorRetryAspectExt() {
return retryConfiguration.reactorRetryAspectExt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void testRetryCommonConfig() {
public void testRateLimiterCommonConfig() {
RateLimiterConfigurationOnMissingBean rateLimiterConfigurationOnMissingBean = new RateLimiterConfigurationOnMissingBean();
assertThat(rateLimiterConfigurationOnMissingBean.reactorRateLimiterAspectExt()).isNotNull();
assertThat(rateLimiterConfigurationOnMissingBean.rxJava2RateLimterAspectExt()).isNotNull();
assertThat(rateLimiterConfigurationOnMissingBean.rxJava2RateLimiterAspectExt()).isNotNull();
assertThat(rateLimiterConfigurationOnMissingBean.rateLimiterRegistry(new RateLimiterConfigurationProperties(), new DefaultEventConsumerRegistry<>())).isNotNull();
assertThat(rateLimiterConfigurationOnMissingBean.rateLimiterAspect(new RateLimiterConfigurationProperties(), RateLimiterRegistry.ofDefaults(), Collections.emptyList(), new FallbackDecorators(Arrays.asList(new CompletionStageFallbackDecorator()))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@
*/
package io.github.resilience4j.bulkhead.configure;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import io.github.resilience4j.bulkhead.Bulkhead;
import io.github.resilience4j.bulkhead.BulkheadConfig;
import io.github.resilience4j.bulkhead.BulkheadRegistry;
Expand All @@ -36,8 +25,19 @@
import io.github.resilience4j.consumer.EventConsumerRegistry;
import io.github.resilience4j.fallback.FallbackDecorators;
import io.github.resilience4j.fallback.configure.FallbackConfiguration;
import io.github.resilience4j.utils.AspectJOnClasspathCondition;
import io.github.resilience4j.utils.ReactorOnClasspathCondition;
import io.github.resilience4j.utils.RxJava2OnClasspathCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* {@link Configuration
Expand Down Expand Up @@ -94,20 +94,21 @@ private void registerEventConsumer(EventConsumerRegistry<BulkheadEvent> eventCon
}

@Bean
@Conditional(value = {AspectJOnClasspathCondition.class})
public BulkheadAspect bulkheadAspect(BulkheadConfigurationProperties bulkheadConfigurationProperties, ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry,
BulkheadRegistry bulkheadRegistry, @Autowired(required = false) List<BulkheadAspectExt> bulkHeadAspectExtList,
FallbackDecorators fallbackDecorators) {
return new BulkheadAspect(bulkheadConfigurationProperties, threadPoolBulkheadRegistry, bulkheadRegistry, bulkHeadAspectExtList, fallbackDecorators);
}

@Bean
@Conditional(value = {RxJava2OnClasspathCondition.class})
@Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class})
public RxJava2BulkheadAspectExt rxJava2BulkHeadAspectExt() {
return new RxJava2BulkheadAspectExt();
}

@Bean
@Conditional(value = {ReactorOnClasspathCondition.class})
@Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class})
public ReactorBulkheadAspectExt reactorBulkHeadAspectExt() {
return new ReactorBulkheadAspectExt();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
*/
package io.github.resilience4j.circuitbreaker.configure;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import io.github.resilience4j.circuitbreaker.CircuitBreaker;
import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry;
import io.github.resilience4j.circuitbreaker.event.CircuitBreakerEvent;
import io.github.resilience4j.consumer.DefaultEventConsumerRegistry;
import io.github.resilience4j.consumer.EventConsumerRegistry;
import io.github.resilience4j.fallback.FallbackDecorators;
import io.github.resilience4j.utils.AspectJOnClasspathCondition;
import io.github.resilience4j.utils.ReactorOnClasspathCondition;
import io.github.resilience4j.utils.RxJava2OnClasspathCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* {@link org.springframework.context.annotation.Configuration
Expand All @@ -56,6 +56,7 @@ public CircuitBreakerRegistry circuitBreakerRegistry(EventConsumerRegistry<Circu
}

@Bean
@Conditional(value = {AspectJOnClasspathCondition.class})
public CircuitBreakerAspect circuitBreakerAspect(CircuitBreakerRegistry circuitBreakerRegistry,
@Autowired(required = false) List<CircuitBreakerAspectExt> circuitBreakerAspectExtList,
FallbackDecorators fallbackDecorators) {
Expand All @@ -64,13 +65,13 @@ public CircuitBreakerAspect circuitBreakerAspect(CircuitBreakerRegistry circuitB


@Bean
@Conditional(value = {RxJava2OnClasspathCondition.class})
@Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class})
public RxJava2CircuitBreakerAspectExt rxJava2CircuitBreakerAspect() {
return new RxJava2CircuitBreakerAspectExt();
}

@Bean
@Conditional(value = {ReactorOnClasspathCondition.class})
@Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class})
public ReactorCircuitBreakerAspectExt reactorCircuitBreakerAspect() {
return new ReactorCircuitBreakerAspectExt();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
package io.github.resilience4j.ratelimiter.configure;


import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import io.github.resilience4j.consumer.DefaultEventConsumerRegistry;
import io.github.resilience4j.consumer.EventConsumerRegistry;
import io.github.resilience4j.fallback.FallbackDecorators;
import io.github.resilience4j.ratelimiter.RateLimiter;
import io.github.resilience4j.ratelimiter.RateLimiterConfig;
import io.github.resilience4j.ratelimiter.RateLimiterRegistry;
import io.github.resilience4j.ratelimiter.event.RateLimiterEvent;
import io.github.resilience4j.utils.AspectJOnClasspathCondition;
import io.github.resilience4j.utils.ReactorOnClasspathCondition;
import io.github.resilience4j.utils.RxJava2OnClasspathCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* {@link org.springframework.context.annotation.Configuration
Expand Down Expand Up @@ -86,18 +86,19 @@ private void registerEventConsumer(EventConsumerRegistry<RateLimiterEvent> event
}

@Bean
@Conditional(value = {AspectJOnClasspathCondition.class})
public RateLimiterAspect rateLimiterAspect(RateLimiterConfigurationProperties rateLimiterProperties, RateLimiterRegistry rateLimiterRegistry, @Autowired(required = false) List<RateLimiterAspectExt> rateLimiterAspectExtList, FallbackDecorators fallbackDecorators) {
return new RateLimiterAspect(rateLimiterRegistry, rateLimiterProperties, rateLimiterAspectExtList, fallbackDecorators);
}

@Bean
@Conditional(value = {RxJava2OnClasspathCondition.class})
public RxJava2RateLimiterAspectExt rxJava2RateLimterAspectExt() {
@Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class})
public RxJava2RateLimiterAspectExt rxJava2RateLimiterAspectExt() {
return new RxJava2RateLimiterAspectExt();
}

@Bean
@Conditional(value = {ReactorOnClasspathCondition.class})
@Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class})
public ReactorRateLimiterAspectExt reactorRateLimiterAspectExt() {
return new ReactorRateLimiterAspectExt();
}
Expand Down
Loading

0 comments on commit f4577dc

Please sign in to comment.