Skip to content

Commit 2ce017f

Browse files
author
dmitriy.grytsovets
committed
fixup! 1.7.0-SNAPSHOT
1 parent 454f465 commit 2ce017f

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/it/java/org/tarantool/TestTarantoolClient.java

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ public void run() {
5353
t.start();
5454
}
5555

56+
57+
@Override
58+
protected void configureThreads(String threadName) {
59+
super.configureThreads(threadName);
60+
reader.setDaemon(true);
61+
writer.setDaemon(true);
62+
}
63+
5664
@Override
5765
protected void reconnect(int retry, Throwable lastError) {
5866
if (s != null) {

src/main/java/org/tarantool/TarantoolClientImpl.java

+21-11
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ protected void connect(final SocketChannel channel) throws Exception {
146146
} finally {
147147
bufferLock.unlock();
148148
}
149+
150+
channel.configureBlocking(false);
151+
this.channel = channel;
152+
153+
startThreads(channel.getRemoteAddress().toString());
154+
}
155+
156+
protected void startThreads(String threadName) throws IOException, InterruptedException {
149157
final CountDownLatch init = new CountDownLatch(2);
150158
reader = new Thread(new Runnable() {
151159
@Override
@@ -162,18 +170,20 @@ public void run() {
162170
}
163171
});
164172

165-
channel.configureBlocking(false);
166-
this.channel = channel;
167173

168-
reader.setName("Tarantool " + channel.getRemoteAddress().toString() + " reader");
169-
writer.setName("Tarantool " + channel.getRemoteAddress().toString() + " writer");
170-
writer.setPriority(config.writerThreadPriority);
171-
reader.setPriority(config.readerThreadPriority);
174+
configureThreads(threadName);
172175
reader.start();
173176
writer.start();
174177
init.await();
175178
}
176179

180+
protected void configureThreads(String threadName) {
181+
reader.setName("Tarantool " + threadName + " reader");
182+
writer.setName("Tarantool " + threadName + " writer");
183+
writer.setPriority(config.writerThreadPriority);
184+
reader.setPriority(config.readerThreadPriority);
185+
}
186+
177187

178188
protected void auth(String username, final String password) throws Exception {
179189
final MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
@@ -324,7 +334,7 @@ protected void writeFully(SocketChannel channel, ByteBuffer buffer) throws IOExc
324334

325335
protected void readThread() {
326336
try {
327-
while (!Thread.interrupted()) {
337+
while (!Thread.currentThread().isInterrupted()) {
328338
try {
329339
long code;
330340
readPacket();
@@ -358,13 +368,13 @@ protected void readPacket() throws IOException {
358368

359369
protected void writeThread() {
360370
writerBuffer.clear();
361-
while (!Thread.interrupted()) {
371+
while (!Thread.currentThread().isInterrupted()) {
362372
try {
363373
bufferLock.lock();
364-
if (sharedBuffer.position() == 0) {
365-
bufferNotEmpty.await();
366-
}
367374
try {
375+
while (sharedBuffer.position() == 0) {
376+
bufferNotEmpty.await();
377+
}
368378
sharedBuffer.flip();
369379
writerBuffer.put(sharedBuffer);
370380
sharedBuffer.clear();

0 commit comments

Comments
 (0)