@@ -6,6 +6,7 @@ import akka.util.Timeout
6
6
import com .typesafe .config .ConfigFactory
7
7
import org .nullvector .ReactiveMongoDriver .QueryType .QueryType
8
8
import org .nullvector .ReactiveMongoDriver .{DatabaseProvider , QueryType }
9
+ import org .slf4j .{Logger , LoggerFactory }
9
10
import play .api .libs .json .{JsString , Json }
10
11
import reactivemongo .api .bson .BSONDocument
11
12
import reactivemongo .api .bson .collection .BSONCollection
@@ -33,16 +34,30 @@ object ReactiveMongoDriver extends ExtensionId[ReactiveMongoDriver] with Extensi
33
34
}
34
35
35
36
class ReactiveMongoDriver (system : ExtendedActorSystem ) extends Extension {
37
+ protected val logger : Logger = LoggerFactory .getLogger(getClass)
38
+
36
39
private val dispatcherName = " akka-persistence-reactivemongo-dispatcher"
37
40
protected implicit val dispatcher : ExecutionContext = system.dispatchers.lookup(dispatcherName)
38
41
private implicit val timeout : Timeout = Timeout (5 .seconds)
39
42
private val defaultProvider : DatabaseProvider = new DatabaseProvider {
40
43
private lazy val db : DB = {
41
44
val mongoUri = system.settings.config.getString(" akka-persistence-reactivemongo.mongo-uri" )
45
+ logger.info(" Connecting to {}" , mongoUri)
42
46
Await .result(
43
47
MongoConnection .fromString(mongoUri).flatMap { parsedUri =>
44
- val databaseName = parsedUri.db.getOrElse(throw new Exception (" Missing database name" ))
45
- AsyncDriver (system.settings.config).connect(parsedUri).flatMap(_.database(databaseName))
48
+ parsedUri.db match {
49
+ case Some (databaseName) =>
50
+ AsyncDriver (system.settings.config).connect(parsedUri).flatMap(_.database(databaseName))
51
+ .recover {
52
+ case throwable : Throwable =>
53
+ logger.error(throwable.getMessage, throwable)
54
+ throw throwable
55
+ }
56
+ case None =>
57
+ val exception = new IllegalStateException (s " Missing Database Name in $mongoUri" )
58
+ logger.error(exception.getMessage, exception)
59
+ throw exception
60
+ }
46
61
},
47
62
30 .seconds
48
63
)
@@ -96,11 +111,11 @@ class ReactiveMongoDriver(system: ExtendedActorSystem) extends Extension {
96
111
}
97
112
98
113
(extractValue(" mongodb.explain-all" ).map(_ => QueryType .All ) ::
99
- extractValue(" mongodb.explain-recovery" ).map(_ => QueryType .Recovery ) ::
100
- extractValue(" mongodb.explain-highest-seq" ).map(_ => QueryType .HighestSeq ) ::
101
- extractValue(" mongodb.explain-load-snapshot" ).map(_ => QueryType .LoadSnapshot ) ::
102
- extractValue(" mongodb.explain-events-by-tag" ).map(_ => QueryType .EventsByTag ) ::
103
- Nil ).flatten
114
+ extractValue(" mongodb.explain-recovery" ).map(_ => QueryType .Recovery ) ::
115
+ extractValue(" mongodb.explain-highest-seq" ).map(_ => QueryType .HighestSeq ) ::
116
+ extractValue(" mongodb.explain-load-snapshot" ).map(_ => QueryType .LoadSnapshot ) ::
117
+ extractValue(" mongodb.explain-events-by-tag" ).map(_ => QueryType .EventsByTag ) ::
118
+ Nil ).flatten
104
119
}
105
120
106
121
def explain (collection : BSONCollection )(queryType : QueryType .QueryType , queryBuilder : collection.QueryBuilder ) = {
@@ -114,7 +129,7 @@ class ReactiveMongoDriver(system: ExtendedActorSystem) extends Extension {
114
129
(queryType : QueryType .QueryType , stages : List [collection.PipelineOperator ], hint : Option [collection.Hint ]) = {
115
130
if (shoudExplain(queryType)) {
116
131
collection
117
- .aggregatorContext[BSONDocument ](stages,explain = true , hint = hint)
132
+ .aggregatorContext[BSONDocument ](stages, explain = true , hint = hint)
118
133
.prepared
119
134
.cursor
120
135
.collect[List ]()
0 commit comments