-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
eric
committed
Jan 31, 2014
1 parent
7340c6e
commit 2ec6df5
Showing
7 changed files
with
119 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,36 @@ | ||
package actors | ||
|
||
import scala.collection.parallel.ParSet | ||
|
||
import play.api.libs.ws.WS | ||
import play.api.libs.iteratee.{ Iteratee, Enumerator, Concurrent } | ||
import play.api.libs.concurrent.Execution.Implicits._ | ||
|
||
import akka.actor.{Props, ActorRef, Actor} | ||
import akka.actor.{ Props, ActorRef, Actor } | ||
import akka.event.EventStream | ||
|
||
object MessageStream { | ||
|
||
case class Subscribe(actor: ActorRef) | ||
type Message = String | ||
|
||
case class Unsubscribe(actor: ActorRef) | ||
} | ||
case class Subscribe(actor: ActorRef) | ||
|
||
case class Unsubscribe(actor: ActorRef) | ||
|
||
class MessageStream extends Actor { | ||
case class Broadcast(message: Message) | ||
|
||
} | ||
|
||
import MessageStream._ | ||
class MessageStream(messages: List[MessageStream.Message]) extends Actor { | ||
|
||
type Message = String | ||
import MessageStream._ | ||
|
||
var subscribers = ParSet[ActorRef]() | ||
val eventStream = new EventStream | ||
|
||
val messages = Enumerator[Message]("The discarded bicycle pressures the rod.", "How does the definitive plaster honor an appointed scholar?", "A hollow parade tends a worthwhile deaf. Why can't the circle migrate?") | ||
|
||
val (streamEnumerator, streamChannel) = Concurrent.broadcast[Message] | ||
def receive = { | ||
|
||
streamEnumerator |>>> Iteratee.foreach[Message](m => subscribers.foreach(_ ! m)) | ||
case Subscribe(actor: ActorRef) => eventStream.subscribe(sender, classOf[SocketEndpoint.NewMessage]) | ||
|
||
def receive = { | ||
|
||
case Subscribe(actor: ActorRef) => subscribers = subscribers + actor | ||
case Unsubscribe(actor: ActorRef) => eventStream.unsubscribe(sender) | ||
|
||
case Unsubscribe(actor: ActorRef) => subscribers = subscribers - actor | ||
} | ||
case Broadcast(message: Message) => eventStream.publish(SocketEndpoint.NewMessage(message)) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package actors | ||
|
||
import play.api.libs.ws.WS | ||
import play.api.libs.iteratee.{ Iteratee, Enumerator, Concurrent } | ||
import play.api.libs.concurrent.Execution.Implicits._ | ||
|
||
import akka.actor.{ Props, ActorRef, Actor } | ||
import akka.event.EventStream | ||
|
||
object SocketEndpoint { | ||
|
||
case class NewMessage(message: MessageStream.Message) | ||
|
||
def props(out: Enumerator[MessageStream.Message]) = Props(classOf[SocketEndpoint], out) | ||
|
||
} | ||
|
||
class SocketEndpoint(out: Enumerator[MessageStream.Message]) extends Actor { | ||
|
||
import SocketEndpoint._ | ||
|
||
def receive = { | ||
|
||
case NewMessage(message: MessageStream.Message) => out >>> Enumerator(message) | ||
|
||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package actors | ||
|
||
import play.api.libs.ws.WS | ||
import play.api.libs.iteratee.{ Iteratee, Enumerator, Concurrent } | ||
import play.api.libs.concurrent.Execution.Implicits._ | ||
import play.api.Play.current | ||
|
||
import akka.actor.{ Props, ActorRef, Actor } | ||
import akka.event.EventStream | ||
|
||
object Supervisor { | ||
|
||
case class NewSocket(out: Enumerator[MessageStream.Message]) | ||
|
||
} | ||
|
||
class Supervisor extends Actor { | ||
|
||
import Supervisor._ | ||
|
||
var sockets = Set[ActorRef]() | ||
|
||
def receive = { | ||
|
||
case NewSocket(out: Enumerator[MessageStream.Message]) => { | ||
val newSocket = context.actorOf(SocketEndpoint.props(out)) | ||
|
||
sockets = sockets + newSocket | ||
} | ||
|
||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ libraryDependencies ++= Seq( | |
) | ||
|
||
play.Project.playScalaSettings | ||
|
||
scalariformSettings |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Actually keffiyeh retro master cleanse American Apparel blog, cray Banksy hoodie Thundercats High Life cred typewriter VHS. | ||
Lomo twee fanny pack Etsy, messenger bag meggings Blue Bottle readymade Pinterest. | ||
Hella fashion axe Banksy fap, wayfarers direct trade farm-to-table art party hoodie 3 wolf moon. | ||
Retro Etsy kitsch, Pinterest Vice Marfa American Apparel keffiyeh High Life Terry Richardson 8-bit slow-carb quinoa Austin roof party. | ||
Williamsburg Shoreditch pug Blue Bottle art party kogi, authentic food truck Carles shabby chic Portland banjo before they sold out seitan vinyl. | ||
Banh mi sustainable Vice pickled, organic disrupt ethnic gastropub butcher Thundercats. | ||
Ethical YOLO 8-bit, Brooklyn sartorial mustache artisan slow-carb. | ||
Tofu tattooed flannel locavore. | ||
Shabby chic sriracha gentrify Bushwick, mustache put a bird on it readymade synth fingerstache deep v meggings blog photo booth. | ||
Keffiyeh Portland pop-up, 3 wolf moon dreamcatcher fingerstache vegan 90's scenester Carles. | ||
Etsy ethical viral, aesthetic mumblecore gentrify pork belly pour-over. | ||
Occupy pickled post-ironic, hella Bushwick butcher you probably haven't heard of them gluten-free food truck craft beer paleo. | ||
PBR butcher Blue Bottle, twee small batch Tonx irony Cosby sweater mixtape fap cardigan sartorial. | ||
Bushwick retro sustainable squid, artisan next level ugh authentic lomo keffiyeh raw denim ethnic Pinterest Etsy. | ||
Hella mlkshk cardigan Wes Anderson, 3 wolf moon Marfa ugh before they sold out kale chips flexitarian sriracha retro gluten-free pour-over pork belly. | ||
Mixtape chillwave 90's butcher. | ||
Narwhal actually viral cornhole tote bag, typewriter Marfa. | ||
Swag VHS selvage chambray, single-origin coffee Tonx twee High Life gastropub cred Helvetica. | ||
Put a bird on it street art cornhole 3 wolf moon, Tumblr meggings mumblecore sriracha irony locavore umami hashtag pour-over fashion axe. | ||
DIY 90's Tonx, raw denim master cleanse Wes Anderson American Apparel Terry Richardson trust fund bespoke. | ||
Shoreditch typewriter semiotics whatever slow-carb. | ||
Sustainable food truck banjo meggings, semiotics single-origin coffee gluten-free Marfa asymmetrical Tumblr. | ||
You probably haven't heard of them Wes Anderson pork belly Bushwick butcher drinking vinegar. | ||
Chia drinking vinegar trust fund Brooklyn salvia. | ||
You probably haven't heard of them Brooklyn Carles Tonx Bushwick. | ||
Banjo umami High Life, lo-fi actually master cleanse PBR hella Pitchfork scenester letterpress. | ||
VHS trust fund Tonx, four loko organic fingerstache Bushwick Thundercats wayfarers actually drinking vinegar fixie tote bag 90's wolf. | ||
Readymade chia DIY keytar organic. |
This file contains 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