Skip to content

Commit 7bb42e8

Browse files
MessageBodyCreator => MessageBodySource
1 parent 796ffa9 commit 7bb42e8

File tree

6 files changed

+21
-25
lines changed

6 files changed

+21
-25
lines changed

src/main/java/com/rabbitmq/perf/FromFilesMessageBodyCreator.java renamed to src/main/java/com/rabbitmq/perf/FromFilesMessageBodySource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
/**
2323
*
2424
*/
25-
public class FromFilesMessageBodyCreator implements MessageBodyCreator {
25+
public class FromFilesMessageBodySource implements MessageBodySource {
2626

2727
private final List<byte[]> bodies;
2828

2929
private final String contentType;
3030

31-
public FromFilesMessageBodyCreator(List<String> filesNames, String contentType) throws IOException {
31+
public FromFilesMessageBodySource(List<String> filesNames, String contentType) throws IOException {
3232
bodies = new ArrayList<byte[]>(filesNames.size());
3333
for (String fileName : filesNames) {
3434
File file = new File(fileName.trim());
@@ -51,7 +51,7 @@ public FromFilesMessageBodyCreator(List<String> filesNames, String contentType)
5151
this.contentType = contentType;
5252
}
5353

54-
public FromFilesMessageBodyCreator(List<String> filesNames) throws IOException {
54+
public FromFilesMessageBodySource(List<String> filesNames) throws IOException {
5555
this(filesNames, null);
5656
}
5757

src/main/java/com/rabbitmq/perf/MessageBodyCreator.java renamed to src/main/java/com/rabbitmq/perf/MessageBodySource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
import java.io.IOException;
1919

2020
/**
21-
*
21+
* Sources produce message bodies and content type
22+
* used by publishers.
2223
*/
23-
public interface MessageBodyCreator {
24+
public interface MessageBodySource {
2425

2526
MessageBodyAndContentType create(int sequenceNumber) throws IOException;
2627

src/main/java/com/rabbitmq/perf/MulticastParams.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,17 @@ public Producer createProducer(Connection connection, Stats stats, String id) th
223223
if (!predeclared || !exchangeExists(connection, exchangeName)) {
224224
channel.exchangeDeclare(exchangeName, exchangeType);
225225
}
226-
MessageBodyCreator messageBodyCreator = null;
226+
MessageBodySource messageBodySource = null;
227227
if (bodyFiles.size() > 0) {
228-
messageBodyCreator = new FromFilesMessageBodyCreator(bodyFiles, bodyContentType);
228+
messageBodySource = new FromFilesMessageBodySource(bodyFiles, bodyContentType);
229229
} else {
230-
messageBodyCreator = new SequenceTimeMessageBodyCreator(minMsgSize);
230+
messageBodySource = new SequenceTimeMessageBodySource(minMsgSize);
231231
}
232232
final Producer producer = new Producer(channel, exchangeName, id,
233233
randomRoutingKey, flags, producerTxSize,
234234
producerRateLimit, producerMsgCount,
235235
timeLimit,
236-
confirm, messageBodyCreator, stats);
236+
confirm, messageBodySource, stats);
237237
channel.addReturnListener(producer);
238238
channel.addConfirmListener(producer);
239239
return producer;

src/main/java/com/rabbitmq/perf/Producer.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818
import com.rabbitmq.client.AMQP;
1919
import com.rabbitmq.client.Channel;
2020
import com.rabbitmq.client.ConfirmListener;
21-
import com.rabbitmq.client.MessageProperties;
2221
import com.rabbitmq.client.ReturnListener;
2322

24-
import java.io.ByteArrayOutputStream;
25-
import java.io.DataOutputStream;
2623
import java.io.IOException;
2724
import java.util.Collections;
2825
import java.util.List;
@@ -47,7 +44,7 @@ public class Producer extends ProducerConsumerBase implements Runnable, ReturnLi
4744

4845
private final Stats stats;
4946

50-
private final MessageBodyCreator messageBodyCreator;
47+
private final MessageBodySource messageBodySource;
5148

5249
private Semaphore confirmPool;
5350
private final SortedSet<Long> unconfirmedSet =
@@ -56,7 +53,7 @@ public class Producer extends ProducerConsumerBase implements Runnable, ReturnLi
5653
public Producer(Channel channel, String exchangeName, String id, boolean randomRoutingKey,
5754
List<?> flags, int txSize,
5855
float rateLimit, int msgLimit, int timeLimit,
59-
long confirm, MessageBodyCreator messageBodyCreator, Stats stats)
56+
long confirm, MessageBodySource messageBodySource, Stats stats)
6057
throws IOException {
6158

6259
this.channel = channel;
@@ -70,7 +67,7 @@ public Producer(Channel channel, String exchangeName, String id, boolean randomR
7067
this.rateLimit = rateLimit;
7168
this.msgLimit = msgLimit;
7269
this.timeLimit = 1000L * timeLimit;
73-
this.messageBodyCreator = messageBodyCreator;
70+
this.messageBodySource = messageBodySource;
7471
if (confirm > 0) {
7572
this.confirmPool = new Semaphore((int)confirm);
7673
}
@@ -136,7 +133,7 @@ public void run() {
136133
if (confirmPool != null) {
137134
confirmPool.acquire();
138135
}
139-
publish(messageBodyCreator.create(totalMsgCount));
136+
publish(messageBodySource.create(totalMsgCount));
140137
totalMsgCount++;
141138
msgCount++;
142139

@@ -154,7 +151,7 @@ public void run() {
154151
}
155152
}
156153

157-
private void publish(MessageBodyCreator.MessageBodyAndContentType messageBodyAndContentType)
154+
private void publish(MessageBodySource.MessageBodyAndContentType messageBodyAndContentType)
158155
throws IOException {
159156

160157
AMQP.BasicProperties.Builder propertiesBuilder = new AMQP.BasicProperties.Builder();

src/main/java/com/rabbitmq/perf/SequenceTimeMessageBodyCreator.java renamed to src/main/java/com/rabbitmq/perf/SequenceTimeMessageBodySource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
/**
2323
*
2424
*/
25-
public class SequenceTimeMessageBodyCreator implements MessageBodyCreator {
25+
public class SequenceTimeMessageBodySource implements MessageBodySource {
2626

2727
private final byte[] message;
2828

29-
public SequenceTimeMessageBodyCreator(int minMsgSize) {
29+
public SequenceTimeMessageBodySource(int minMsgSize) {
3030
this.message = new byte[minMsgSize];
3131
}
3232

src/test/java/com/rabbitmq/perf/FromFilesMessageBodyCreatorTest.java renamed to src/test/java/com/rabbitmq/perf/FromFilesMessageBodySourceTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515

1616
package com.rabbitmq.perf;
1717

18-
import org.junit.Assert;
1918
import org.junit.Rule;
2019
import org.junit.Test;
2120
import org.junit.rules.TemporaryFolder;
2221

2322
import java.io.File;
2423
import java.io.FileWriter;
2524
import java.util.ArrayList;
26-
import java.util.Arrays;
2725
import java.util.List;
2826

2927
import static java.util.Arrays.asList;
@@ -33,7 +31,7 @@
3331
/**
3432
*
3533
*/
36-
public class FromFilesMessageBodyCreatorTest {
34+
public class FromFilesMessageBodySourceTest {
3735

3836
@Rule
3937
public TemporaryFolder folder = new TemporaryFolder();
@@ -42,7 +40,7 @@ public class FromFilesMessageBodyCreatorTest {
4240
File file = folder.newFile("content.txt");
4341
String content = "dummy content";
4442
write(file, content);
45-
MessageBodyCreator creator = new FromFilesMessageBodyCreator(asList(file.getAbsolutePath()));
43+
MessageBodySource creator = new FromFilesMessageBodySource(asList(file.getAbsolutePath()));
4644
byte[] body1 = creator.create(1).getBody();
4745
byte[] body2 = creator.create(1).getBody();
4846
assertEquals(content, new String(body1, "UTF-8"));
@@ -58,7 +56,7 @@ public class FromFilesMessageBodyCreatorTest {
5856
files.add(file.getAbsolutePath());
5957
}
6058

61-
MessageBodyCreator creator = new FromFilesMessageBodyCreator(files);
59+
MessageBodySource creator = new FromFilesMessageBodySource(files);
6260
byte[] body0 = creator.create(0).getBody();
6361
assertEquals("content0", new String(body0, "UTF-8"));
6462
byte[] body1 = creator.create(1).getBody();
@@ -72,7 +70,7 @@ public class FromFilesMessageBodyCreatorTest {
7270
@Test public void createFileDoesNotExist() throws Exception {
7371
File file = new File(folder.getRoot(), "dummy.txt");
7472
try {
75-
new FromFilesMessageBodyCreator(asList(file.getAbsolutePath()));
73+
new FromFilesMessageBodySource(asList(file.getAbsolutePath()));
7674
fail("File does not exist, exception should have thrown");
7775
} catch (IllegalArgumentException e) {
7876
// ok

0 commit comments

Comments
 (0)