Polishing

This commit is contained in:
Juergen Hoeller 2023-11-16 11:22:09 +01:00
parent b0e29acd23
commit 99378fe947
7 changed files with 28 additions and 27 deletions

View File

@ -33,12 +33,13 @@ import org.springframework.util.ClassUtils;
*/ */
class AspectJAdvisorBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor { class AspectJAdvisorBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
private static final boolean aspectJPresent = ClassUtils.isPresent("org.aspectj.lang.annotation.Pointcut", private static final boolean aspectjPresent = ClassUtils.isPresent("org.aspectj.lang.annotation.Pointcut",
AspectJAdvisorBeanRegistrationAotProcessor.class.getClassLoader()); AspectJAdvisorBeanRegistrationAotProcessor.class.getClassLoader());
@Override @Override
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
if (aspectJPresent) { if (aspectjPresent) {
Class<?> beanClass = registeredBean.getBeanClass(); Class<?> beanClass = registeredBean.getBeanClass();
if (AbstractAspectJAdvisorFactory.compiledByAjc(beanClass)) { if (AbstractAspectJAdvisorFactory.compiledByAjc(beanClass)) {
return new AspectJAdvisorContribution(beanClass); return new AspectJAdvisorContribution(beanClass);
@ -47,6 +48,7 @@ class AspectJAdvisorBeanRegistrationAotProcessor implements BeanRegistrationAotP
return null; return null;
} }
private static class AspectJAdvisorContribution implements BeanRegistrationAotContribution { private static class AspectJAdvisorContribution implements BeanRegistrationAotContribution {
private final Class<?> beanClass; private final Class<?> beanClass;

View File

@ -40,11 +40,12 @@ import org.springframework.util.ClassUtils;
*/ */
class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor { class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor {
private static final boolean aspectJPresent = ClassUtils.isPresent( private static final boolean aspectJPresent = ClassUtils.isPresent("org.aspectj.lang.annotation.Pointcut",
"org.aspectj.lang.annotation.Pointcut", AspectJBeanFactoryInitializationAotProcessor.class.getClassLoader()); AspectJBeanFactoryInitializationAotProcessor.class.getClassLoader());
@Nullable
@Override @Override
@Nullable
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
if (aspectJPresent) { if (aspectJPresent) {
return AspectDelegate.processAheadOfTime(beanFactory); return AspectDelegate.processAheadOfTime(beanFactory);
@ -52,6 +53,7 @@ class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitial
return null; return null;
} }
/** /**
* Inner class to avoid a hard dependency on AspectJ at runtime. * Inner class to avoid a hard dependency on AspectJ at runtime.
*/ */
@ -63,7 +65,6 @@ class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitial
List<Advisor> advisors = builder.buildAspectJAdvisors(); List<Advisor> advisors = builder.buildAspectJAdvisors();
return (advisors.isEmpty() ? null : new AspectContribution(advisors)); return (advisors.isEmpty() ? null : new AspectContribution(advisors));
} }
} }
@ -84,7 +85,6 @@ class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitial
} }
} }
} }
} }
} }

View File

@ -42,14 +42,14 @@ import org.springframework.util.MimeTypeUtils;
*/ */
public final class CharBufferDecoder extends AbstractCharSequenceDecoder<CharBuffer> { public final class CharBufferDecoder extends AbstractCharSequenceDecoder<CharBuffer> {
public CharBufferDecoder(List<String> delimiters, boolean stripDelimiter, MimeType... mimeTypes) { public CharBufferDecoder(List<String> delimiters, boolean stripDelimiter, MimeType... mimeTypes) {
super(delimiters, stripDelimiter, mimeTypes); super(delimiters, stripDelimiter, mimeTypes);
} }
@Override @Override
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) { public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
return elementType.resolve() == CharBuffer.class && super.canDecode(elementType, mimeType); return (elementType.resolve() == CharBuffer.class) && super.canDecode(elementType, mimeType);
} }
@Override @Override
@ -70,8 +70,7 @@ public final class CharBufferDecoder extends AbstractCharSequenceDecoder<CharBuf
/** /**
* Create a {@code CharBufferDecoder} for {@code "text/plain"}. * Create a {@code CharBufferDecoder} for {@code "text/plain"}.
* @param delimiters delimiter strings to use to split the input stream * @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting * @param stripDelimiter whether to remove delimiters from the resulting input strings
* input strings
*/ */
public static CharBufferDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter) { public static CharBufferDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter) {
var textPlain = new MimeType("text", "plain", DEFAULT_CHARSET); var textPlain = new MimeType("text", "plain", DEFAULT_CHARSET);
@ -88,8 +87,7 @@ public final class CharBufferDecoder extends AbstractCharSequenceDecoder<CharBuf
/** /**
* Create a {@code CharBufferDecoder} that supports all MIME types. * Create a {@code CharBufferDecoder} that supports all MIME types.
* @param delimiters delimiter strings to use to split the input stream * @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting * @param stripDelimiter whether to remove delimiters from the resulting input strings
* input strings
*/ */
public static CharBufferDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter) { public static CharBufferDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter) {
var textPlain = new MimeType("text", "plain", DEFAULT_CHARSET); var textPlain = new MimeType("text", "plain", DEFAULT_CHARSET);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -51,8 +51,7 @@ public final class CharSequenceEncoder extends AbstractEncoder<CharSequence> {
*/ */
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
private final ConcurrentMap<Charset, Float> charsetToMaxBytesPerChar = private final ConcurrentMap<Charset, Float> charsetToMaxBytesPerChar = new ConcurrentHashMap<>(3);
new ConcurrentHashMap<>(3);
private CharSequenceEncoder(MimeType... mimeTypes) { private CharSequenceEncoder(MimeType... mimeTypes) {
@ -105,8 +104,8 @@ public final class CharSequenceEncoder extends AbstractEncoder<CharSequence> {
} }
int calculateCapacity(CharSequence sequence, Charset charset) { int calculateCapacity(CharSequence sequence, Charset charset) {
float maxBytesPerChar = this.charsetToMaxBytesPerChar float maxBytesPerChar = this.charsetToMaxBytesPerChar.computeIfAbsent(charset,
.computeIfAbsent(charset, cs -> cs.newEncoder().maxBytesPerChar()); cs -> cs.newEncoder().maxBytesPerChar());
float maxBytesForSequence = sequence.length() * maxBytesPerChar; float maxBytesForSequence = sequence.length() * maxBytesPerChar;
return (int) Math.ceil(maxBytesForSequence); return (int) Math.ceil(maxBytesForSequence);
} }

View File

@ -68,8 +68,8 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
public void subscribe(Subscriber<? super DataBuffer> subscriber) { public void subscribe(Subscriber<? super DataBuffer> subscriber) {
Objects.requireNonNull(subscriber, "Subscriber must not be null"); Objects.requireNonNull(subscriber, "Subscriber must not be null");
OutputStreamSubscription subscription = new OutputStreamSubscription(subscriber, this.outputStreamConsumer, OutputStreamSubscription subscription = new OutputStreamSubscription(
this.bufferFactory, this.chunkSize); subscriber, this.outputStreamConsumer, this.bufferFactory, this.chunkSize);
subscriber.onSubscribe(subscription); subscriber.onSubscribe(subscription);
this.executor.execute(subscription::invokeHandler); this.executor.execute(subscription::invokeHandler);
@ -80,7 +80,6 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
private static final Object READY = new Object(); private static final Object READY = new Object();
private final Subscriber<? super DataBuffer> actual; private final Subscriber<? super DataBuffer> actual;
private final Consumer<OutputStream> outputStreamHandler; private final Consumer<OutputStream> outputStreamHandler;
@ -98,7 +97,6 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
private long produced; private long produced;
OutputStreamSubscription(Subscriber<? super DataBuffer> actual, OutputStreamSubscription(Subscriber<? super DataBuffer> actual,
Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, int chunkSize) { Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, int chunkSize) {
@ -351,4 +349,5 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
return res; return res;
} }
} }
} }

View File

@ -22,8 +22,9 @@ import io.micrometer.context.ContextSnapshotFactory;
import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.TaskDecorator;
/** /**
* {@link TaskDecorator} that {@link ContextSnapshot#wrap(Runnable) wraps the execution} of * {@link TaskDecorator} that {@link ContextSnapshot#wrap(Runnable) wraps the execution}
* tasks, assisting with context propagation. * of tasks, assisting with context propagation.
*
* <p>This operation is only useful when the task execution is scheduled on a different * <p>This operation is only useful when the task execution is scheduled on a different
* thread than the original call stack; this depends on the choice of * thread than the original call stack; this depends on the choice of
* {@link org.springframework.core.task.TaskExecutor}. This is particularly useful for * {@link org.springframework.core.task.TaskExecutor}. This is particularly useful for
@ -39,6 +40,7 @@ public class ContextPropagatingTaskDecorator implements TaskDecorator {
private final ContextSnapshotFactory factory; private final ContextSnapshotFactory factory;
/** /**
* Create a new decorator that uses a default instance of the {@link ContextSnapshotFactory}. * Create a new decorator that uses a default instance of the {@link ContextSnapshotFactory}.
*/ */
@ -54,6 +56,7 @@ public class ContextPropagatingTaskDecorator implements TaskDecorator {
this.factory = factory; this.factory = factory;
} }
@Override @Override
public Runnable decorate(Runnable runnable) { public Runnable decorate(Runnable runnable) {
return this.factory.captureAll().wrap(runnable); return this.factory.captureAll().wrap(runnable);

View File

@ -54,7 +54,7 @@ public interface StreamingHttpOutputMessage extends HttpOutputMessage {
/** /**
* Indicates whether this body is capable of * Indicates whether this body is capable of
* {@linkplain #writeTo(OutputStream) writing its data} more than * {@linkplain #writeTo(OutputStream) writing its data} more than
* once. Default implementation returns {@code false}. * once. The default implementation returns {@code false}.
* @return {@code true} if this body can be written repeatedly, * @return {@code true} if this body can be written repeatedly,
* {@code false} otherwise * {@code false} otherwise
* @since 6.1 * @since 6.1