Skip to content

Commit eae1c4f

Browse files
author
Simon MacMullen
committed
Those clearXXXListeners() are not needed, so clean up a bit.
1 parent f752dfe commit eae1c4f

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

test/src/com/rabbitmq/examples/perf/MulticastParams.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ public int getMinMsgSize() {
142142
return minMsgSize;
143143
}
144144

145-
public Producer createProducer(Connection connection, Channel channel, Stats stats, String id) throws IOException {
145+
public Producer createProducer(Connection connection, Stats stats, String id) throws IOException {
146+
Channel channel = connection.createChannel();
146147
if (producerTxSize > 0) channel.txSelect();
147148
if (confirm >= 0) channel.confirmSelect();
148149
if (!exchangeExists(connection, exchangeName)) {
@@ -158,9 +159,10 @@ public Producer createProducer(Connection connection, Channel channel, Stats sta
158159
return producer;
159160
}
160161

161-
public Consumer createConsumer(Connection connection, Channel channel, Stats stats, String id) throws IOException {
162+
public Consumer createConsumer(Connection connection, Stats stats, String id) throws IOException {
163+
Channel channel = connection.createChannel();
162164
if (consumerTxSize > 0) channel.txSelect();
163-
String qName = configureQueue(connection, channel, id);
165+
String qName = configureQueue(connection, id);
164166
if (prefetchCount > 0) channel.basicQos(prefetchCount);
165167
return new Consumer(channel, id, qName,
166168
consumerTxSize, autoAck, multiAckEvery,
@@ -171,7 +173,8 @@ public boolean shouldConfigureQueue() {
171173
return consumerCount == 0 && !queueName.equals("");
172174
}
173175

174-
public String configureQueue(Connection connection, Channel channel, String id) throws IOException {
176+
public String configureQueue(Connection connection, String id) throws IOException {
177+
Channel channel = connection.createChannel();
175178
if (!exchangeExists(connection, exchangeName)) {
176179
channel.exchangeDeclare(exchangeName, exchangeType);
177180
}
@@ -183,6 +186,7 @@ public String configureQueue(Connection connection, Channel channel, String id)
183186
null).getQueue();
184187
}
185188
channel.queueBind(qName, exchangeName, id);
189+
channel.close();
186190
return qName;
187191
}
188192

test/src/com/rabbitmq/examples/perf/MulticastSet.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,25 @@ public void run(boolean announceStartup) throws IOException, InterruptedExceptio
5050
}
5151
Connection conn = factory.newConnection();
5252
consumerConnections[i] = conn;
53-
Channel channel = conn.createChannel();
54-
Thread t = new Thread(params.createConsumer(conn, channel, stats, id));
53+
Thread t = new Thread(params.createConsumer(conn, stats, id));
5554
consumerThreads[i] = t;
5655
}
5756

5857
if (params.shouldConfigureQueue()) {
5958
Connection conn = factory.newConnection();
60-
Channel channel = conn.createChannel();
61-
params.configureQueue(conn, channel, id);
59+
params.configureQueue(conn, id);
6260
conn.close();
6361
}
6462

6563
Thread[] producerThreads = new Thread[params.getProducerCount()];
6664
Connection[] producerConnections = new Connection[producerThreads.length];
67-
Channel[] producerChannels = new Channel[producerConnections.length];
68-
for (int i = 0; i < producerChannels.length; i++) {
65+
for (int i = 0; i < producerThreads.length; i++) {
6966
if (announceStartup) {
7067
System.out.println("starting producer #" + i);
7168
}
7269
Connection conn = factory.newConnection();
7370
producerConnections[i] = conn;
74-
Channel channel = conn.createChannel();
75-
producerChannels[i] = channel;
76-
Thread t = new Thread(params.createProducer(conn, channel, stats, id));
71+
Thread t = new Thread(params.createProducer(conn, stats, id));
7772
producerThreads[i] = t;
7873
}
7974

@@ -87,8 +82,6 @@ public void run(boolean announceStartup) throws IOException, InterruptedExceptio
8782

8883
for (int i = 0; i < producerThreads.length; i++) {
8984
producerThreads[i].join();
90-
producerChannels[i].clearReturnListeners();
91-
producerChannels[i].clearConfirmListeners();
9285
producerConnections[i].close();
9386
}
9487

0 commit comments

Comments
 (0)