From d36286c7d1b5ffd13d847e3b97f4da2d8df66d74 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Fri, 27 May 2016 09:51:42 +0200 Subject: [PATCH] Renamed DataBufferAllocator to DataBufferFactory --- .../springframework/core/codec/Encoder.java | 6 ++--- .../support/AbstractSingleValueEncoder.java | 10 +++---- .../core/codec/support/ByteBufferEncoder.java | 6 ++--- .../codec/support/JacksonJsonEncoder.java | 25 +++++++++-------- .../core/codec/support/Jaxb2Encoder.java | 6 ++--- .../core/codec/support/JsonObjectDecoder.java | 8 +++--- .../core/codec/support/ResourceEncoder.java | 7 ++--- .../core/codec/support/StringEncoder.java | 6 ++--- .../core/io/buffer/DataBuffer.java | 6 ++--- ...rAllocator.java => DataBufferFactory.java} | 6 ++--- .../core/io/buffer/DefaultDataBuffer.java | 27 ++++++++++--------- ...tor.java => DefaultDataBufferFactory.java} | 20 +++++++------- .../core/io/buffer/NettyDataBuffer.java | 18 ++++++------- ...cator.java => NettyDataBufferFactory.java} | 12 ++++----- .../io/buffer/support/DataBufferUtils.java | 27 ++++++++++--------- .../http/ReactiveHttpOutputMessage.java | 8 +++--- .../reactive/ReactorClientHttpRequest.java | 19 +++++++------ .../reactive/ReactorClientHttpResponse.java | 13 +++++---- .../ReactorHttpClientRequestFactory.java | 3 --- .../reactive/RxNettyClientHttpRequest.java | 22 +++++++-------- .../reactive/RxNettyClientHttpResponse.java | 13 ++++----- .../RxNettyHttpClientRequestFactory.java | 11 ++++---- .../reactive/CodecHttpMessageConverter.java | 6 ++--- .../reactive/AbstractServerHttpResponse.java | 14 +++++----- .../reactive/ReactorHttpHandlerAdapter.java | 10 +++---- .../reactive/ReactorServerHttpRequest.java | 13 ++++----- .../reactive/ReactorServerHttpResponse.java | 6 ++--- .../reactive/RxNettyHttpHandlerAdapter.java | 10 +++---- .../reactive/RxNettyServerHttpRequest.java | 13 ++++----- .../reactive/RxNettyServerHttpResponse.java | 6 ++--- .../reactive/ServletHttpHandlerAdapter.java | 24 ++++++++--------- .../reactive/ServletServerHttpResponse.java | 6 ++--- .../reactive/UndertowHttpHandlerAdapter.java | 24 ++++++++--------- .../reactive/UndertowServerHttpResponse.java | 6 ++--- .../reactive/boot/UndertowHttpServer.java | 13 ++++----- .../reactive/DefaultHttpRequestBuilder.java | 7 ++--- .../reactive/result/view/AbstractView.java | 20 +++++++------- .../result/view/ViewResolverSupport.java | 19 ++++++------- .../codec/support/ByteBufferEncoderTests.java | 2 +- .../support/JacksonJsonEncoderTests.java | 3 ++- .../core/codec/support/Jaxb2EncoderTests.java | 4 +-- .../codec/support/ResourceEncoderTests.java | 4 +-- .../codec/support/StringEncoderTests.java | 2 +- .../AbstractDataBufferAllocatingTestCase.java | 20 +++++++------- .../core/io/buffer/PooledDataBufferTests.java | 12 ++++----- .../support/DataBufferTestUtilsTests.java | 4 +-- .../buffer/support/DataBufferUtilsTests.java | 6 ++--- .../reactive/AsyncIntegrationTests.java | 11 ++++---- .../reactive/MockServerHttpResponse.java | 10 +++---- .../RandomHandlerIntegrationTests.java | 8 +++--- .../reactive/ServerHttpResponseTests.java | 6 ++--- .../reactive/DispatcherHandlerErrorTests.java | 8 +++--- .../result/WebHandlerIntegrationTests.java | 5 ++-- .../RequestMappingIntegrationTests.java | 16 +++++------ .../ViewResolutionResultHandlerTests.java | 9 +++---- 55 files changed, 303 insertions(+), 303 deletions(-) rename spring-web-reactive/src/main/java/org/springframework/core/io/buffer/{DataBufferAllocator.java => DataBufferFactory.java} (91%) rename spring-web-reactive/src/main/java/org/springframework/core/io/buffer/{DefaultDataBufferAllocator.java => DefaultDataBufferFactory.java} (78%) rename spring-web-reactive/src/main/java/org/springframework/core/io/buffer/{NettyDataBufferAllocator.java => NettyDataBufferFactory.java} (83%) diff --git a/spring-web-reactive/src/main/java/org/springframework/core/codec/Encoder.java b/spring-web-reactive/src/main/java/org/springframework/core/codec/Encoder.java index 0a53c9552bd..f7b53956598 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/codec/Encoder.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/codec/Encoder.java @@ -23,7 +23,7 @@ import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.util.MimeType; /** @@ -46,14 +46,14 @@ public interface Encoder { /** * Encode an input stream of {@code T} to an output {@link DataBuffer} stream. * @param inputStream the input stream to process. - * @param allocator a buffer allocator used to create the output + * @param dataBufferFactory a buffer factory used to create the output * @param type the stream element type to process. * @param mimeType the mime type to process. * @param hints Additional information about how to do decode, optional. * @return the output stream */ Flux encode(Publisher inputStream, - DataBufferAllocator allocator, ResolvableType type, + DataBufferFactory dataBufferFactory, ResolvableType type, MimeType mimeType, Object... hints); /** diff --git a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/AbstractSingleValueEncoder.java b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/AbstractSingleValueEncoder.java index 15c8ffcc423..82264f003a3 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/AbstractSingleValueEncoder.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/AbstractSingleValueEncoder.java @@ -21,7 +21,7 @@ import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.util.MimeType; /** @@ -37,13 +37,13 @@ public abstract class AbstractSingleValueEncoder extends AbstractEncoder { @Override public final Flux encode(Publisher inputStream, - DataBufferAllocator allocator, ResolvableType type, MimeType mimeType, + DataBufferFactory dataBufferFactory, ResolvableType type, MimeType mimeType, Object... hints) { return Flux.from(inputStream). take(1). concatMap(t -> { try { - return encode(t, allocator, type, mimeType); + return encode(t, dataBufferFactory, type, mimeType); } catch (Exception ex) { return Flux.error(ex); @@ -54,14 +54,14 @@ public abstract class AbstractSingleValueEncoder extends AbstractEncoder { /** * Encodes {@code T} to an output {@link DataBuffer} stream. * @param t the value to process - * @param allocator a buffer allocator used to create the output + * @param dataBufferFactory a buffer factory used to create the output * @param type the stream element type to process * @param mimeType the mime type to process * @param hints Additional information about how to do decode, optional * @return the output stream * @throws Exception in case of errors */ - protected abstract Flux encode(T t, DataBufferAllocator allocator, + protected abstract Flux encode(T t, DataBufferFactory dataBufferFactory, ResolvableType type, MimeType mimeType, Object... hints) throws Exception; diff --git a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/ByteBufferEncoder.java b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/ByteBufferEncoder.java index 3d006f2c99c..fe1f0a9803a 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/ByteBufferEncoder.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/ByteBufferEncoder.java @@ -23,7 +23,7 @@ import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; @@ -45,10 +45,10 @@ public class ByteBufferEncoder extends AbstractEncoder { @Override public Flux encode(Publisher inputStream, - DataBufferAllocator allocator, ResolvableType type, MimeType mimeType, + DataBufferFactory dataBufferFactory, ResolvableType type, MimeType mimeType, Object... hints) { - return Flux.from(inputStream).map(allocator::wrap); + return Flux.from(inputStream).map(dataBufferFactory::wrap); } } \ No newline at end of file diff --git a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JacksonJsonEncoder.java b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JacksonJsonEncoder.java index 81e317b1141..7c0a9924aaa 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JacksonJsonEncoder.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JacksonJsonEncoder.java @@ -29,7 +29,7 @@ import reactor.core.publisher.Mono; import org.springframework.core.ResolvableType; import org.springframework.core.codec.CodecException; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.util.Assert; import org.springframework.util.MimeType; @@ -64,21 +64,24 @@ public class JacksonJsonEncoder extends AbstractEncoder { @Override public Flux encode(Publisher inputStream, - DataBufferAllocator allocator, ResolvableType type, MimeType mimeType, + DataBufferFactory dataBufferFactory, ResolvableType type, MimeType mimeType, Object... hints) { if (inputStream instanceof Mono) { // single object - return Flux.from(inputStream).map(value -> serialize(value, allocator)); + return Flux.from(inputStream) + .map(value -> serialize(value, dataBufferFactory)); } else { // array - Mono startArray = Mono.just(allocator.wrap(START_ARRAY_BUFFER)); - Flux arraySeparators = Mono.just(allocator.wrap(SEPARATOR_BUFFER)) - .repeat(); - Mono endArray = Mono.just(allocator.wrap(END_ARRAY_BUFFER)); + Mono startArray = + Mono.just(dataBufferFactory.wrap(START_ARRAY_BUFFER)); + Flux arraySeparators = + Mono.just(dataBufferFactory.wrap(SEPARATOR_BUFFER)).repeat(); + Mono endArray = + Mono.just(dataBufferFactory.wrap(END_ARRAY_BUFFER)); - Flux serializedObjects = - Flux.from(inputStream).map(value -> serialize(value, allocator)); + Flux serializedObjects = Flux.from(inputStream) + .map(value -> serialize(value, dataBufferFactory)); Flux array = Flux.zip(serializedObjects, arraySeparators) .flatMap(tuple -> Flux.just(tuple.getT1(), tuple.getT2())); @@ -89,8 +92,8 @@ public class JacksonJsonEncoder extends AbstractEncoder { } } - private DataBuffer serialize(Object value, DataBufferAllocator allocator) { - DataBuffer buffer = allocator.allocateBuffer(); + private DataBuffer serialize(Object value, DataBufferFactory dataBufferFactory) { + DataBuffer buffer = dataBufferFactory.allocateBuffer(); OutputStream outputStream = buffer.asOutputStream(); try { this.mapper.writeValue(outputStream, value); diff --git a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/Jaxb2Encoder.java b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/Jaxb2Encoder.java index 9674c8b79b4..d2d9d2f6cb7 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/Jaxb2Encoder.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/Jaxb2Encoder.java @@ -27,7 +27,7 @@ import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.util.ClassUtils; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; @@ -61,10 +61,10 @@ public class Jaxb2Encoder extends AbstractSingleValueEncoder { } @Override - protected Flux encode(Object value, DataBufferAllocator allocator, + protected Flux encode(Object value, DataBufferFactory dataBufferFactory, ResolvableType type, MimeType mimeType, Object... hints) { try { - DataBuffer buffer = allocator.allocateBuffer(1024); + DataBuffer buffer = dataBufferFactory.allocateBuffer(1024); OutputStream outputStream = buffer.asOutputStream(); Class clazz = ClassUtils.getUserClass(value); Marshaller marshaller = jaxbContexts.createMarshaller(clazz); diff --git a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JsonObjectDecoder.java b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JsonObjectDecoder.java index 1c37fe14f34..fbcb00ab3d9 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JsonObjectDecoder.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JsonObjectDecoder.java @@ -29,7 +29,7 @@ import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.support.DataBufferUtils; import org.springframework.util.MimeType; @@ -131,7 +131,7 @@ public class JsonObjectDecoder extends AbstractDecoder { return Flux.error(new IllegalStateException("object length exceeds " + maxObjectLength + ": " + this.writerIndex + " bytes discarded")); } - DataBufferAllocator allocator = b.allocator(); + DataBufferFactory dataBufferFactory = b.factory(); for (/* use current index */; this.index < this.writerIndex; this.index++) { byte c = this.input.getByte(this.index); if (this.state == ST_DECODING_NORMAL) { @@ -143,7 +143,7 @@ public class JsonObjectDecoder extends AbstractDecoder { ByteBuf json = extractObject(this.input, this.input.readerIndex(), this.index + 1 - this.input.readerIndex()); if (json != null) { - chunks.add(allocator.wrap(json.nioBuffer())); + chunks.add(dataBufferFactory.wrap(json.nioBuffer())); } // The JSON object/array was extracted => discard the bytes from @@ -177,7 +177,7 @@ public class JsonObjectDecoder extends AbstractDecoder { idxNoSpaces + 1 - this.input.readerIndex()); if (json != null) { - chunks.add(allocator.wrap(json.nioBuffer())); + chunks.add(dataBufferFactory.wrap(json.nioBuffer())); } this.input.readerIndex(this.index + 1); diff --git a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/ResourceEncoder.java b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/ResourceEncoder.java index 497b79efd83..742c8de634a 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/ResourceEncoder.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/ResourceEncoder.java @@ -24,7 +24,7 @@ import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; import org.springframework.core.io.Resource; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.support.DataBufferUtils; import org.springframework.util.Assert; import org.springframework.util.MimeType; @@ -59,10 +59,11 @@ public class ResourceEncoder extends AbstractSingleValueEncoder { } @Override - protected Flux encode(Resource resource, DataBufferAllocator allocator, + protected Flux encode(Resource resource, + DataBufferFactory dataBufferFactory, ResolvableType type, MimeType mimeType, Object... hints) throws IOException { InputStream is = resource.getInputStream(); - return DataBufferUtils.read(is, allocator, bufferSize); + return DataBufferUtils.read(is, dataBufferFactory, bufferSize); } } diff --git a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/StringEncoder.java b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/StringEncoder.java index 14914e4b158..21c09cfc827 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/StringEncoder.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/StringEncoder.java @@ -24,7 +24,7 @@ import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.util.MimeType; /** @@ -50,7 +50,7 @@ public class StringEncoder extends AbstractEncoder { @Override public Flux encode(Publisher inputStream, - DataBufferAllocator allocator, ResolvableType type, MimeType mimeType, + DataBufferFactory dataBufferFactory, ResolvableType type, MimeType mimeType, Object... hints) { Charset charset; if (mimeType != null && mimeType.getCharSet() != null) { @@ -61,7 +61,7 @@ public class StringEncoder extends AbstractEncoder { } return Flux.from(inputStream).map(s -> { byte[] bytes = s.getBytes(charset); - DataBuffer dataBuffer = allocator.allocateBuffer(bytes.length); + DataBuffer dataBuffer = dataBufferFactory.allocateBuffer(bytes.length); dataBuffer.write(bytes); return dataBuffer; }); diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBuffer.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBuffer.java index 31cf7f63ace..8fd84476ffb 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBuffer.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBuffer.java @@ -29,10 +29,10 @@ import java.util.function.IntPredicate; public interface DataBuffer { /** - * Returns the {@link DataBufferAllocator} that created this buffer. - * @return the creating buffer allocator + * Returns the {@link DataBufferFactory} that created this buffer. + * @return the creating buffer factory */ - DataBufferAllocator allocator(); + DataBufferFactory factory(); /** * Returns the index of the first byte in this buffer that matches the given diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferAllocator.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferFactory.java similarity index 91% rename from spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferAllocator.java rename to spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferFactory.java index 881de92684a..9fba5de665b 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferAllocator.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferFactory.java @@ -19,13 +19,13 @@ package org.springframework.core.io.buffer; import java.nio.ByteBuffer; /** - * A factory for {@link DataBuffer}s, allowing for allocation of heap-based and direct - * data buffers. + * A factory for {@link DataBuffer}s, allowing for allocation and wrapping of data + * buffers. * * @author Arjen Poutsma * @see DataBuffer */ -public interface DataBufferAllocator { +public interface DataBufferFactory { /** * Allocates a data buffer of a default initial capacity. Depending on the underlying diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java index 940c0d1a8b8..b46a03ce908 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java @@ -30,14 +30,14 @@ import org.springframework.util.ObjectUtils; /** * Default implementation of the {@link DataBuffer} interface that uses a {@link * ByteBuffer} internally, with separate read and write positions. Constructed - * using the {@link DefaultDataBufferAllocator}. + * using the {@link DefaultDataBufferFactory}. * * @author Arjen Poutsma - * @see DefaultDataBufferAllocator + * @see DefaultDataBufferFactory */ public class DefaultDataBuffer implements DataBuffer { - private final DefaultDataBufferAllocator allocator; + private final DefaultDataBufferFactory dataBufferFactory; private ByteBuffer byteBuffer; @@ -51,27 +51,28 @@ public class DefaultDataBuffer implements DataBuffer { * ByteBuffer#position() position} of the given buffer. * @param byteBuffer the buffer to base this buffer on */ - DefaultDataBuffer(ByteBuffer byteBuffer, DefaultDataBufferAllocator allocator) { - this(byteBuffer, byteBuffer.position(), byteBuffer.position(), allocator); + DefaultDataBuffer(ByteBuffer byteBuffer, DefaultDataBufferFactory dataBufferFactory) { + this(byteBuffer, byteBuffer.position(), byteBuffer.position(), dataBufferFactory); } - DefaultDataBuffer(ByteBuffer byteBuffer, int readPosition, int writePosition, DefaultDataBufferAllocator allocator) { + DefaultDataBuffer(ByteBuffer byteBuffer, int readPosition, int writePosition, + DefaultDataBufferFactory dataBufferFactory) { Assert.notNull(byteBuffer, "'byteBuffer' must not be null"); Assert.isTrue(readPosition >= 0, "'readPosition' must be 0 or higher"); Assert.isTrue(writePosition >= 0, "'writePosition' must be 0 or higher"); Assert.isTrue(readPosition <= writePosition, "'readPosition' must be smaller than or equal to 'writePosition'"); - Assert.notNull(allocator, "'allocator' must not be null"); + Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); this.byteBuffer = byteBuffer; this.readPosition = readPosition; this.writePosition = writePosition; - this.allocator = allocator; + this.dataBufferFactory = dataBufferFactory; } @Override - public DefaultDataBufferAllocator allocator() { - return this.allocator; + public DefaultDataBufferFactory factory() { + return this.dataBufferFactory; } /** @@ -219,7 +220,7 @@ public class DefaultDataBuffer implements DataBuffer { this.byteBuffer.position(index); ByteBuffer slice = this.byteBuffer.slice(); slice.limit(length); - return new SlicedDefaultDataBuffer(slice, 0, length, this.allocator); + return new SlicedDefaultDataBuffer(slice, 0, length, this.dataBufferFactory); } finally { this.byteBuffer.position(oldPosition); @@ -337,8 +338,8 @@ public class DefaultDataBuffer implements DataBuffer { private static class SlicedDefaultDataBuffer extends DefaultDataBuffer { SlicedDefaultDataBuffer(ByteBuffer byteBuffer, int readPosition, - int writePosition, DefaultDataBufferAllocator allocator) { - super(byteBuffer, readPosition, writePosition, allocator); + int writePosition, DefaultDataBufferFactory dataBufferFactory) { + super(byteBuffer, readPosition, writePosition, dataBufferFactory); } @Override diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferAllocator.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferFactory.java similarity index 78% rename from spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferAllocator.java rename to spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferFactory.java index 0d3c6661b15..7b1dd007b8d 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferAllocator.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferFactory.java @@ -21,18 +21,18 @@ import java.nio.ByteBuffer; import org.springframework.util.Assert; /** - * Default implementation of the {@code DataBufferAllocator} interface. Allows for + * Default implementation of the {@code DataBufferFactory} interface. Allows for * specification of the default initial capacity at construction time, as well as whether * heap-based or direct buffers are to be preferred. * * @author Arjen Poutsma */ -public class DefaultDataBufferAllocator implements DataBufferAllocator { +public class DefaultDataBufferFactory implements DataBufferFactory { /** * The default capacity when none is specified. - * @see #DefaultDataBufferAllocator() - * @see #DefaultDataBufferAllocator(boolean) + * @see #DefaultDataBufferFactory() + * @see #DefaultDataBufferFactory(boolean) */ public static final int DEFAULT_INITIAL_CAPACITY = 256; @@ -42,30 +42,30 @@ public class DefaultDataBufferAllocator implements DataBufferAllocator { private final int defaultInitialCapacity; /** - * Creates a new {@code DefaultDataBufferAllocator} with default settings. + * Creates a new {@code DefaultDataBufferFactory} with default settings. */ - public DefaultDataBufferAllocator() { + public DefaultDataBufferFactory() { this(false); } /** - * Creates a new {@code DefaultDataBufferAllocator}, indicating whether direct buffers + * Creates a new {@code DefaultDataBufferFactory}, indicating whether direct buffers * should be created by {@link #allocateBuffer()} and {@link #allocateBuffer(int)}. * @param preferDirect {@code true} if direct buffers are to be preferred; {@code * false} otherwise */ - public DefaultDataBufferAllocator(boolean preferDirect) { + public DefaultDataBufferFactory(boolean preferDirect) { this(preferDirect, DEFAULT_INITIAL_CAPACITY); } /** - * Creates a new {@code DefaultDataBufferAllocator}, indicating whether direct buffers + * Creates a new {@code DefaultDataBufferFactory}, indicating whether direct buffers * should be created by {@link #allocateBuffer()} and {@link #allocateBuffer(int)}, * and what the capacity is to be used for {@link #allocateBuffer()}. * @param preferDirect {@code true} if direct buffers are to be preferred; {@code * false} otherwise */ - public DefaultDataBufferAllocator(boolean preferDirect, int defaultInitialCapacity) { + public DefaultDataBufferFactory(boolean preferDirect, int defaultInitialCapacity) { Assert.isTrue(defaultInitialCapacity > 0, "'defaultInitialCapacity' should be larger than 0"); this.preferDirect = preferDirect; diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java index c5aa526c04f..4686490fd1b 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java @@ -33,13 +33,13 @@ import org.springframework.util.ObjectUtils; /** * Implementation of the {@code DataBuffer} interface that wraps a Netty {@link ByteBuf}. - * Typically constructed using the {@link NettyDataBufferAllocator}. + * Typically constructed using the {@link NettyDataBufferFactory}. * * @author Arjen Poutsma */ public class NettyDataBuffer implements PooledDataBuffer { - private final NettyDataBufferAllocator allocator; + private final NettyDataBufferFactory dataBufferFactory; private ByteBuf byteBuf; @@ -47,17 +47,17 @@ public class NettyDataBuffer implements PooledDataBuffer { * Creates a new {@code NettyDataBuffer} based on the given {@code ByteBuff}. * @param byteBuf the buffer to base this buffer on */ - NettyDataBuffer(ByteBuf byteBuf, NettyDataBufferAllocator allocator) { + NettyDataBuffer(ByteBuf byteBuf, NettyDataBufferFactory dataBufferFactory) { Assert.notNull(byteBuf, "'byteBuf' must not be null"); - Assert.notNull(allocator, "'allocator' must not be null"); + Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); this.byteBuf = byteBuf; - this.allocator = allocator; + this.dataBufferFactory = dataBufferFactory; } @Override - public NettyDataBufferAllocator allocator() { - return allocator; + public NettyDataBufferFactory factory() { + return this.dataBufferFactory; } /** @@ -177,7 +177,7 @@ public class NettyDataBuffer implements PooledDataBuffer { @Override public DataBuffer slice(int index, int length) { ByteBuf slice = this.byteBuf.slice(index, length); - return new NettyDataBuffer(slice, this.allocator); + return new NettyDataBuffer(slice, this.dataBufferFactory); } @Override @@ -197,7 +197,7 @@ public class NettyDataBuffer implements PooledDataBuffer { @Override public PooledDataBuffer retain() { - return new NettyDataBuffer(this.byteBuf.retain(), allocator); + return new NettyDataBuffer(this.byteBuf.retain(), dataBufferFactory); } @Override diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferAllocator.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferFactory.java similarity index 83% rename from spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferAllocator.java rename to spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferFactory.java index 12f8dae0ab0..440c2c0f4b6 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferAllocator.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferFactory.java @@ -25,24 +25,24 @@ import io.netty.buffer.Unpooled; import org.springframework.util.Assert; /** - * Implementation of the {@code DataBufferAllocator} interface based on a Netty + * Implementation of the {@code DataBufferFactory} interface based on a Netty * {@link ByteBufAllocator}. * * @author Arjen Poutsma * @see io.netty.buffer.PooledByteBufAllocator * @see io.netty.buffer.UnpooledByteBufAllocator */ -public class NettyDataBufferAllocator implements DataBufferAllocator { +public class NettyDataBufferFactory implements DataBufferFactory { private final ByteBufAllocator byteBufAllocator; /** - * Creates a new {@code NettyDataBufferAllocator} based on the given allocator. - * @param byteBufAllocator the allocator to use + * Creates a new {@code NettyDataBufferFactory} based on the given factory. + * @param byteBufAllocator the factory to use * @see io.netty.buffer.PooledByteBufAllocator * @see io.netty.buffer.UnpooledByteBufAllocator */ - public NettyDataBufferAllocator(ByteBufAllocator byteBufAllocator) { + public NettyDataBufferFactory(ByteBufAllocator byteBufAllocator) { Assert.notNull(byteBufAllocator, "'byteBufAllocator' must not be null"); this.byteBufAllocator = byteBufAllocator; @@ -77,6 +77,6 @@ public class NettyDataBufferAllocator implements DataBufferAllocator { @Override public String toString() { - return "NettyDataBufferAllocator (" + this.byteBufAllocator + ")"; + return "NettyDataBufferFactory (" + this.byteBufAllocator + ")"; } } diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/support/DataBufferUtils.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/support/DataBufferUtils.java index 5c264a6dad5..09270ff7db7 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/support/DataBufferUtils.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/support/DataBufferUtils.java @@ -34,7 +34,7 @@ import reactor.core.publisher.Flux; import reactor.core.subscriber.SignalEmitter; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.PooledDataBuffer; import org.springframework.util.Assert; @@ -59,34 +59,34 @@ public abstract class DataBufferUtils { * Reads the given {@code InputStream} into a {@code Flux} of * {@code DataBuffer}s. Closes the stream when the flux inputStream terminated. * @param inputStream the input stream to read from - * @param allocator the allocator to create data buffers with + * @param dataBufferFactory the factory to create data buffers with * @param bufferSize the maximum size of the data buffers * @return a flux of data buffers read from the given channel */ public static Flux read(InputStream inputStream, - DataBufferAllocator allocator, int bufferSize) { + DataBufferFactory dataBufferFactory, int bufferSize) { Assert.notNull(inputStream, "'inputStream' must not be null"); - Assert.notNull(allocator, "'allocator' must not be null"); + Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); ReadableByteChannel channel = Channels.newChannel(inputStream); - return read(channel, allocator, bufferSize); + return read(channel, dataBufferFactory, bufferSize); } /** * Reads the given {@code ReadableByteChannel} into a {@code Flux} of * {@code DataBuffer}s. Closes the channel when the flux is terminated. * @param channel the channel to read from - * @param allocator the allocator to create data buffers with + * @param dataBufferFactory the factory to create data buffers with * @param bufferSize the maximum size of the data buffers * @return a flux of data buffers read from the given channel */ public static Flux read(ReadableByteChannel channel, - DataBufferAllocator allocator, int bufferSize) { + DataBufferFactory dataBufferFactory, int bufferSize) { Assert.notNull(channel, "'channel' must not be null"); - Assert.notNull(allocator, "'allocator' must not be null"); + Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); return Flux.generate(() -> channel, - new ReadableByteChannelGenerator(allocator, bufferSize), + new ReadableByteChannelGenerator(dataBufferFactory, bufferSize), CLOSE_CONSUMER); } @@ -194,12 +194,13 @@ public abstract class DataBufferUtils { implements BiFunction, ReadableByteChannel> { - private final DataBufferAllocator allocator; + private final DataBufferFactory dataBufferFactory; private final int chunkSize; - public ReadableByteChannelGenerator(DataBufferAllocator allocator, int chunkSize) { - this.allocator = allocator; + public ReadableByteChannelGenerator(DataBufferFactory dataBufferFactory, + int chunkSize) { + this.dataBufferFactory = dataBufferFactory; this.chunkSize = chunkSize; } @@ -212,7 +213,7 @@ public abstract class DataBufferUtils { if ((read = channel.read(byteBuffer)) > 0) { byteBuffer.flip(); boolean release = true; - DataBuffer dataBuffer = this.allocator.allocateBuffer(read); + DataBuffer dataBuffer = this.dataBufferFactory.allocateBuffer(read); try { dataBuffer.write(byteBuffer); release = false; diff --git a/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java b/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java index 0eaa89515db..4e84c918869 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/ReactiveHttpOutputMessage.java @@ -22,7 +22,7 @@ import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; /** * A "reactive" HTTP output message that accepts output as a {@link Publisher}. @@ -50,10 +50,10 @@ public interface ReactiveHttpOutputMessage extends HttpMessage { Mono setBody(Publisher body); /** - * Returns a {@link DataBufferAllocator} that can be used for creating the body. - * @return a buffer allocator + * Returns a {@link DataBufferFactory} that can be used for creating the body. + * @return a buffer factory * @see #setBody(Publisher) */ - DataBufferAllocator allocator(); + DataBufferFactory dataBufferFactory(); } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java index 07ce7068cad..d97c495d751 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java @@ -28,10 +28,9 @@ import reactor.core.publisher.Mono; import reactor.io.netty.http.HttpClient; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.core.io.buffer.NettyDataBuffer; -import org.springframework.core.io.buffer.NettyDataBufferAllocator; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -43,7 +42,7 @@ import org.springframework.http.HttpMethod; */ public class ReactorClientHttpRequest extends AbstractClientHttpRequest { - private final DataBufferAllocator allocator; + private final DataBufferFactory dataBufferFactory; private final HttpMethod httpMethod; @@ -56,16 +55,16 @@ public class ReactorClientHttpRequest extends AbstractClientHttpRequest { public ReactorClientHttpRequest(HttpMethod httpMethod, URI uri, HttpClient httpClient, HttpHeaders headers) { super(headers); - //FIXME use Netty allocator - this.allocator = new DefaultDataBufferAllocator(); + //FIXME use Netty factory + this.dataBufferFactory = new DefaultDataBufferFactory(); this.httpMethod = httpMethod; this.uri = uri; this.httpClient = httpClient; } @Override - public DataBufferAllocator allocator() { - return this.allocator; + public DataBufferFactory dataBufferFactory() { + return this.dataBufferFactory; } @Override @@ -121,8 +120,8 @@ public class ReactorClientHttpRequest extends AbstractClientHttpRequest { return channel.sendHeaders(); } }); - }) - .map(httpChannel -> new ReactorClientHttpResponse(httpChannel, allocator)); + }).map(httpChannel -> new ReactorClientHttpResponse(httpChannel, + dataBufferFactory)); } private ByteBuf toByteBuf(DataBuffer buffer) { diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java index 8e687132b76..0a6e4f6d735 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java @@ -22,8 +22,7 @@ import reactor.core.publisher.Flux; import reactor.io.netty.http.HttpInbound; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.NettyDataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; @@ -39,19 +38,19 @@ import org.springframework.util.MultiValueMap; */ public class ReactorClientHttpResponse implements ClientHttpResponse { - private final DataBufferAllocator allocator; + private final DataBufferFactory dataBufferFactory; private final HttpInbound channel; - - public ReactorClientHttpResponse(HttpInbound channel, DataBufferAllocator allocator) { - this.allocator = allocator; + public ReactorClientHttpResponse(HttpInbound channel, + DataBufferFactory dataBufferFactory) { + this.dataBufferFactory = dataBufferFactory; this.channel = channel; } @Override public Flux getBody() { - return channel.receiveByteBuffer().map(allocator::wrap); + return channel.receiveByteBuffer().map(dataBufferFactory::wrap); } @Override diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorHttpClientRequestFactory.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorHttpClientRequestFactory.java index ad1a9aad423..70becdd9993 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorHttpClientRequestFactory.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/ReactorHttpClientRequestFactory.java @@ -20,9 +20,6 @@ import java.net.URI; import reactor.io.netty.http.HttpClient; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; -import org.springframework.core.io.buffer.NettyDataBufferAllocator; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.util.Assert; diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpRequest.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpRequest.java index cf42da74bfc..46d9550c317 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpRequest.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpRequest.java @@ -31,8 +31,8 @@ import reactor.core.publisher.Mono; import rx.Observable; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.NettyDataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -44,7 +44,7 @@ import org.springframework.http.HttpMethod; */ public class RxNettyClientHttpRequest extends AbstractClientHttpRequest { - private final NettyDataBufferAllocator allocator; + private final NettyDataBufferFactory dataBufferFactory; private final HttpMethod httpMethod; @@ -52,17 +52,17 @@ public class RxNettyClientHttpRequest extends AbstractClientHttpRequest { private Observable body; - - public RxNettyClientHttpRequest(HttpMethod httpMethod, URI uri, HttpHeaders headers, NettyDataBufferAllocator allocator) { + public RxNettyClientHttpRequest(HttpMethod httpMethod, URI uri, HttpHeaders headers, + NettyDataBufferFactory dataBufferFactory) { super(headers); this.httpMethod = httpMethod; this.uri = uri; - this.allocator = allocator; + this.dataBufferFactory = dataBufferFactory; } @Override - public DataBufferAllocator allocator() { - return this.allocator; + public DataBufferFactory dataBufferFactory() { + return this.dataBufferFactory; } /** @@ -80,7 +80,7 @@ public class RxNettyClientHttpRequest extends AbstractClientHttpRequest { public Mono setBody(Publisher body) { this.body = RxJava1ObservableConverter.from(Flux.from(body) - .map(b -> allocator.wrap(b.asByteBuffer()).getNativeBuffer())); + .map(b -> dataBufferFactory.wrap(b.asByteBuffer()).getNativeBuffer())); return Mono.empty(); } @@ -126,8 +126,8 @@ public class RxNettyClientHttpRequest extends AbstractClientHttpRequest { } }) .flatMap(resp -> resp) - .next() - .map(response -> new RxNettyClientHttpResponse(response, this.allocator)); + .next().map(response -> new RxNettyClientHttpResponse(response, + this.dataBufferFactory)); } catch (IllegalArgumentException exc) { return Mono.error(exc); diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpResponse.java index 9077bdc0f58..4495d134f59 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyClientHttpResponse.java @@ -24,7 +24,7 @@ import reactor.core.converter.RxJava1ObservableConverter; import reactor.core.publisher.Flux; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.NettyDataBufferAllocator; +import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; @@ -46,14 +46,14 @@ public class RxNettyClientHttpResponse implements ClientHttpResponse { private final MultiValueMap cookies; - private final NettyDataBufferAllocator allocator; + private final NettyDataBufferFactory dataBufferFactory; public RxNettyClientHttpResponse(HttpClientResponse response, - NettyDataBufferAllocator allocator) { + NettyDataBufferFactory dataBufferFactory) { Assert.notNull("'request', request must not be null"); - Assert.notNull(allocator, "'allocator' must not be null"); - this.allocator = allocator; + Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); + this.dataBufferFactory = dataBufferFactory; this.response = response; this.headers = new HttpHeaders(); this.response.headerIterator().forEachRemaining(e -> this.headers.set(e.getKey().toString(), e.getValue().toString())); @@ -84,7 +84,8 @@ public class RxNettyClientHttpResponse implements ClientHttpResponse { @Override public Flux getBody() { - return RxJava1ObservableConverter.from(this.response.getContent().map(allocator::wrap)); + return RxJava1ObservableConverter + .from(this.response.getContent().map(dataBufferFactory::wrap)); } @Override diff --git a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyHttpClientRequestFactory.java b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyHttpClientRequestFactory.java index f96e97a0c2f..0b935af8128 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyHttpClientRequestFactory.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/client/reactive/RxNettyHttpClientRequestFactory.java @@ -18,7 +18,7 @@ package org.springframework.http.client.reactive; import java.net.URI; -import org.springframework.core.io.buffer.NettyDataBufferAllocator; +import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.util.Assert; @@ -30,10 +30,10 @@ import org.springframework.util.Assert; */ public class RxNettyHttpClientRequestFactory implements ClientHttpRequestFactory { - private final NettyDataBufferAllocator allocator; + private final NettyDataBufferFactory dataBufferFactory; - public RxNettyHttpClientRequestFactory(NettyDataBufferAllocator allocator) { - this.allocator = allocator; + public RxNettyHttpClientRequestFactory(NettyDataBufferFactory dataBufferFactory) { + this.dataBufferFactory = dataBufferFactory; } @Override @@ -42,6 +42,7 @@ public class RxNettyHttpClientRequestFactory implements ClientHttpRequestFactory Assert.notNull(uri, "request URI is required"); Assert.notNull(headers, "request headers are required"); - return new RxNettyClientHttpRequest(httpMethod, uri, headers, this.allocator); + return new RxNettyClientHttpRequest(httpMethod, uri, headers, + this.dataBufferFactory); } } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/converter/reactive/CodecHttpMessageConverter.java b/spring-web-reactive/src/main/java/org/springframework/http/converter/reactive/CodecHttpMessageConverter.java index 4444a42619f..3544bf05315 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/converter/reactive/CodecHttpMessageConverter.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/converter/reactive/CodecHttpMessageConverter.java @@ -28,7 +28,7 @@ import org.springframework.core.ResolvableType; import org.springframework.core.codec.Decoder; import org.springframework.core.codec.Encoder; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpInputMessage; @@ -128,9 +128,9 @@ public class CodecHttpMessageConverter implements HttpMessageConverter { if (headers.getContentType() == null) { headers.setContentType(contentType); } - DataBufferAllocator allocator = outputMessage.allocator(); + DataBufferFactory dataBufferFactory = outputMessage.dataBufferFactory(); Flux body = - this.encoder.encode(inputStream, allocator, type, contentType); + this.encoder.encode(inputStream, dataBufferFactory, type, contentType); return outputMessage.setBody(body); } } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java index 57d03643c01..5700146307c 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java @@ -25,7 +25,7 @@ import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseCookie; import org.springframework.util.Assert; @@ -55,19 +55,19 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse { private final List>> beforeCommitActions = new ArrayList<>(4); - private final DataBufferAllocator allocator; + private final DataBufferFactory dataBufferFactory; - public AbstractServerHttpResponse(DataBufferAllocator allocator) { - Assert.notNull(allocator, "'allocator' must not be null"); + public AbstractServerHttpResponse(DataBufferFactory dataBufferFactory) { + Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); - this.allocator = allocator; + this.dataBufferFactory = dataBufferFactory; this.headers = new HttpHeaders(); this.cookies = new LinkedMultiValueMap(); } @Override - public final DataBufferAllocator allocator() { - return this.allocator; + public final DataBufferFactory dataBufferFactory() { + return this.dataBufferFactory; } @Override diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java index 24358893b40..a582963d4bf 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java @@ -21,7 +21,7 @@ import reactor.core.publisher.Mono; import reactor.io.ipc.ChannelHandler; import reactor.io.netty.http.HttpChannel; -import org.springframework.core.io.buffer.NettyDataBufferAllocator; +import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.util.Assert; /** @@ -39,13 +39,13 @@ public class ReactorHttpHandlerAdapter @Override public Mono apply(HttpChannel channel) { - NettyDataBufferAllocator allocator = - new NettyDataBufferAllocator(channel.delegate().alloc()); + NettyDataBufferFactory dataBufferFactory = + new NettyDataBufferFactory(channel.delegate().alloc()); ReactorServerHttpRequest adaptedRequest = - new ReactorServerHttpRequest(channel, allocator); + new ReactorServerHttpRequest(channel, dataBufferFactory); ReactorServerHttpResponse adaptedResponse = - new ReactorServerHttpResponse(channel, allocator); + new ReactorServerHttpResponse(channel, dataBufferFactory); return this.httpHandler.handle(adaptedRequest, adaptedResponse); } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java index da38767324c..bdd587c0ca4 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.http.server.reactive; import java.net.URI; @@ -23,7 +24,7 @@ import reactor.core.publisher.Flux; import reactor.io.netty.http.HttpChannel; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.NettyDataBufferAllocator; +import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -40,14 +41,14 @@ public class ReactorServerHttpRequest extends AbstractServerHttpRequest { private final HttpChannel channel; - private final NettyDataBufferAllocator allocator; + private final NettyDataBufferFactory dataBufferFactory; public ReactorServerHttpRequest(HttpChannel request, - NettyDataBufferAllocator allocator) { + NettyDataBufferFactory dataBufferFactory) { Assert.notNull("'request' must not be null"); - Assert.notNull(allocator, "'allocator' must not be null"); + Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); this.channel = request; - this.allocator = allocator; + this.dataBufferFactory = dataBufferFactory; } @@ -90,7 +91,7 @@ public class ReactorServerHttpRequest extends AbstractServerHttpRequest { public Flux getBody() { return this.channel.receive() .retain() //FIXME Rogue reference holding - .map(allocator::wrap); + .map(dataBufferFactory::wrap); } } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java index 361e4e96300..a132f635aaa 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java @@ -29,7 +29,7 @@ import reactor.core.publisher.Mono; import reactor.io.netty.http.HttpChannel; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.NettyDataBuffer; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; @@ -48,8 +48,8 @@ public class ReactorServerHttpResponse extends AbstractServerHttpResponse private final HttpChannel channel; public ReactorServerHttpResponse(HttpChannel response, - DataBufferAllocator allocator) { - super(allocator); + DataBufferFactory dataBufferFactory) { + super(dataBufferFactory); Assert.notNull("'response' must not be null."); this.channel = response; } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java index a3ec1909b14..6d0b8cb720c 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java @@ -24,7 +24,7 @@ import org.reactivestreams.Publisher; import reactor.core.converter.RxJava1ObservableConverter; import rx.Observable; -import org.springframework.core.io.buffer.NettyDataBufferAllocator; +import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.util.Assert; /** @@ -41,13 +41,13 @@ public class RxNettyHttpHandlerAdapter implements RequestHandler handle(HttpServerRequest request, HttpServerResponse response) { - NettyDataBufferAllocator allocator = - new NettyDataBufferAllocator(response.unsafeNettyChannel().alloc()); + NettyDataBufferFactory dataBufferFactory = + new NettyDataBufferFactory(response.unsafeNettyChannel().alloc()); RxNettyServerHttpRequest adaptedRequest = - new RxNettyServerHttpRequest(request, allocator); + new RxNettyServerHttpRequest(request, dataBufferFactory); RxNettyServerHttpResponse adaptedResponse = - new RxNettyServerHttpResponse(response, allocator); + new RxNettyServerHttpResponse(response, dataBufferFactory); Publisher result = this.httpHandler.handle(adaptedRequest, adaptedResponse); return RxJava1ObservableConverter.from(result); } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpRequest.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpRequest.java index dab7c23f837..cd07391adee 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpRequest.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpRequest.java @@ -27,7 +27,7 @@ import reactor.core.publisher.Flux; import rx.Observable; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.NettyDataBufferAllocator; +import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -45,13 +45,13 @@ public class RxNettyServerHttpRequest extends AbstractServerHttpRequest { private final HttpServerRequest request; - private final NettyDataBufferAllocator allocator; + private final NettyDataBufferFactory dataBufferFactory; public RxNettyServerHttpRequest(HttpServerRequest request, - NettyDataBufferAllocator allocator) { + NettyDataBufferFactory dataBufferFactory) { Assert.notNull("'request', request must not be null"); - Assert.notNull(allocator, "'allocator' must not be null"); - this.allocator = allocator; + Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); + this.dataBufferFactory = dataBufferFactory; this.request = request; } @@ -93,7 +93,8 @@ public class RxNettyServerHttpRequest extends AbstractServerHttpRequest { @Override public Flux getBody() { - Observable content = this.request.getContent().map(allocator::wrap); + Observable content = + this.request.getContent().map(dataBufferFactory::wrap); content = content.concatWith(Observable.empty()); // See GH issue #58 return RxJava1ObservableConverter.from(content); } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java index 7fa7aac5bbe..bb6f571526c 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java @@ -29,7 +29,7 @@ import rx.Observable; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.NettyDataBuffer; -import org.springframework.core.io.buffer.NettyDataBufferAllocator; +import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; import org.springframework.util.Assert; @@ -45,8 +45,8 @@ public class RxNettyServerHttpResponse extends AbstractServerHttpResponse { private final HttpServerResponse response; public RxNettyServerHttpResponse(HttpServerResponse response, - NettyDataBufferAllocator allocator) { - super(allocator); + NettyDataBufferFactory dataBufferFactory) { + super(dataBufferFactory); Assert.notNull("'response', response must not be null."); this.response = response; diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java index f65ec1a16a6..0c463bbda26 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java @@ -37,8 +37,8 @@ import reactor.core.publisher.Mono; import reactor.core.util.BackpressureUtils; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.core.io.buffer.support.DataBufferUtils; import org.springframework.http.HttpStatus; import org.springframework.util.Assert; @@ -59,7 +59,7 @@ public class ServletHttpHandlerAdapter extends HttpServlet { // Servlet is based on blocking I/O, hence the usage of non-direct, heap-based buffers // (i.e. 'false' as constructor argument) - private DataBufferAllocator allocator = new DefaultDataBufferAllocator(false); + private DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(false); private int bufferSize = DEFAULT_BUFFER_SIZE; @@ -69,9 +69,9 @@ public class ServletHttpHandlerAdapter extends HttpServlet { this.handler = handler; } - public void setAllocator(DataBufferAllocator allocator) { - Assert.notNull(allocator, "'allocator' must not be null"); - this.allocator = allocator; + public void setDataBufferFactory(DataBufferFactory dataBufferFactory) { + Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); + this.dataBufferFactory = dataBufferFactory; } public void setBufferSize(int bufferSize) { @@ -87,7 +87,7 @@ public class ServletHttpHandlerAdapter extends HttpServlet { ServletAsyncContextSynchronizer synchronizer = new ServletAsyncContextSynchronizer(context); RequestBodyPublisher requestBody = - new RequestBodyPublisher(synchronizer, allocator, bufferSize); + new RequestBodyPublisher(synchronizer, dataBufferFactory, bufferSize); requestBody.registerListener(); ServletServerHttpRequest request = new ServletServerHttpRequest(servletRequest, requestBody); @@ -96,7 +96,7 @@ public class ServletHttpHandlerAdapter extends HttpServlet { new ResponseBodySubscriber(synchronizer, bufferSize); responseBody.registerListener(); ServletServerHttpResponse response = - new ServletServerHttpResponse(servletResponse, allocator, + new ServletServerHttpResponse(servletResponse, dataBufferFactory, publisher -> Mono .from(subscriber -> publisher.subscribe(responseBody))); @@ -149,14 +149,14 @@ public class ServletHttpHandlerAdapter extends HttpServlet { private final ServletAsyncContextSynchronizer synchronizer; - private final DataBufferAllocator allocator; + private final DataBufferFactory dataBufferFactory; private final byte[] buffer; public RequestBodyPublisher(ServletAsyncContextSynchronizer synchronizer, - DataBufferAllocator allocator, int bufferSize) { + DataBufferFactory dataBufferFactory, int bufferSize) { this.synchronizer = synchronizer; - this.allocator = allocator; + this.dataBufferFactory = dataBufferFactory; this.buffer = new byte[bufferSize]; } @@ -204,7 +204,7 @@ public class ServletHttpHandlerAdapter extends HttpServlet { break; } else if (read > 0) { - DataBuffer dataBuffer = allocator.allocateBuffer(read); + DataBuffer dataBuffer = dataBufferFactory.allocateBuffer(read); dataBuffer.write(buffer, 0, read); publishOnNext(dataBuffer); diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java index 17e69de7353..59e3ea26d50 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java @@ -29,7 +29,7 @@ import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseCookie; @@ -49,9 +49,9 @@ public class ServletServerHttpResponse extends AbstractServerHttpResponse { private final Function, Mono> responseBodyWriter; public ServletServerHttpResponse(HttpServletResponse response, - DataBufferAllocator allocator, + DataBufferFactory dataBufferFactory, Function, Mono> responseBodyWriter) { - super(allocator); + super(dataBufferFactory); Assert.notNull(response, "'response' must not be null"); Assert.notNull(responseBodyWriter, "'responseBodyWriter' must not be null"); this.response = response; diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java index 05cf650a5e6..f0ed1d5a99e 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java @@ -34,7 +34,7 @@ import reactor.core.publisher.Mono; import reactor.core.util.BackpressureUtils; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.util.Assert; /** @@ -48,22 +48,22 @@ public class UndertowHttpHandlerAdapter implements io.undertow.server.HttpHandle private final HttpHandler delegate; - // TODO: use UndertowDBA when introduced - private final DataBufferAllocator allocator; + private final DataBufferFactory dataBufferFactory; public UndertowHttpHandlerAdapter(HttpHandler delegate, - DataBufferAllocator allocator) { + DataBufferFactory dataBufferFactory) { Assert.notNull(delegate, "'delegate' is required"); - Assert.notNull(allocator, "'allocator' must not be null"); + Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); this.delegate = delegate; - this.allocator = allocator; + this.dataBufferFactory = dataBufferFactory; } @Override public void handleRequest(HttpServerExchange exchange) throws Exception { - RequestBodyPublisher requestBody = new RequestBodyPublisher(exchange, allocator); + RequestBodyPublisher requestBody = + new RequestBodyPublisher(exchange, dataBufferFactory); requestBody.registerListener(); ServerHttpRequest request = new UndertowServerHttpRequest(exchange, requestBody); @@ -74,7 +74,7 @@ public class UndertowHttpHandlerAdapter implements io.undertow.server.HttpHandle ServerHttpResponse response = new UndertowServerHttpResponse(exchange, responseChannel, publisher -> Mono.from(subscriber -> publisher.subscribe(responseBody)), - allocator); + dataBufferFactory); this.delegate.handle(request, response).subscribe(new Subscriber() { @@ -115,16 +115,16 @@ public class UndertowHttpHandlerAdapter implements io.undertow.server.HttpHandle private final StreamSourceChannel requestChannel; - private final DataBufferAllocator allocator; + private final DataBufferFactory dataBufferFactory; private final PooledByteBuffer pooledByteBuffer; public RequestBodyPublisher(HttpServerExchange exchange, - DataBufferAllocator allocator) { + DataBufferFactory dataBufferFactory) { this.requestChannel = exchange.getRequestChannel(); this.pooledByteBuffer = exchange.getConnection().getByteBufferPool().allocate(); - this.allocator = allocator; + this.dataBufferFactory = dataBufferFactory; } public void registerListener() { @@ -175,7 +175,7 @@ public class UndertowHttpHandlerAdapter implements io.undertow.server.HttpHandle } else { byteBuffer.flip(); - DataBuffer dataBuffer = allocator.wrap(byteBuffer); + DataBuffer dataBuffer = dataBufferFactory.wrap(byteBuffer); publishOnNext(dataBuffer); } } diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java index 67dd0a893ce..dd7507a78eb 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java @@ -33,7 +33,7 @@ import org.xnio.channels.StreamSinkChannel; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; import org.springframework.http.ZeroCopyHttpOutputMessage; @@ -57,8 +57,8 @@ public class UndertowServerHttpResponse extends AbstractServerHttpResponse public UndertowServerHttpResponse(HttpServerExchange exchange, StreamSinkChannel responseChannel, Function, Mono> responseBodyWriter, - DataBufferAllocator allocator) { - super(allocator); + DataBufferFactory dataBufferFactory) { + super(dataBufferFactory); Assert.notNull(exchange, "'exchange' is required."); Assert.notNull(responseChannel, "'responseChannel' must not be null"); Assert.notNull(responseBodyWriter, "'responseBodyWriter' must not be null"); diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/boot/UndertowHttpServer.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/boot/UndertowHttpServer.java index 7226e505d9e..66d92e2c257 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/boot/UndertowHttpServer.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/boot/UndertowHttpServer.java @@ -19,8 +19,8 @@ package org.springframework.http.server.reactive.boot; import io.undertow.Undertow; import io.undertow.server.HttpHandler; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.server.reactive.UndertowHttpHandlerAdapter; import org.springframework.util.Assert; @@ -31,18 +31,19 @@ public class UndertowHttpServer extends HttpServerSupport implements HttpServer private Undertow server; - private DataBufferAllocator allocator = new DefaultDataBufferAllocator(); + private DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); private boolean running; - public void setAllocator(DataBufferAllocator allocator) { - this.allocator = allocator; + public void setDataBufferFactory(DataBufferFactory dataBufferFactory) { + this.dataBufferFactory = dataBufferFactory; } @Override public void afterPropertiesSet() throws Exception { Assert.notNull(getHttpHandler()); - HttpHandler handler = new UndertowHttpHandlerAdapter(getHttpHandler(), allocator); + HttpHandler handler = + new UndertowHttpHandlerAdapter(getHttpHandler(), dataBufferFactory); int port = (getPort() != -1 ? getPort() : 8080); this.server = Undertow.builder().addHttpListener(port, "localhost") .setHandler(handler).build(); diff --git a/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/DefaultHttpRequestBuilder.java b/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/DefaultHttpRequestBuilder.java index cdbe4c9ed2b..d57db2042c0 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/DefaultHttpRequestBuilder.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/DefaultHttpRequestBuilder.java @@ -16,7 +16,6 @@ package org.springframework.web.client.reactive; - import java.net.URI; import java.util.ArrayList; import java.util.Arrays; @@ -30,7 +29,6 @@ import reactor.core.publisher.Mono; import org.springframework.core.ResolvableType; import org.springframework.core.codec.Encoder; -import org.springframework.core.io.buffer.DataBufferAllocator; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -150,10 +148,9 @@ public class DefaultHttpRequestBuilder implements HttpRequestBuilder { .findFirst(); if (messageEncoder.isPresent()) { - DataBufferAllocator allocator = request.allocator(); request.setBody(messageEncoder.get() - .encode(this.contentPublisher, allocator, requestBodyType, - mediaType)); + .encode(this.contentPublisher, request.dataBufferFactory(), + requestBodyType, mediaType)); } else { throw new WebClientException("Can't write request body " + diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java index 55939260071..ecf8ab2c621 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.result.view; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -28,8 +28,8 @@ import reactor.core.publisher.Flux; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.MediaType; import org.springframework.ui.ModelMap; import org.springframework.util.Assert; @@ -48,7 +48,7 @@ public abstract class AbstractView implements View, ApplicationContextAware { private final List mediaTypes = new ArrayList<>(4); - private DataBufferAllocator bufferAllocator = new DefaultDataBufferAllocator(); + private DataBufferFactory bufferAllocator = new DefaultDataBufferFactory(); private ApplicationContext applicationContext; @@ -79,19 +79,19 @@ public abstract class AbstractView implements View, ApplicationContextAware { } /** - * Configure the {@link DataBufferAllocator} to use for write I/O. - *

By default this is set to {@link DefaultDataBufferAllocator}. - * @param bufferAllocator the allocator to use + * Configure the {@link DataBufferFactory} to use for write I/O. + *

By default this is set to {@link DefaultDataBufferFactory}. + * @param bufferAllocator the factory to use */ - public void setBufferAllocator(DataBufferAllocator bufferAllocator) { + public void setBufferAllocator(DataBufferFactory bufferAllocator) { Assert.notNull(bufferAllocator, "'bufferAllocator' is required."); this.bufferAllocator = bufferAllocator; } /** - * Return the configured buffer allocator, never {@code null}. + * Return the configured buffer factory, never {@code null}. */ - public DataBufferAllocator getBufferAllocator() { + public DataBufferFactory getBufferAllocator() { return this.bufferAllocator; } diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java index fb4d2a0f727..9d334dbaba0 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolverSupport.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.result.view; import java.util.ArrayList; @@ -21,8 +22,8 @@ import java.util.List; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.Ordered; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.MediaType; import org.springframework.util.Assert; @@ -39,7 +40,7 @@ public abstract class ViewResolverSupport implements ApplicationContextAware, Or private List mediaTypes = new ArrayList<>(4); - private DataBufferAllocator bufferAllocator = new DefaultDataBufferAllocator(); + private DataBufferFactory bufferAllocator = new DefaultDataBufferFactory(); private ApplicationContext applicationContext; @@ -71,19 +72,19 @@ public abstract class ViewResolverSupport implements ApplicationContextAware, Or } /** - * Configure the {@link DataBufferAllocator} to use for write I/O. - *

By default this is set to {@link DefaultDataBufferAllocator}. - * @param bufferAllocator the allocator to use + * Configure the {@link DataBufferFactory} to use for write I/O. + *

By default this is set to {@link DefaultDataBufferFactory}. + * @param bufferAllocator the factory to use */ - public void setBufferAllocator(DataBufferAllocator bufferAllocator) { + public void setBufferAllocator(DataBufferFactory bufferAllocator) { Assert.notNull(bufferAllocator, "'bufferAllocator' is required."); this.bufferAllocator = bufferAllocator; } /** - * Return the configured buffer allocator, never {@code null}. + * Return the configured buffer factory, never {@code null}. */ - public DataBufferAllocator getBufferAllocator() { + public DataBufferFactory getBufferAllocator() { return this.bufferAllocator; } diff --git a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/ByteBufferEncoderTests.java b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/ByteBufferEncoderTests.java index 0a1b904dc9c..611662dad93 100644 --- a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/ByteBufferEncoderTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/ByteBufferEncoderTests.java @@ -61,7 +61,7 @@ public class ByteBufferEncoderTests extends AbstractDataBufferAllocatingTestCase Flux source = Flux.just(ByteBuffer.wrap(fooBytes), ByteBuffer.wrap(barBytes)); - Flux output = this.encoder.encode(source, this.allocator, + Flux output = this.encoder.encode(source, this.dataBufferFactory, ResolvableType.forClassWithGenerics(Publisher.class, ByteBuffer.class), null); TestSubscriber testSubscriber = new TestSubscriber<>(); diff --git a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/JacksonJsonEncoderTests.java b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/JacksonJsonEncoderTests.java index 676769cbb58..2523899e573 100644 --- a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/JacksonJsonEncoderTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/JacksonJsonEncoderTests.java @@ -50,7 +50,8 @@ public class JacksonJsonEncoderTests extends AbstractDataBufferAllocatingTestCas public void write() { Flux source = Flux.just(new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar")); - Flux output = this.encoder.encode(source, this.allocator, null, null); + Flux output = + this.encoder.encode(source, this.dataBufferFactory, null, null); TestSubscriber testSubscriber = new TestSubscriber<>(); testSubscriber.bindTo(output). diff --git a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/Jaxb2EncoderTests.java b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/Jaxb2EncoderTests.java index 56d2a7b6a2a..8d956741c08 100644 --- a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/Jaxb2EncoderTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/Jaxb2EncoderTests.java @@ -70,8 +70,8 @@ public class Jaxb2EncoderTests extends AbstractDataBufferAllocatingTestCase { @Test public void encode() { Flux source = Flux.just(new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar")); - Flux output = this.encoder - .encode(source, this.allocator, ResolvableType.forClass(Pojo.class), + Flux output = this.encoder.encode(source, this.dataBufferFactory, + ResolvableType.forClass(Pojo.class), MediaType.APPLICATION_XML); TestSubscriber testSubscriber = new TestSubscriber<>(); testSubscriber.bindTo(output).assertValuesWith(dataBuffer -> { diff --git a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/ResourceEncoderTests.java b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/ResourceEncoderTests.java index c3d67320dff..19b4c3bec93 100644 --- a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/ResourceEncoderTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/ResourceEncoderTests.java @@ -62,8 +62,8 @@ public class ResourceEncoderTests extends AbstractDataBufferAllocatingTestCase { Mono source = Mono.just(resource); - Flux output = this.encoder - .encode(source, this.allocator, ResolvableType.forClass(Resource.class), + Flux output = this.encoder.encode(source, this.dataBufferFactory, + ResolvableType.forClass(Resource.class), null); TestSubscriber testSubscriber = new TestSubscriber<>(); diff --git a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/StringEncoderTests.java b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/StringEncoderTests.java index 20e642d9346..eb3062e8bc2 100644 --- a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/StringEncoderTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/StringEncoderTests.java @@ -59,7 +59,7 @@ public class StringEncoderTests extends AbstractDataBufferAllocatingTestCase { @Test public void write() throws InterruptedException { Flux output = Flux.from( - this.encoder.encode(Flux.just("foo"), this.allocator, null, null)) + this.encoder.encode(Flux.just("foo"), this.dataBufferFactory, null, null)) .map(chunk -> { byte[] b = new byte[chunk.readableByteCount()]; chunk.read(b); diff --git a/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/AbstractDataBufferAllocatingTestCase.java b/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/AbstractDataBufferAllocatingTestCase.java index 958bf947e0d..8afe4d5abf7 100644 --- a/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/AbstractDataBufferAllocatingTestCase.java +++ b/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/AbstractDataBufferAllocatingTestCase.java @@ -37,28 +37,28 @@ import static org.junit.Assert.assertEquals; public abstract class AbstractDataBufferAllocatingTestCase { @Parameterized.Parameter - public DataBufferAllocator allocator; + public DataBufferFactory dataBufferFactory; @Parameterized.Parameters(name = "{0}") - public static Object[][] allocators() { + public static Object[][] dataBufferFactories() { return new Object[][]{ - {new NettyDataBufferAllocator(new UnpooledByteBufAllocator(true))}, - {new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false))}, - {new NettyDataBufferAllocator(new PooledByteBufAllocator(true))}, - {new NettyDataBufferAllocator(new PooledByteBufAllocator(false))}, - {new DefaultDataBufferAllocator(true)}, - {new DefaultDataBufferAllocator(false)} + {new NettyDataBufferFactory(new UnpooledByteBufAllocator(true))}, + {new NettyDataBufferFactory(new UnpooledByteBufAllocator(false))}, + {new NettyDataBufferFactory(new PooledByteBufAllocator(true))}, + {new NettyDataBufferFactory(new PooledByteBufAllocator(false))}, + {new DefaultDataBufferFactory(true)}, + {new DefaultDataBufferFactory(false)} }; } protected DataBuffer createDataBuffer(int capacity) { - return this.allocator.allocateBuffer(capacity); + return this.dataBufferFactory.allocateBuffer(capacity); } protected DataBuffer stringBuffer(String value) { byte[] bytes = value.getBytes(StandardCharsets.UTF_8); - DataBuffer buffer = this.allocator.allocateBuffer(bytes.length); + DataBuffer buffer = this.dataBufferFactory.allocateBuffer(bytes.length); buffer.write(bytes); return buffer; } diff --git a/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/PooledDataBufferTests.java b/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/PooledDataBufferTests.java index c0f4ae591f8..1acc24fa0e1 100644 --- a/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/PooledDataBufferTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/PooledDataBufferTests.java @@ -32,20 +32,20 @@ import static org.junit.Assert.assertTrue; public class PooledDataBufferTests { @Parameterized.Parameter - public DataBufferAllocator allocator; + public DataBufferFactory dataBufferFactory; @Parameterized.Parameters(name = "{0}") public static Object[][] buffers() { return new Object[][]{ - {new NettyDataBufferAllocator(new UnpooledByteBufAllocator(true))}, - {new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false))}, - {new NettyDataBufferAllocator(new PooledByteBufAllocator(true))}, - {new NettyDataBufferAllocator(new PooledByteBufAllocator(false))}}; + {new NettyDataBufferFactory(new UnpooledByteBufAllocator(true))}, + {new NettyDataBufferFactory(new UnpooledByteBufAllocator(false))}, + {new NettyDataBufferFactory(new PooledByteBufAllocator(true))}, + {new NettyDataBufferFactory(new PooledByteBufAllocator(false))}}; } private PooledDataBuffer createDataBuffer(int capacity) { - return (PooledDataBuffer) allocator.allocateBuffer(capacity); + return (PooledDataBuffer) dataBufferFactory.allocateBuffer(capacity); } @Test diff --git a/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java b/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java index 05fa82283a8..6c5012e5a58 100644 --- a/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java @@ -33,7 +33,7 @@ public class DataBufferTestUtilsTests extends AbstractDataBufferAllocatingTestCa @Test public void dumpBytes() { - DataBuffer buffer = this.allocator.allocateBuffer(4); + DataBuffer buffer = this.dataBufferFactory.allocateBuffer(4); byte[] source = {'a', 'b', 'c', 'd'}; buffer.write(source); @@ -46,7 +46,7 @@ public class DataBufferTestUtilsTests extends AbstractDataBufferAllocatingTestCa @Test public void dumpString() { - DataBuffer buffer = this.allocator.allocateBuffer(4); + DataBuffer buffer = this.dataBufferFactory.allocateBuffer(4); String source = "abcd"; buffer.write(source.getBytes(StandardCharsets.UTF_8)); diff --git a/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/support/DataBufferUtilsTests.java b/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/support/DataBufferUtilsTests.java index e00aa4125b8..22e123cbf3b 100644 --- a/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/support/DataBufferUtilsTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/support/DataBufferUtilsTests.java @@ -45,7 +45,7 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase { .toURI(); FileChannel channel = FileChannel.open(Paths.get(uri), StandardOpenOption.READ); - Flux flux = DataBufferUtils.read(channel, this.allocator, 4); + Flux flux = DataBufferUtils.read(channel, this.dataBufferFactory, 4); TestSubscriber testSubscriber = new TestSubscriber<>(); testSubscriber.bindTo(flux). @@ -63,7 +63,7 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase { .toURI(); FileChannel channel = FileChannel.open(Paths.get(uri), StandardOpenOption.READ); - Flux flux = DataBufferUtils.read(channel, this.allocator, 3); + Flux flux = DataBufferUtils.read(channel, this.dataBufferFactory, 3); TestSubscriber testSubscriber = new TestSubscriber<>(); testSubscriber.bindTo(flux). @@ -81,7 +81,7 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase { InputStream is = DataBufferUtilsTests.class .getResourceAsStream("DataBufferUtilsTests.txt"); - Flux flux = DataBufferUtils.read(is, this.allocator, 4); + Flux flux = DataBufferUtils.read(is, this.dataBufferFactory, 4); TestSubscriber testSubscriber = new TestSubscriber<>(); testSubscriber.bindTo(flux). diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java index 69658622bc8..54c922baec2 100644 --- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java @@ -21,14 +21,14 @@ import java.time.Duration; import org.hamcrest.Matchers; import org.junit.Test; +import reactor.core.publisher.Computations; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import reactor.core.publisher.Computations; import reactor.core.scheduler.Scheduler; import reactor.core.scheduler.Timer; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; @@ -44,7 +44,7 @@ public class AsyncIntegrationTests extends AbstractHttpHandlerIntegrationTests { private final Scheduler asyncGroup = Computations.parallel(); - private final DataBufferAllocator allocator = new DefaultDataBufferAllocator(); + private final DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); @Override protected AsyncHandler createHttpHandler() { @@ -69,8 +69,7 @@ public class AsyncIntegrationTests extends AbstractHttpHandlerIntegrationTests { .useTimer(Timer.global()) .delay(Duration.ofMillis(100)) .publishOn(asyncGroup) - .collect(allocator::allocateBuffer, - (buffer, str) -> buffer.write(str.getBytes()))); + .collect(dataBufferFactory::allocateBuffer, (buffer, str) -> buffer.write(str.getBytes()))); } } diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java index 91f370a0563..baae492abf2 100644 --- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java +++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java @@ -23,8 +23,8 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; @@ -44,7 +44,7 @@ public class MockServerHttpResponse implements ServerHttpResponse { private Publisher body; - private DataBufferAllocator allocator = new DefaultDataBufferAllocator(); + private DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); @Override @@ -86,8 +86,8 @@ public class MockServerHttpResponse implements ServerHttpResponse { } @Override - public DataBufferAllocator allocator() { - return this.allocator; + public DataBufferFactory dataBufferFactory() { + return this.dataBufferFactory; } } diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java index 7e92d620dff..8ab8aa79179 100644 --- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java @@ -27,8 +27,8 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.http.server.reactive.boot.ReactorHttpServer; @@ -48,7 +48,7 @@ public class RandomHandlerIntegrationTests extends AbstractHttpHandlerIntegratio private final RandomHandler handler = new RandomHandler(); - private final DataBufferAllocator allocator = new DefaultDataBufferAllocator(); + private final DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); @Override @@ -146,7 +146,7 @@ public class RandomHandlerIntegrationTests extends AbstractHttpHandlerIntegratio private DataBuffer randomBuffer(int size) { byte[] bytes = new byte[size]; rnd.nextBytes(bytes); - DataBuffer buffer = allocator.allocateBuffer(size); + DataBuffer buffer = dataBufferFactory.allocateBuffer(size); buffer.write(bytes); return buffer; } diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java index 1d0577d5b7a..049e5f5d4e3 100644 --- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java @@ -27,7 +27,7 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseCookie; @@ -133,7 +133,7 @@ public class ServerHttpResponseTests { private DataBuffer wrap(String a) { - return new DefaultDataBufferAllocator().wrap(ByteBuffer.wrap(a.getBytes(UTF_8))); + return new DefaultDataBufferFactory().wrap(ByteBuffer.wrap(a.getBytes(UTF_8))); } @@ -146,7 +146,7 @@ public class ServerHttpResponseTests { private final List content = new ArrayList<>(); public TestServerHttpResponse() { - super(new DefaultDataBufferAllocator()); + super(new DefaultDataBufferFactory()); } @Override diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java index c7f84a8028c..f014b1fcee9 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java @@ -34,7 +34,7 @@ import org.springframework.core.codec.support.StringDecoder; import org.springframework.core.codec.support.StringEncoder; import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -62,9 +62,7 @@ import org.springframework.web.server.handler.FilteringWebHandler; import org.springframework.web.server.session.WebSessionManager; import static org.hamcrest.CoreMatchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; import static org.mockito.Mockito.mock; /** @@ -162,7 +160,7 @@ public class DispatcherHandlerErrorTests { public void notAcceptable() throws Exception { this.request.setUri(new URI("/request-body")); this.request.getHeaders().setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - DataBuffer buffer = new DefaultDataBufferAllocator().allocateBuffer() + DataBuffer buffer = new DefaultDataBufferFactory().allocateBuffer() .write("body".getBytes("UTF-8")); this.request.setBody(Mono.just(buffer)); diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/WebHandlerIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/WebHandlerIntegrationTests.java index 7eee8878ed3..5445bf9b9f0 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/WebHandlerIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/WebHandlerIntegrationTests.java @@ -28,7 +28,7 @@ import reactor.core.publisher.Mono; import org.springframework.context.support.StaticApplicationContext; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpStatus; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; @@ -141,7 +141,8 @@ public class WebHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTe } private static DataBuffer asDataBuffer(String text) { - return new DefaultDataBufferAllocator().allocateBuffer().write(text.getBytes(StandardCharsets.UTF_8)); + return new DefaultDataBufferFactory().allocateBuffer() + .write(text.getBytes(StandardCharsets.UTF_8)); } private static class FooHandler implements WebHandler { diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java index c866052e9d1..561d407395c 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java @@ -53,8 +53,8 @@ import org.springframework.core.convert.support.ReactiveStreamsToRxJava1Converte import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferAllocator; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; @@ -82,9 +82,7 @@ import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigu import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** @@ -384,7 +382,7 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati @SuppressWarnings("unused") static class FrameworkConfig { - private DataBufferAllocator allocator = new DefaultDataBufferAllocator(); + private DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); @Bean @@ -432,7 +430,7 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati @Bean public ViewResolver freeMarkerViewResolver() { FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver("", ".ftl"); - viewResolver.setBufferAllocator(this.allocator); + viewResolver.setBufferAllocator(this.dataBufferFactory); return viewResolver; } @@ -485,9 +483,9 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati @RequestMapping("/raw") public Publisher rawResponseBody() { - DataBufferAllocator allocator = new DefaultDataBufferAllocator(); + DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); JacksonJsonEncoder encoder = new JacksonJsonEncoder(); - return encoder.encode(Mono.just(new Person("Robert")), allocator, + return encoder.encode(Mono.just(new Person("Robert")), dataBufferFactory, ResolvableType.forClass(Person.class), MediaType.APPLICATION_JSON).map(DataBuffer::asByteBuffer); } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java index 04f00bdd4c7..eff32fb3045 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.result.view; import java.lang.reflect.Method; @@ -40,7 +41,7 @@ import org.springframework.core.ResolvableType; import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.core.convert.support.ReactiveStreamsToRxJava1Converter; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DefaultDataBufferAllocator; +import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.MockServerHttpRequest; @@ -55,9 +56,7 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange; import org.springframework.web.server.session.DefaultWebSessionManager; import org.springframework.web.server.session.WebSessionManager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.mockito.Mockito.mock; @@ -253,7 +252,7 @@ public class ViewResolutionResultHandlerTests { private static DataBuffer asDataBuffer(String value) { ByteBuffer byteBuffer = ByteBuffer.wrap(value.getBytes(UTF_8)); - return new DefaultDataBufferAllocator().wrap(byteBuffer); + return new DefaultDataBufferFactory().wrap(byteBuffer); } private static String asString(DataBuffer dataBuffer) {