Skip to content

Commit a9f60e7

Browse files
author
Reinier Lamers
committed
also share HashedWheelTimer between clients
1 parent 929531b commit a9f60e7

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

src/main/scala/io/backchat/hookup/client.scala

+6-21
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,15 @@ object HookupClient {
136136
*/
137137
private final class HookupClientHost(val client: HookupClient)(implicit executionContext: ExecutionContext) extends HookupClientLike with BroadcastChannel with Connectable with Reconnectable {
138138

139+
import HookupClientHost._
140+
139141
private[this] val normalized = client.settings.uri.normalize()
140142
private[this] val tgt = if (normalized.getPath == null || normalized.getPath.trim().isEmpty) {
141143
new URI(normalized.getScheme, normalized.getAuthority, "/", normalized.getQuery, normalized.getFragment)
142144
} else normalized
143145

144-
private[this] val bootstrap = new ClientBootstrap(HookupClientHost.clientSocketChannelFactory)
146+
private[this] val bootstrap = new ClientBootstrap(clientSocketChannelFactory)
145147
private[this] var handshaker: WebSocketClientHandshaker = null
146-
private[this] val timer = new HashedWheelTimer()
147148
private[this] var channel: Channel = null
148149
private[this] var _isConnected: Promise[OperationResult] = Promise[OperationResult]()
149150
private[this] val buffer = client.settings.buffer
@@ -329,25 +330,7 @@ object HookupClient {
329330
}
330331

331332
disconnected.future onComplete {
332-
case _ {
333-
_isConnected = Promise[OperationResult]()
334-
try {
335-
if (!isReconnecting && bootstrap != null) {
336-
val thread = new Thread {
337-
override def run = {
338-
timer.stop.asScala foreach (_.cancel())
339-
}
340-
}
341-
thread.setDaemon(false)
342-
thread.start()
343-
thread.join()
344-
}
345-
} catch {
346-
case e: Throwable logger.error("error while closing the connection", e)
347-
} finally {
348-
if (!closing.isCompleted) closing.success(Success)
349-
}
350-
}
333+
_ if (!closing.isCompleted) closing.success(Success)
351334
}
352335

353336
closing.future
@@ -390,6 +373,8 @@ object HookupClient {
390373
object HookupClientHost {
391374
private lazy val clientSocketChannelFactory =
392375
new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())
376+
377+
private lazy val timer = new HashedWheelTimer
393378
}
394379

395380
/**

0 commit comments

Comments
 (0)