iterate

Broadcasting messages in Play Framework WebSockets

走远了吗. 提交于 2019-12-19 04:36:14
问题 I'm pushing messages in Play Framework WebSockets using Concurrent.unicast[JsValue] , and I want to optimize sending the same message to multiple users. Is it possible to broadcast message using somehow multiple Concurrent.Channel ? 回答1: Short answer Maintain separate channel for each user and have groups associated with users Long answer package controllers import akka.actor.Actor import play.api.libs.iteratee.Enumerator import play.api.libs.iteratee.Concurrent.Channel import play.api.libs

Using Iteratees and Enumerators in Play Scala to Stream Data to S3

一世执手 提交于 2019-12-19 03:26:06
问题 I am building a Play Framework application in Scala where I would like to stream an array of bytes to S3. I am using the Play-S3 library to do this. The "Multipart file upload" of the documentation section is what's relevant here: // Retrieve an upload ticket val result:Future[BucketFileUploadTicket] = bucket initiateMultipartUpload BucketFile(fileName, mimeType) // Upload the parts and save the tickets val result:Future[BucketFilePartUploadTicket] = bucket uploadPart (uploadTicket,

Play 2.x : Reactive file upload with Iteratees

隐身守侯 提交于 2019-12-17 15:15:30
问题 I will start with the question: How to use Scala API's Iteratee to upload a file to the cloud storage (Azure Blob Storage in my case, but I don't think it's most important now) Background: I need to chunk the input into blocks of about 1 MB for storing large media files (300 MB+) as an Azure's BlockBlobs . Unfortunately, my Scala knowledge is still poor (my project is Java based and the only use for Scala in it will be an Upload controller). I tried with this code: Why makes calling error or

Scala: Getting original iteratee after applying enumeratee (example from play documentation doesn't compile)

a 夏天 提交于 2019-12-13 20:43:20
问题 I want to apply an enumeratee to an iteratee and afterwards get the original iteratee back, so I can apply further stuff. There is an example in the play documentation which uses an Iteratee[Int,Int] that just sums up its input (http://www.playframework.org/documentation/2.0.1/Enumeratees). Then they use an Enumeratee[String,Int] that allows strings like "3" and "6" as input. The example is as follows: val sum:Iteratee[Int,Int] = Iteratee.fold[Int,Int](0){ (s,e) => s + e } //create am

How to merge 2 Enumerators in one, based on merge rule

旧时模样 提交于 2019-12-10 21:57:24
问题 We have a small Scala project on Playframework. I'm trying to do everything reactive, and stumbled on a problem. I have two Enumerator[A] instances, representing values from a DB ordered by date. I need to return them as a single Enumerator[A] keeping date ordering. I have not found any solution for that in Enumerator[A], so I'm accumulating A's in single collection, and ordering them afterwards. case class A( created: Date, data: String ) val as: Enumerator[A] = findByAOrderedByCreated() val

Scalaz 7 Iteratee to process large zip file (OutOfMemoryError)

随声附和 提交于 2019-12-09 18:20:25
问题 I'm trying to use the scalaz iteratee package to process a large zip file in constant space. I have a long-running process I need to perform on each file in the zip file. Those processes can (and should) be run in parallel. I created an EnumeratorT that inflates each ZipEntry into a File object. The signature looks like: def enumZipFile(f:File):EnumeratorT[IoExceptionOr[IO[File]], IO] I want to attach an IterateeT that will perform the long-running process on each file. I basically end up

How to understand `Iteratee` in play2?

社会主义新天地 提交于 2019-12-09 05:32:50
问题 There's a package play.api.libs.iteratee in play2, which has a big object Iteratee which has more than 1000 lines. Why play2 need such a big object and how to understand it? 回答1: I just wrote an article trying to explain the concepts of Iteratees provided by Play2 for those who try to discover them. http://mandubian.com/2012/08/27/understanding-play2-iteratees-for-normal-humans/ Here is the conclusion of the article because it appears I must put essential parts to answer your question. But my

scala iteratee to recursively process files and subdirectories

夙愿已清 提交于 2019-12-08 07:31:21
问题 I want to apply a function for every file in a directory and subdirectories, as follows: def applyRecursively(dir: String, fn: (File) => Any) { def listAndProcess(dir: File) { dir.listFiles match { case null => out.println("exception: dir cannot be listed: " + dir.getPath); List[File]() case files => files.toList.sortBy(_.getName).foreach(file => { fn(file) if (!java.nio.file.Files.isSymbolicLink(file.toPath) && file.isDirectory) listAndProcess(file) }) } } listAndProcess(new File(dir)) } def

Asynchronous iteratee processing in Scalaz

左心房为你撑大大i 提交于 2019-12-07 03:22:35
问题 I've been using Scalaz 7 iteratees to process a large (i.e., unbounded) stream of data in constant heap space. In code, it looks something like this: type ErrorOrT[M[+_], A] = EitherT[M, Throwable, A] type ErrorOr[A] = ErrorOrT[IO, A] def processChunk(c: Chunk): Result def process(data: EnumeratorT[Chunk, ErrorOr]): IterateeT[Chunk, ErrorOr, List[Result]] = Iteratee.fold[Chunk, ErrorOr, List[Result]](Nil) { (rs, c) => processChunk(c) :: rs } &= data Now I'd like to perform the processing in

Creating an Enumeratee from a stateful algorithm

≯℡__Kan透↙ 提交于 2019-12-06 13:38:38
I have a stateful algorithm that incrementally takes input and incrementally produces output. The inputs and outputs are unrelated in number; i.e. an input may produce zero or more outputs. I am attempting to turn it into an Enumeratee in the Play Framework, but I am having difficulty getting started. My algorithm has local mutable state and synchronous operations and looks something like this var state = 'foo var i = input() while (i != null) { if (state == 'foo && i >= 0) { // 2 outputs, and change state output(i - 2) output(i * 3) state = 'bar } else if (state == 'foo) { // error error(