This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trait BatchProcessingActor[T] extends ConcurrentTaskProcessingActor[Seq[T]] { _: Actor => | |
| final protected val minConcurrentTasks: Int = 1 | |
| final protected val maxConcurrentTasks: Int = 1 | |
| final protected def pullTasks(limit: Int): Future[Seq[Seq[T]]] = { | |
| if (limit == 1) nextBatch.map(Seq(_).filter(_.nonEmpty))(immediately) else Future.successful(Seq.empty) | |
| } | |
| final protected def processTasks(tasks: Seq[Seq[T]]): Map[Seq[T], Future[Unit]] = { | |
| tasks.map { batch => batch -> processBatch(batch) }.toMap | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected def nextBatch: Future[Seq[T]] | |
| protected def processBatch(batch: Seq[T]): Future[Unit] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private[this] var closing = false | |
| private[this] var pulling = 0 | |
| private[this] var processing = Set.empty[T] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected val minConcurrentTasks: Int | |
| protected val maxConcurrentTasks: Int | |
| protected def pullTasks(limit: Int): Future[Seq[T]] | |
| protected def processTasks(tasks: Seq[T]): Map[T, Future[Unit]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Global extends GlobalSettings { | |
| override def onStart(app: Application) { | |
| // ... | |
| registerToLoadBalancer() // ready to receive external traffic | |
| // ... | |
| } | |
| override def onStop(app: Application) { | |
| // ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // retrieve instance id using AWS instance metadata and Play! WS API | |
| val request = WS.url("http://169.254.169.254/latest/meta-data/instance-id") | |
| val instanceId = Await.result(request.get(), 1 minute).body // careful when blocking | |
| // set up AWS EC2 and ELB clients | |
| val EC2Client = new AmazonEC2Client | |
| val ELBClient = new AmazonElasticLoadBalancingClient | |
| val region = Region.getRegion(Regions.<your_region>) | |
| EC2Client.setRegion(region) | |
| ELBClient.setRegion(region) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| libraryDependencies += "com.kifi" %% "json-annotation" % "0.1" | |
| addCompilerPlugin("org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val q"object $obj extends ..$bases { ..$body }" = compDecl | |
| q""" | |
| object $obj extends ..$bases { | |
| ..$body | |
| $format | |
| } | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val format = fields.length match { | |
| case 0 => c.abort(c.enclosingPosition, "Cannot create json formatter for case class with no fields") | |
| case 1 => | |
| // Only one field, use the serializer for the field | |
| q""" | |
| implicit val jsonAnnotationFormat = { | |
| import play.api.libs.json._ | |
| Format( | |
| __.read[${fields.head.tpt}].map(s => ${className.toTermName}(s)), | |
| new Writes[$className] { def writes(o: $className) = Json.toJson(o.${fields.head.name}) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val (className, fields) = try { | |
| val q"case class $className(..$fields) extends ..$bases { ..$body }" = classDecl | |
| (className, fields) | |
| } catch { | |
| case _: MatchError => c.abort(c.enclosingPosition, "Annotation is only supported on case class") | |
| } |
NewerOlder