mirror of https://github.com/zlatinb/muwire
set flag before submitting to threadpool
parent
15c59b440f
commit
2e22369ce0
|
@ -1,5 +1,6 @@
|
||||||
package com.muwire.core.chat
|
package com.muwire.core.chat
|
||||||
|
|
||||||
|
import java.lang.System.Logger.Level
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.util.concurrent.Executor
|
import java.util.concurrent.Executor
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
@ -46,11 +47,11 @@ class ChatClient implements Closeable {
|
||||||
void connectIfNeeded() {
|
void connectIfNeeded() {
|
||||||
if (connection != null || connectInProgress || (System.currentTimeMillis() - lastRejectionTime < REJECTION_BACKOFF))
|
if (connection != null || connectInProgress || (System.currentTimeMillis() - lastRejectionTime < REJECTION_BACKOFF))
|
||||||
return
|
return
|
||||||
|
connectInProgress = true
|
||||||
CONNECTOR.execute({connect()})
|
CONNECTOR.execute({connect()})
|
||||||
}
|
}
|
||||||
|
|
||||||
private void connect() {
|
private void connect() {
|
||||||
connectInProgress = true
|
|
||||||
connectThread = Thread.currentThread()
|
connectThread = Thread.currentThread()
|
||||||
Endpoint endpoint = null
|
Endpoint endpoint = null
|
||||||
try {
|
try {
|
||||||
|
@ -94,6 +95,7 @@ class ChatClient implements Closeable {
|
||||||
eventBus.publish(new ChatConnectionEvent(status : ChatConnectionAttemptStatus.SUCCESSFUL, persona : host,
|
eventBus.publish(new ChatConnectionEvent(status : ChatConnectionAttemptStatus.SUCCESSFUL, persona : host,
|
||||||
connection : connection))
|
connection : connection))
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.log(java.util.logging.Level.WARNING, "connect failed", e)
|
||||||
eventBus.publish(new ChatConnectionEvent(status : ChatConnectionAttemptStatus.FAILED, persona : host))
|
eventBus.publish(new ChatConnectionEvent(status : ChatConnectionAttemptStatus.FAILED, persona : host))
|
||||||
if (endpoint != null) {
|
if (endpoint != null) {
|
||||||
try {endpoint.getOutputStream().close() } catch (IOException ignore) {}
|
try {endpoint.getOutputStream().close() } catch (IOException ignore) {}
|
||||||
|
|
Loading…
Reference in New Issue