Skip to content

Commit ac2f60a

Browse files
authored
Remove extra buffer copy in StompNIOSSLTransport (#2107) (#2109)
Optimizes the StompNIOSSLTransport by removing the unnecessary extra byte array allocation and buffer copy when processing frames
1 parent a7c1ab5 commit ac2f60a

3 files changed

Lines changed: 5 additions & 11 deletions

File tree

activemq-stomp/src/main/java/org/apache/activemq/transport/stomp/StompCodec.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.activemq.transport.stomp;
1818

1919
import java.io.ByteArrayInputStream;
20+
import java.nio.ByteBuffer;
2021
import java.util.Arrays;
2122
import java.util.Collections;
2223
import java.util.HashSet;
@@ -47,11 +48,11 @@ public StompCodec(TcpTransport transport) {
4748
this.wireFormat = (StompWireFormat) Objects.requireNonNull(transport.getWireFormat());
4849
}
4950

50-
public void parse(ByteArrayInputStream input, int readSize) throws Exception {
51+
public void parse(ByteBuffer input, int readSize) throws Exception {
5152
int i = 0;
5253
int b;
5354
while(i++ < readSize) {
54-
b = input.read();
55+
b = input.get();
5556
// skip repeating nulls
5657
if (!processedHeaders && previousByte == 0 && b == 0) {
5758
continue;

activemq-stomp/src/main/java/org/apache/activemq/transport/stomp/StompNIOSSLTransport.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ protected void initializeStreams() throws IOException {
7474

7575
@Override
7676
protected void processCommand(ByteBuffer plain) throws Exception {
77-
byte[] fill = new byte[plain.remaining()];
78-
plain.get(fill);
79-
ByteArrayInputStream input = new ByteArrayInputStream(fill);
80-
codec.parse(input, fill.length);
77+
codec.parse(plain, plain.remaining());
8178
}
8279

8380
@Override

activemq-stomp/src/main/java/org/apache/activemq/transport/stomp/StompNIOTransport.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,8 @@ private void serviceRead() {
129129

130130
protected void processBuffer(ByteBuffer buffer, int readSize) throws Exception {
131131
receiveCounter.addAndGet(readSize);
132-
133132
buffer.flip();
134-
135-
ByteArrayInputStream input = new ByteArrayInputStream(buffer.array());
136-
codec.parse(input, readSize);
137-
133+
codec.parse(buffer, readSize);
138134
// clear the buffer
139135
buffer.clear();
140136
}

0 commit comments

Comments
 (0)