Skip to content

Commit f5a97d4

Browse files
committed
Wait until registering handler finished, see #37 (comment)
Signed-off-by: Joern Bernhardt <[email protected]>
1 parent 422b9f4 commit f5a97d4

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/main/scala/io/vertx/asyncsql/Starter.scala

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package io.vertx.asyncsql
22

33
import scala.annotation.implicitNotFound
4-
import scala.concurrent.{ ExecutionContext, Promise }
4+
import scala.concurrent.{ExecutionContext, Promise}
55

6-
import org.vertx.scala.core.json.{ Json, JsonObject }
6+
import org.vertx.scala.core.json.{Json, JsonObject}
77
import org.vertx.scala.platform.Verticle
88

99
import com.github.mauricio.async.db.Configuration
1010

11-
import io.vertx.asyncsql.database.{ ConnectionHandler, MySqlConnectionHandler, PostgreSqlConnectionHandler }
11+
import org.vertx.scala.core.FunctionConverters._
12+
import io.vertx.asyncsql.database.{ConnectionHandler, MySqlConnectionHandler, PostgreSqlConnectionHandler}
13+
14+
import scala.util.{Try, Failure, Success}
1215

1316
class Starter extends Verticle {
1417

@@ -31,11 +34,13 @@ class Starter extends Verticle {
3134
case "postgresql" => new PostgreSqlConnectionHandler(this, configuration, maxPoolSize, transactionTimeout)
3235
case "mysql" => new MySqlConnectionHandler(this, configuration, maxPoolSize, transactionTimeout)
3336
}
34-
vertx.eventBus.registerHandler(address, handler)
35-
36-
logger.info("Async database module for MySQL and PostgreSQL started with config " + configuration)
37-
38-
startedResult.success()
37+
vertx.eventBus.registerHandler(address, handler, {
38+
case Success(x) =>
39+
logger.info("Async database module for MySQL and PostgreSQL started")
40+
startedResult.success()
41+
case Failure(x) =>
42+
startedResult.failure(x)
43+
}: Try[Void] => Unit)
3944
} catch {
4045
case ex: Throwable =>
4146
logger.fatal("could not start async database module!", ex)
@@ -44,7 +49,12 @@ class Starter extends Verticle {
4449
}
4550

4651
override def stop() {
47-
Option(handler).map(_.close)
52+
Option(handler).map(pool => pool.close() andThen {
53+
case Success(x) =>
54+
logger.info(s"Async database module for MySQL and PostgreSQL stopped completely on address ${container.config().getString("address")}")
55+
case Failure(ex) =>
56+
logger.warn(s"Async database module for MySQL and PostgreSQL failed to stop completely on address ${container.config().getString("address")}", ex)
57+
})
4858
}
4959

5060
private def getDatabaseType(config: JsonObject) = {

0 commit comments

Comments
 (0)