Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Nov 16, 2023
1 parent b0e29ac commit 99378fe
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
*/
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());


@Override
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
if (aspectJPresent) {
if (aspectjPresent) {
Class<?> beanClass = registeredBean.getBeanClass();
if (AbstractAspectJAdvisorFactory.compiledByAjc(beanClass)) {
return new AspectJAdvisorContribution(beanClass);
Expand All @@ -47,6 +48,7 @@ public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registe
return null;
}


private static class AspectJAdvisorContribution implements BeanRegistrationAotContribution {

private final Class<?> beanClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@
*/
class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor {

private static final boolean aspectJPresent = ClassUtils.isPresent(
"org.aspectj.lang.annotation.Pointcut", AspectJBeanFactoryInitializationAotProcessor.class.getClassLoader());
private static final boolean aspectJPresent = ClassUtils.isPresent("org.aspectj.lang.annotation.Pointcut",
AspectJBeanFactoryInitializationAotProcessor.class.getClassLoader());


@Nullable
@Override
@Nullable
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
if (aspectJPresent) {
return AspectDelegate.processAheadOfTime(beanFactory);
}
return null;
}


/**
* Inner class to avoid a hard dependency on AspectJ at runtime.
*/
Expand All @@ -63,7 +65,6 @@ private static AspectContribution processAheadOfTime(ConfigurableListableBeanFac
List<Advisor> advisors = builder.buildAspectJAdvisors();
return (advisors.isEmpty() ? null : new AspectContribution(advisors));
}

}


Expand All @@ -84,7 +85,6 @@ public void applyTo(GenerationContext generationContext, BeanFactoryInitializati
}
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
*/
public final class CharBufferDecoder extends AbstractCharSequenceDecoder<CharBuffer> {


public CharBufferDecoder(List<String> delimiters, boolean stripDelimiter, MimeType... mimeTypes) {
super(delimiters, stripDelimiter, mimeTypes);
}


@Override
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
Expand All @@ -69,9 +69,8 @@ public static CharBufferDecoder textPlainOnly() {

/**
* Create a {@code CharBufferDecoder} for {@code "text/plain"}.
* @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting
* input strings
* @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting input strings
*/
public static CharBufferDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter) {
var textPlain = new MimeType("text", "plain", DEFAULT_CHARSET);
Expand All @@ -87,9 +86,8 @@ public static CharBufferDecoder allMimeTypes() {

/**
* Create a {@code CharBufferDecoder} that supports all MIME types.
* @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting
* input strings
* @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting input strings
*/
public static CharBufferDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter) {
var textPlain = new MimeType("text", "plain", DEFAULT_CHARSET);
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,8 +51,7 @@ public final class CharSequenceEncoder extends AbstractEncoder<CharSequence> {
*/
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;

private final ConcurrentMap<Charset, Float> charsetToMaxBytesPerChar =
new ConcurrentHashMap<>(3);
private final ConcurrentMap<Charset, Float> charsetToMaxBytesPerChar = new ConcurrentHashMap<>(3);


private CharSequenceEncoder(MimeType... mimeTypes) {
Expand Down Expand Up @@ -105,8 +104,8 @@ public DataBuffer encodeValue(CharSequence charSequence, DataBufferFactory buffe
}

int calculateCapacity(CharSequence sequence, Charset charset) {
float maxBytesPerChar = this.charsetToMaxBytesPerChar
.computeIfAbsent(charset, cs -> cs.newEncoder().maxBytesPerChar());
float maxBytesPerChar = this.charsetToMaxBytesPerChar.computeIfAbsent(charset,
cs -> cs.newEncoder().maxBytesPerChar());
float maxBytesForSequence = sequence.length() * maxBytesPerChar;
return (int) Math.ceil(maxBytesForSequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
public void subscribe(Subscriber<? super DataBuffer> subscriber) {
Objects.requireNonNull(subscriber, "Subscriber must not be null");

OutputStreamSubscription subscription = new OutputStreamSubscription(subscriber, this.outputStreamConsumer,
this.bufferFactory, this.chunkSize);
OutputStreamSubscription subscription = new OutputStreamSubscription(
subscriber, this.outputStreamConsumer, this.bufferFactory, this.chunkSize);

subscriber.onSubscribe(subscription);
this.executor.execute(subscription::invokeHandler);
Expand All @@ -80,7 +80,6 @@ private static final class OutputStreamSubscription extends OutputStream impleme

private static final Object READY = new Object();


private final Subscriber<? super DataBuffer> actual;

private final Consumer<OutputStream> outputStreamHandler;
Expand All @@ -98,7 +97,6 @@ private static final class OutputStreamSubscription extends OutputStream impleme

private long produced;


OutputStreamSubscription(Subscriber<? super DataBuffer> actual,
Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, int chunkSize) {

Expand Down Expand Up @@ -351,4 +349,5 @@ private static long addCap(long a, long b) {
return res;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import org.springframework.core.task.TaskDecorator;

/**
* {@link TaskDecorator} that {@link ContextSnapshot#wrap(Runnable) wraps the execution} of
* tasks, assisting with context propagation.
* {@link TaskDecorator} that {@link ContextSnapshot#wrap(Runnable) wraps the execution}
* of tasks, assisting with context propagation.
*
* <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
* {@link org.springframework.core.task.TaskExecutor}. This is particularly useful for
Expand All @@ -39,6 +40,7 @@ public class ContextPropagatingTaskDecorator implements TaskDecorator {

private final ContextSnapshotFactory factory;


/**
* Create a new decorator that uses a default instance of the {@link ContextSnapshotFactory}.
*/
Expand All @@ -54,6 +56,7 @@ public ContextPropagatingTaskDecorator(ContextSnapshotFactory factory) {
this.factory = factory;
}


@Override
public Runnable decorate(Runnable runnable) {
return this.factory.captureAll().wrap(runnable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ interface Body {
/**
* Indicates whether this body is capable of
* {@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,
* {@code false} otherwise
* @since 6.1
Expand Down

0 comments on commit 99378fe

Please sign in to comment.