Skip to content

Commit 2a638c8

Browse files
committed
Polish
Fixes #11
1 parent ed3deab commit 2a638c8

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/main/java/com/rabbitmq/client/impl/SocketChannelFrameHandlerFactory.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
import java.util.Iterator;
3333
import java.util.Queue;
3434
import java.util.Set;
35-
import java.util.concurrent.*;
35+
import java.util.concurrent.ExecutorService;
36+
import java.util.concurrent.Future;
37+
import java.util.concurrent.LinkedBlockingQueue;
38+
import java.util.concurrent.ThreadFactory;
3639
import java.util.concurrent.atomic.AtomicLong;
3740
import java.util.concurrent.locks.Lock;
3841
import java.util.concurrent.locks.ReentrantLock;
@@ -57,7 +60,12 @@ public class SocketChannelFrameHandlerFactory extends AbstractFrameHandlerFactor
5760

5861
private Thread readThread, writeThread;
5962

60-
private Future<?> readTask, writeTask;
63+
private Future<?> writeTask;
64+
65+
// FIXME make the following configuration settings
66+
// size of byte buffers
67+
// nb of NIO threads (should be even, 1 thread for read, 1 thread for write to scale IO
68+
// SocketChannelFrameHandlerState.write timeout
6169

6270
public SocketChannelFrameHandlerFactory(int connectionTimeout, SocketConfigurator configurator, boolean ssl, ExecutorService executorService) throws IOException {
6371
super(connectionTimeout, configurator, ssl);
@@ -100,10 +108,6 @@ public FrameHandler create(Address addr) throws IOException {
100108
}
101109

102110
protected boolean cleanUp() {
103-
// get connection count
104-
// lock
105-
// if connection count has changed, do nothing
106-
// if connection count hasn't changed, clean
107111
long connectionCountNow = connectionCount.get();
108112
stateLock.lock();
109113
try {
@@ -143,11 +147,9 @@ protected boolean cleanUp() {
143147

144148
protected void initStateIfNecessary() throws IOException {
145149
if(this.readSelectorState == null) {
146-
// create selectors
147150
this.readSelectorState = new SelectorState(Selector.open());
148151
this.writeSelectorState = new SelectorState(Selector.open());
149152

150-
// create threads/tasks
151153
startIoLoops();
152154
}
153155
}
@@ -159,7 +161,7 @@ protected void startIoLoops() {
159161
readThread.start();
160162
writeThread.start();
161163
} else {
162-
this.readTask = this.executorService.submit(new ReadLoop(this.readSelectorState));
164+
this.executorService.submit(new ReadLoop(this.readSelectorState));
163165
this.writeTask = this.executorService.submit(new WriteLoop(this.writeSelectorState));
164166
}
165167
}
@@ -183,7 +185,6 @@ public void run() {
183185

184186
for (SelectionKey selectionKey : selector.keys()) {
185187
SocketChannelFrameHandlerState state = (SocketChannelFrameHandlerState) selectionKey.attachment();
186-
// FIXME connection should always be here
187188
if(state.getConnection().getHeartbeat() > 0) {
188189
long now = System.currentTimeMillis();
189190
if((now - state.getLastActivity()) > state.getConnection().getHeartbeat() * 1000 * 2) {
@@ -196,14 +197,6 @@ public void run() {
196197
}
197198
}
198199
}
199-
200-
// FIXME really necessary? key are supposed to be removed when channel is closed
201-
/*
202-
if(!selectionKey.channel().isOpen()) {
203-
LOGGER.warn("Channel for connection {} closed, removing it from IO thread", state.getConnection());
204-
selectionKey.cancel();
205-
}
206-
*/
207200
}
208201

209202
int select;
@@ -354,7 +347,7 @@ public void run() {
354347
buffer.put((byte) AMQP.PROTOCOL.MINOR);
355348
buffer.put((byte) AMQP.PROTOCOL.REVISION);
356349
buffer.flip();
357-
while(buffer.hasRemaining() && channel.write(buffer) != 0);
350+
while(buffer.hasRemaining() && channel.write(buffer) != -1);
358351
buffer.clear();
359352
state.setSendHeader(false);
360353
}

src/test/java/com/rabbitmq/examples/PerfTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public static void main(String[] args) {
9191
factory.setUri(uri);
9292
factory.setRequestedFrameMax(frameMax);
9393
factory.setRequestedHeartbeat(heartbeat);
94-
factory.setNio(true);
9594

9695
MulticastParams p = new MulticastParams();
9796
p.setAutoAck( autoAck);

0 commit comments

Comments
 (0)