Change to fix spurious stack trace on connection close, #34

This commit is contained in:
Gideon le Grange 2016-02-08 22:16:09 +02:00
parent c0e97f8138
commit 387da6e6cd
1 changed files with 15 additions and 6 deletions

View File

@ -14,6 +14,8 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.SocketFactory;
import me.legrange.mikrotik.ApiConnection;
import me.legrange.mikrotik.ApiConnectionException;
@ -199,18 +201,25 @@ public final class ApiConnectionImpl extends ApiConnection {
try {
String s = Util.decode(in);
if (s != null) {
queue.put(s);
put(s);
}
} catch (ApiDataException ex) {
put(ex);
} catch (ApiConnectionException ex) {
if (connected || !sock.isClosed()) {
put(ex);
}
}
}
}
private void put(Object data) {
try {
queue.put(ex);
} catch (InterruptedException ex2) {
}
} catch (ApiConnectionException | InterruptedException ex) {
ex.printStackTrace();
}
queue.put(data);
} catch (InterruptedException ex) {
}
}
private final LinkedBlockingQueue queue = new LinkedBlockingQueue(40);
}