1
1
package io .vertx .asyncsql
2
2
3
3
import scala .annotation .implicitNotFound
4
- import scala .concurrent .{ ExecutionContext , Promise }
4
+ import scala .concurrent .{ExecutionContext , Promise }
5
5
6
- import org .vertx .scala .core .json .{ Json , JsonObject }
6
+ import org .vertx .scala .core .json .{Json , JsonObject }
7
7
import org .vertx .scala .platform .Verticle
8
8
9
9
import com .github .mauricio .async .db .Configuration
10
10
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 }
12
15
13
16
class Starter extends Verticle {
14
17
@@ -31,11 +34,13 @@ class Starter extends Verticle {
31
34
case " postgresql" => new PostgreSqlConnectionHandler (this , configuration, maxPoolSize, transactionTimeout)
32
35
case " mysql" => new MySqlConnectionHandler (this , configuration, maxPoolSize, transactionTimeout)
33
36
}
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 )
39
44
} catch {
40
45
case ex : Throwable =>
41
46
logger.fatal(" could not start async database module!" , ex)
@@ -44,7 +49,12 @@ class Starter extends Verticle {
44
49
}
45
50
46
51
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
+ })
48
58
}
49
59
50
60
private def getDatabaseType (config : JsonObject ) = {
0 commit comments