Shared static instance of DefaultDataBufferFactory
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -73,8 +73,6 @@ public abstract class AbstractEncoderMethodReturnValueHandler implements Handler
|
||||
|
||||
private final ReactiveAdapterRegistry adapterRegistry;
|
||||
|
||||
private DataBufferFactory defaultBufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
protected AbstractEncoderMethodReturnValueHandler(List<Encoder<?>> encoders, ReactiveAdapterRegistry registry) {
|
||||
Assert.notEmpty(encoders, "At least one Encoder is required");
|
||||
@@ -114,7 +112,8 @@ public abstract class AbstractEncoderMethodReturnValueHandler implements Handler
|
||||
}
|
||||
|
||||
DataBufferFactory bufferFactory = (DataBufferFactory) message.getHeaders()
|
||||
.getOrDefault(HandlerMethodReturnValueHandler.DATA_BUFFER_FACTORY_HEADER, this.defaultBufferFactory);
|
||||
.getOrDefault(HandlerMethodReturnValueHandler.DATA_BUFFER_FACTORY_HEADER,
|
||||
DefaultDataBufferFactory.sharedInstance);
|
||||
|
||||
MimeType mimeType = (MimeType) message.getHeaders().get(MessageHeaders.CONTENT_TYPE);
|
||||
Flux<DataBuffer> encodedContent = encodeContent(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,7 +35,6 @@ import org.springframework.core.codec.StringDecoder;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.handler.DestinationPatternsMessageCondition;
|
||||
@@ -60,9 +59,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@SuppressWarnings("ALL")
|
||||
public class MessageMappingMessageHandlerTests {
|
||||
|
||||
private static final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
private TestEncoderMethodReturnValueHandler returnValueHandler;
|
||||
|
||||
|
||||
@@ -163,7 +159,7 @@ public class MessageMappingMessageHandlerTests {
|
||||
}
|
||||
|
||||
private DataBuffer toDataBuffer(String payload) {
|
||||
return bufferFactory.wrap(payload.getBytes(UTF_8));
|
||||
return DefaultDataBufferFactory.sharedInstance.wrap(payload.getBytes(UTF_8));
|
||||
}
|
||||
|
||||
private void verifyOutputContent(List<String> expected) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -154,7 +154,7 @@ public class PayloadMethodArgumentResolverTests {
|
||||
|
||||
|
||||
private DataBuffer toDataBuffer(String value) {
|
||||
return new DefaultDataBufferFactory().wrap(value.getBytes(StandardCharsets.UTF_8));
|
||||
return DefaultDataBufferFactory.sharedInstance.wrap(value.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ public class DefaultRSocketRequesterBuilderTests {
|
||||
@Test
|
||||
public void frameDecoderMatchesDataBufferFactory() throws Exception {
|
||||
testPayloadDecoder(new NettyDataBufferFactory(ByteBufAllocator.DEFAULT), PayloadDecoder.ZERO_COPY);
|
||||
testPayloadDecoder(new DefaultDataBufferFactory(), PayloadDecoder.DEFAULT);
|
||||
testPayloadDecoder(DefaultDataBufferFactory.sharedInstance, PayloadDecoder.DEFAULT);
|
||||
}
|
||||
|
||||
private void testPayloadDecoder(DataBufferFactory bufferFactory, PayloadDecoder payloadDecoder)
|
||||
|
||||
@@ -65,8 +65,6 @@ public class DefaultRSocketRequesterTests {
|
||||
|
||||
private final RSocketStrategies strategies = RSocketStrategies.create();
|
||||
|
||||
private final DefaultDataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
@@ -244,7 +242,8 @@ public class DefaultRSocketRequesterTests {
|
||||
}
|
||||
|
||||
private Payload toPayload(String value) {
|
||||
return PayloadUtils.createPayload(bufferFactory.wrap(value.getBytes(StandardCharsets.UTF_8)));
|
||||
byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
|
||||
return PayloadUtils.createPayload(DefaultDataBufferFactory.sharedInstance.wrap(bytes));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ public class MetadataEncoderTests {
|
||||
|
||||
@Test
|
||||
public void defaultDataBufferFactory() {
|
||||
DefaultDataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
DefaultDataBufferFactory bufferFactory = DefaultDataBufferFactory.sharedInstance;
|
||||
RSocketStrategies strategies = RSocketStrategies.builder().dataBufferFactory(bufferFactory).build();
|
||||
|
||||
DataBuffer buffer = new MetadataEncoder(COMPOSITE_METADATA, strategies)
|
||||
|
||||
@@ -44,8 +44,6 @@ public class PayloadUtilsTests {
|
||||
private LeakAwareNettyDataBufferFactory nettyBufferFactory =
|
||||
new LeakAwareNettyDataBufferFactory(PooledByteBufAllocator.DEFAULT);
|
||||
|
||||
private DefaultDataBufferFactory defaultBufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
@@ -70,7 +68,7 @@ public class PayloadUtilsTests {
|
||||
@Test
|
||||
public void retainAndReleaseWithDefaultFactory() {
|
||||
Payload payload = ByteBufPayload.create("sample data");
|
||||
DataBuffer buffer = PayloadUtils.retainDataAndReleasePayload(payload, this.defaultBufferFactory);
|
||||
DataBuffer buffer = PayloadUtils.retainDataAndReleasePayload(payload, DefaultDataBufferFactory.sharedInstance);
|
||||
|
||||
assertThat(buffer).isInstanceOf(DefaultDataBuffer.class);
|
||||
assertThat(payload.refCnt()).isEqualTo(0);
|
||||
@@ -163,7 +161,7 @@ public class PayloadUtilsTests {
|
||||
}
|
||||
|
||||
private DefaultDataBuffer createDefaultDataBuffer(String content) {
|
||||
DefaultDataBuffer buffer = this.defaultBufferFactory.allocateBuffer();
|
||||
DefaultDataBuffer buffer = DefaultDataBufferFactory.sharedInstance.allocateBuffer();
|
||||
buffer.write(content, StandardCharsets.UTF_8);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user