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
| XLNT.getBucket('mobile.endorsements.profilepromo', 'memberId:23', function(err, bucket) { | |
| if(bucket === 'action_promo') { | |
| // serve view based JSON for action_promo | |
| } else if(bucket === 'hero_promo') { | |
| // serve view based JSON for hero_promo | |
| } else { | |
| // no call to action | |
| } | |
| } |
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
| // Client A connects to the server and is assigned connectionIdA | |
| public Result listen() { | |
| return ok(EventSource.whenConnected(eventSource -> { | |
| String connectionId = UUID.randomUUID().toString(); | |
| // construct an Akka Actor with the new EventSource connection identified by a random connection identifier | |
| Akka.system().actorOf( | |
| ClientConnectionActor.props(connectionId, eventSource), | |
| connectionId); | |
| })); | |
| } |
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
| // User B sends a message to User A | |
| // We identify the Actor which manages the connection on which User A is connected (connectionIdA) | |
| ActorSelection actorSelection = Akka.system().actorSelection("akka://application/user/" + connectionIdA); | |
| // Send B's message to A's Actor | |
| actorSelection.tell(new ClientMessage(data), ActorRef.noSender()); |
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
| public class ClientConnectionActor extends UntypedActor { | |
| public static Props props(String connectionId, EventSource eventSource) { | |
| return Props.create(ClientConnectionActor.class, () -> new ClientConnectionActor(connectionId, eventSource)); | |
| } | |
| public void onReceive(Object msg) throws Exception { | |
| if (msg instanceof ClientMessage) { | |
| eventSource.send(event(Json.toJson(clientMessage))); | |
| } | |
| } |
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
| "Hashed wheel timer #11327" #27780 prio=5 os_prio=0 tid=0x00007f73a8bba000 nid=0x27f4 sleeping[0x00007f7329d23000] | |
| java.lang.Thread.State: TIMED_WAITING (sleeping) | |
| at java.lang.Thread.sleep(Native Method) | |
| at org.jboss.netty.util.HashedWheelTimer$Worker.waitForNextTick(HashedWheelTimer.java:445) | |
| at org.jboss.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:364) | |
| at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) | |
| at java.lang.Thread.run(Thread.java:745) |
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
| Source<EventSource.Event, ActorRef> actorRefPoweredEventSource = | |
| Source.actorRef(100, OverflowStrategy.fail()); |
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
| Pair<ActorRef, Source<EventSource.Event, NotUsed>> actorRefEventSourcePair = | |
| actorRefPoweredEventSource.preMaterialize(_materializer); | |
| ActorRef eventSourceActor = actorRefEventSourcePair.first(); | |
| Source<EventSource.Event, ?> eventSource = actorRefEventSourcePair.second(); |
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
| String connectionIdentifier = UUID.randomUUID().toString(); | |
| _actorSystem.actorOf( | |
| ClientConnection.getProps( | |
| connectionIdentifier, eventSourceActor, _actorSystem.getScheduler() | |
| ), | |
| connectionIdentifier | |
| ); |
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
| return ok().chunked(eventSource.via(EventSource.flow())).as(Http.MimeTypes.EVENT_STREAM); |
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
| _eventSourceActor.tell(event(Json.toJson(new ClientMessage(_connectionId, "heartbeat"))), getSelf()) |