Skip to content

Wait until registering handler finished, see #37 #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/main/scala/io/vertx/asyncsql/Starter.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package io.vertx.asyncsql

import scala.annotation.implicitNotFound
import scala.concurrent.{ ExecutionContext, Promise }
import scala.concurrent.{ExecutionContext, Promise}

import org.vertx.scala.core.json.{ Json, JsonObject }
import org.vertx.scala.core.json.{Json, JsonObject}
import org.vertx.scala.platform.Verticle

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

import io.vertx.asyncsql.database.{ ConnectionHandler, MySqlConnectionHandler, PostgreSqlConnectionHandler }
import org.vertx.scala.core.FunctionConverters._
import io.vertx.asyncsql.database.{ConnectionHandler, MySqlConnectionHandler, PostgreSqlConnectionHandler}

import scala.util.{Try, Failure, Success}

class Starter extends Verticle {

Expand All @@ -31,11 +34,13 @@ class Starter extends Verticle {
case "postgresql" => new PostgreSqlConnectionHandler(this, configuration, maxPoolSize, transactionTimeout)
case "mysql" => new MySqlConnectionHandler(this, configuration, maxPoolSize, transactionTimeout)
}
vertx.eventBus.registerHandler(address, handler)

logger.info("Async database module for MySQL and PostgreSQL started with config " + configuration)

startedResult.success()
vertx.eventBus.registerHandler(address, handler, {
case Success(x) =>
logger.info("Async database module for MySQL and PostgreSQL started")
startedResult.success()
case Failure(x) =>
startedResult.failure(x)
}: Try[Void] => Unit)
} catch {
case ex: Throwable =>
logger.fatal("could not start async database module!", ex)
Expand All @@ -44,7 +49,12 @@ class Starter extends Verticle {
}

override def stop() {
Option(handler).map(_.close)
Option(handler).map(pool => pool.close() andThen {
case Success(x) =>
logger.info(s"Async database module for MySQL and PostgreSQL stopped completely on address ${container.config().getString("address")}")
case Failure(ex) =>
logger.warn(s"Async database module for MySQL and PostgreSQL failed to stop completely on address ${container.config().getString("address")}", ex)
})
}

private def getDatabaseType(config: JsonObject) = {
Expand Down