Skip to content

Commit

Permalink
[reactivemongo] Upgrade ReactiveMongo to 0.16.0 (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
cchantep committed Aug 4, 2018
1 parent a8cc52c commit d816096
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 70 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Expand Up @@ -39,6 +39,8 @@ crossScalaVersions in ThisBuild := Seq(
"2.10.7", "2.11.12", (scalaVersion in ThisBuild).value
)

resolvers in ThisBuild += Resolver.sonatypeRepo("snapshots")

//
val scalacPlugin = ScalacPlugin.project

Expand Down
9 changes: 4 additions & 5 deletions play-reactive-mongo/src/main/scala/PlayReactiveMongoDSL.scala
@@ -1,6 +1,6 @@
package acolyte.reactivemongo

import scala.concurrent.{ ExecutionContext, Future }
import scala.concurrent.{ Await, ExecutionContext, Future }

import reactivemongo.api.{ MongoConnection, MongoDriver }
import play.modules.reactivemongo.ReactiveMongoApi
Expand All @@ -11,6 +11,7 @@ object PlayReactiveMongoDSL {
* @param con the MongoDB connection
*/
def mongoApi(drv: MongoDriver, con: MongoConnection)(implicit ec: ExecutionContext): ReactiveMongoApi = new ReactiveMongoApi {
import scala.concurrent.duration._
import reactivemongo.api._, gridfs._
import reactivemongo.play.json._
import reactivemongo.play.json.collection._
Expand All @@ -23,9 +24,7 @@ object PlayReactiveMongoDSL {
def asyncGridFS: Future[GridFS[JSONSerializationPack.type]] =
database.map(GridFS[JSONSerializationPack.type](_))

@deprecated("Use [[database]]", "1.0.45")
def db: DefaultDB = connection.db("acolyte")

def gridFS = GridFS[JSONSerializationPack.type](db)
def gridFS = Await.result(
database.map(GridFS[JSONSerializationPack.type](_)), 10.seconds)
}
}
26 changes: 6 additions & 20 deletions project/ReactiveMongo.scala
Expand Up @@ -13,32 +13,14 @@ class ReactiveMongo(scalacPlugin: Project) { self =>
lazy val generatedClassDirectory = settingKey[File](
"Directory where classes get generated")

val reactiveMongoVer = "0.15.0"
val reactiveMongoVer = "0.16.0"

lazy val project =
Project(id = "reactive-mongo", base = file("reactive-mongo")).
settings(formatSettings).settings(
name := "reactive-mongo",
fork in Test := true,
javacOptions in Test ++= Seq("-Xlint:unchecked", "-Xlint:deprecation"),
/*scalacOptions ++= {
val v = (version in ThisBuild).value
val sv = (scalaVersion in ThisBuild).value
val b = (baseDirectory in (scalacPlugin, Compile)).value
val n = (name in (scalacPlugin, Compile)).value
val msv = {
if (sv startsWith "2.10") "2.10"
else if (sv startsWith "2.11") "2.11"
else if (sv startsWith "2.12") "2.12"
else sv
}
val td = b / "target" / s"scala-$msv"
val j = td / s"${n}_${msv}-$v.jar"
Seq("-feature", "-deprecation", s"-Xplugin:${j.getAbsolutePath}")
},*/
resolvers ++= reactiveResolvers,
libraryDependencies ++= Seq(
"org.reactivemongo" %% "reactivemongo" % reactiveMongoVer % "provided",
Expand Down Expand Up @@ -79,9 +61,13 @@ class ReactiveMongo(scalacPlugin: Project) { self =>
"2.5.13" -> "play25"
}

val playRmVer = reactiveMongoVer.span(_ != '-') match {
case (v, m) => s"${v}-${playVar}${m}"
}

Seq(
"com.typesafe.play" %% "play" % playVer % Provided,
"org.reactivemongo" %% "play2-reactivemongo" % s"${reactiveMongoVer}-${playVar}" % Provided,
"org.reactivemongo" %% "play2-reactivemongo" % playRmVer % Provided,
"org.specs2" %% "specs2-core" % specsVer.value % Test
)
}
Expand Down
14 changes: 9 additions & 5 deletions reactive-mongo/src/main/scala/Akka.scala
Expand Up @@ -7,6 +7,7 @@ import reactivemongo.bson.{ BSONArray, BSONDocument, BSONString, BSONValue }
import reactivemongo.io.netty.channel.{ ChannelId, DefaultChannelId }
import reactivemongo.core.actors.{
Close,
Closed,
ExpectingResponse,
CheckedWriteRequestExpectingResponse CheckedWriteRequestExResp,
PrimaryAvailable,
Expand All @@ -25,7 +26,7 @@ import reactivemongo.core.nodeset.ProtocolMetadata
private[reactivemongo] class Actor(handler: ConnectionHandler)
extends reactivemongo.core.actors.MongoDBSystem {

import reactivemongo.core.nodeset.{ Authenticate, ChannelFactory, Connection }
import reactivemongo.core.nodeset.{ Authenticate, Connection }

lazy val initialAuthenticates = Seq.empty[Authenticate]

Expand All @@ -39,7 +40,7 @@ private[reactivemongo] class Actor(handler: ConnectionHandler)

protected def sendAuthenticate(connection: Connection, authentication: Authenticate): Connection = connection

protected def newChannelFactory(effect: Unit): ChannelFactory =
protected def newChannelFactory(effect: Unit) =
reactivemongo.acolyte.channelFactory(supervisor, name, options)

private def handleWrite(chanId: ChannelId, op: WriteOp, req: Request): Option[Response] = Try(handler.writeHandler(chanId, op, req)) match {
Expand Down Expand Up @@ -147,10 +148,13 @@ private[reactivemongo] class Actor(handler: ConnectionHandler)
sender ! SetAvailable(ProtocolMetadata.Default)
}

case Close postStop()
case Close | Close(_) {
sender ! Closed
postStop()
}

case _ /*msg */
//println(s"message = $msg")
case msg
println(s"message = $msg")

//next forward msg
()
Expand Down
8 changes: 6 additions & 2 deletions reactive-mongo/src/main/scala/DriverManager.scala
Expand Up @@ -31,7 +31,7 @@ object DriverManager {
override lazy val toString = s"DriverManager(timeout = $timeout)"
}

implicit val Default: DriverManager = new Default(2.seconds)
implicit val Default: DriverManager = new Default(5.seconds)

def withTimeout(timeout: FiniteDuration): DriverManager =
new Default(timeout)
Expand Down Expand Up @@ -63,6 +63,9 @@ object ConnectionManager {
implicit object HandlerConnectionManager
extends ConnectionManager[ConnectionHandler] {

import scala.concurrent.Await
import scala.concurrent.duration._

def open(driver: MongoDriver, handler: ConnectionHandler) = {
val sys = driver.system
val actorRef = sys.actorOf(Props(classOf[Actor], handler))
Expand All @@ -75,10 +78,11 @@ object ConnectionManager {

/** Releases connection if necessary. */
def releaseIfNecessary(connection: MongoConnection): Boolean = try {
connection.close()
Await.result(connection.askClose()(10.seconds), 10.seconds)
true
} catch {
case e: Throwable
println("_here")
e.printStackTrace()
false
}
Expand Down
2 changes: 1 addition & 1 deletion reactive-mongo/src/main/scala/WithHandler.scala
@@ -1,6 +1,6 @@
package acolyte.reactivemongo

import scala.concurrent.{ ExecutionContext, Future }
import scala.concurrent.ExecutionContext

import reactivemongo.api.{ MongoConnection, MongoDriver }

Expand Down
2 changes: 1 addition & 1 deletion reactive-mongo/src/main/scala/WithResult.scala
@@ -1,6 +1,6 @@
package acolyte.reactivemongo

import scala.concurrent.{ ExecutionContext, Future }
import scala.concurrent.ExecutionContext

import reactivemongo.api.{ MongoConnection, MongoDriver }

Expand Down

0 comments on commit d816096

Please sign in to comment.