From beeb49d55b3b26d68e096d411a225c8cc950b8ce Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 27 Feb 2015 15:05:33 -0500 Subject: [PATCH] INT-3577: Remove flush() from TCP Serializers JIRA: https://jira.spring.io/browse/INT-3577 It is no longer necessary to `flush()` the `BufferedOutputStream`. Since INT-3575, the `TcpNetConnection` has flushed the stream. The `TcpNioConnection` now does so too. * Add `id` for the `
`s in the `whats-new.xml` --- .../ip/tcp/connection/TcpNioConnection.java | 3 ++- .../ip/tcp/serializer/ByteArrayCrLfSerializer.java | 3 +-- .../serializer/ByteArrayLengthHeaderSerializer.java | 4 ++-- .../ip/tcp/serializer/ByteArrayLfSerializer.java | 3 ++- .../ip/tcp/serializer/ByteArrayRawSerializer.java | 3 +-- .../ByteArraySingleTerminatorSerializer.java | 3 +-- .../tcp/serializer/ByteArrayStxEtxSerializer.java | 3 +-- .../ip/tcp/serializer/MapJsonSerializer.java | 5 ++--- src/reference/docbook/whats-new.xml | 13 +++++++++++-- 9 files changed, 23 insertions(+), 17 deletions(-) diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java index f883208fed..ebda07f2aa 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -145,6 +145,7 @@ public class TcpNioConnection extends TcpConnectionSupport { this.lastSend = System.currentTimeMillis(); try { ((Serializer) this.getSerializer()).serialize(object, this.bufferedOutputStream); + this.bufferedOutputStream.flush(); } catch (Exception e) { this.publishConnectionExceptionEvent(e); diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayCrLfSerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayCrLfSerializer.java index 610492edd5..9b3a0ba701 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayCrLfSerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayCrLfSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -89,7 +89,6 @@ public class ByteArrayCrLfSerializer extends AbstractByteArraySerializer { public void serialize(byte[] bytes, OutputStream outputStream) throws IOException { outputStream.write(bytes); outputStream.write(CRLF); - outputStream.flush(); } } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java index a44372ffb6..2e51bfa473 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLengthHeaderSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -133,7 +133,6 @@ public class ByteArrayLengthHeaderSerializer extends AbstractByteArraySerializer public void serialize(byte[] bytes, OutputStream outputStream) throws IOException { this.writeHeader(outputStream, bytes.length); outputStream.write(bytes); - outputStream.flush(); } /** @@ -253,4 +252,5 @@ public class ByteArrayLengthHeaderSerializer extends AbstractByteArraySerializer throw e; } } + } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLfSerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLfSerializer.java index b122339969..1b0fba8df5 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLfSerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayLfSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -25,4 +25,5 @@ public class ByteArrayLfSerializer extends ByteArraySingleTerminatorSerializer { public ByteArrayLfSerializer() { super((byte) 0x0a); } + } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayRawSerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayRawSerializer.java index e1b1718273..b212f2f8af 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayRawSerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayRawSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -39,7 +39,6 @@ public class ByteArrayRawSerializer extends AbstractByteArraySerializer { public void serialize(byte[] bytes, OutputStream outputStream) throws IOException { outputStream.write(bytes); - outputStream.flush(); } @Override diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArraySingleTerminatorSerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArraySingleTerminatorSerializer.java index c26e04c3a0..a0c400c915 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArraySingleTerminatorSerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArraySingleTerminatorSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -91,7 +91,6 @@ public class ByteArraySingleTerminatorSerializer extends AbstractByteArraySerial public void serialize(byte[] bytes, OutputStream outputStream) throws IOException { outputStream.write(bytes); outputStream.write(terminator); - outputStream.flush(); } } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayStxEtxSerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayStxEtxSerializer.java index 7e168f1503..58be1b6a20 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayStxEtxSerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/ByteArrayStxEtxSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -88,7 +88,6 @@ public class ByteArrayStxEtxSerializer extends AbstractByteArraySerializer { outputStream.write(STX); outputStream.write(bytes); outputStream.write(ETX); - outputStream.flush(); } } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/MapJsonSerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/MapJsonSerializer.java index 2b3e2d13dd..94d8d05aa9 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/MapJsonSerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/MapJsonSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -26,8 +26,8 @@ import java.util.Map; import org.springframework.core.serializer.Deserializer; import org.springframework.core.serializer.Serializer; -import org.springframework.integration.support.json.JsonObjectMapperProvider; import org.springframework.integration.support.json.JsonObjectMapper; +import org.springframework.integration.support.json.JsonObjectMapperProvider; import org.springframework.util.Assert; /** @@ -107,7 +107,6 @@ public class MapJsonSerializer implements Serializer>, Deserializerfalse. -
+
Class Package Change The ScatterGatherHandler class has been moved from the @@ -39,6 +39,15 @@ org.springframework.integration.scattergather.
+
+ TCP Serializers + + The TCP Serializers no longer flush() the + OutputStream; this is now done by the TcpNxxConnection + classes. If you are using the serializers directly within user code, you may have to + flush() the OutputStream. + +
Server Socket Exceptions @@ -47,7 +56,7 @@ See for more information.
-
+
@InboundChannelAdapter Previously, the @Poller on an inbound channel adapter defaulted