use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.
the class JoinPointMonitorAtAspectJAspect method checkXmlAspect.
private void checkXmlAspect(String appContextFile) {
ApplicationContext context = new ClassPathXmlApplicationContext(appContextFile, getClass());
ICounter counter = (ICounter) context.getBean("counter");
boolean condition = counter instanceof Advised;
assertThat(condition).as("Proxy didn't get created").isTrue();
counter.increment();
JoinPointMonitorAspect callCountingAspect = (JoinPointMonitorAspect) context.getBean("monitoringAspect");
assertThat(callCountingAspect.beforeExecutions).as("Advise didn't get executed").isEqualTo(1);
assertThat(callCountingAspect.aroundExecutions).as("Advise didn't get executed").isEqualTo(1);
}
use of org.springframework.aop.framework.Advised in project spring-cloud-stream by spring-cloud.
the class BindingService method bindConsumer.
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> Collection<Binding<T>> bindConsumer(T input, String inputName) {
Collection<Binding<T>> bindings = new ArrayList<>();
Class<?> inputClass = input.getClass();
if (input instanceof Advised) {
inputClass = Stream.of(((Advised) input).getProxiedInterfaces()).filter(c -> !c.getName().contains("org.springframework")).findFirst().orElse(inputClass);
}
Binder<T, ConsumerProperties, ?> binder = (Binder<T, ConsumerProperties, ?>) getBinder(inputName, inputClass);
ConsumerProperties consumerProperties = this.bindingServiceProperties.getConsumerProperties(inputName);
if (binder instanceof ExtendedPropertiesBinder) {
Object extension = ((ExtendedPropertiesBinder) binder).getExtendedConsumerProperties(inputName);
ExtendedConsumerProperties extendedConsumerProperties = new ExtendedConsumerProperties(extension);
BeanUtils.copyProperties(consumerProperties, extendedConsumerProperties);
consumerProperties = extendedConsumerProperties;
}
validate(consumerProperties);
String bindingTarget = this.bindingServiceProperties.getBindingDestination(inputName);
if (consumerProperties.isMultiplex()) {
bindings.add(doBindConsumer(input, inputName, binder, consumerProperties, bindingTarget));
} else {
String[] bindingTargets = StringUtils.commaDelimitedListToStringArray(bindingTarget);
for (String target : bindingTargets) {
if (!consumerProperties.isPartitioned() || consumerProperties.getInstanceIndexList().isEmpty()) {
Binding<T> binding = input instanceof PollableSource ? doBindPollableConsumer(input, inputName, binder, consumerProperties, target) : doBindConsumer(input, inputName, binder, consumerProperties, target);
bindings.add(binding);
} else {
for (Integer index : consumerProperties.getInstanceIndexList()) {
if (index < 0) {
continue;
}
ConsumerProperties consumerPropertiesTemp = new ExtendedConsumerProperties<>("");
BeanUtils.copyProperties(consumerProperties, consumerPropertiesTemp);
consumerPropertiesTemp.setInstanceIndex(index);
Binding<T> binding = input instanceof PollableSource ? doBindPollableConsumer(input, inputName, binder, consumerPropertiesTemp, target) : doBindConsumer(input, inputName, binder, consumerPropertiesTemp, target);
bindings.add(binding);
}
}
}
}
bindings = Collections.unmodifiableCollection(bindings);
this.consumerBindings.put(inputName, new ArrayList<>(bindings));
return bindings;
}
use of org.springframework.aop.framework.Advised in project spring-cloud-stream by spring-cloud.
the class BindingService method bindProducer.
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> Binding<T> bindProducer(T output, String outputName, boolean cache, @Nullable Binder<T, ?, ProducerProperties> binder) {
String bindingTarget = this.bindingServiceProperties.getBindingDestination(outputName);
Class<?> outputClass = output.getClass();
if (output instanceof Advised) {
outputClass = Stream.of(((Advised) output).getProxiedInterfaces()).filter(c -> !c.getName().contains("org.springframework")).findFirst().orElse(outputClass);
}
if (binder == null) {
binder = (Binder<T, ?, ProducerProperties>) getBinder(outputName, outputClass);
}
ProducerProperties producerProperties = this.bindingServiceProperties.getProducerProperties(outputName);
if (binder instanceof ExtendedPropertiesBinder) {
Object extension = ((ExtendedPropertiesBinder) binder).getExtendedProducerProperties(outputName);
ExtendedProducerProperties extendedProducerProperties = new ExtendedProducerProperties<>(extension);
BeanUtils.copyProperties(producerProperties, extendedProducerProperties);
producerProperties = extendedProducerProperties;
}
validate(producerProperties);
Binding<T> binding = doBindProducer(output, bindingTarget, binder, producerProperties);
if (cache) {
this.producerBindings.put(outputName, binding);
}
return binding;
}
Aggregations