Upload
nljug
View
227
Download
3
Tags:
Embed Size (px)
Citation preview
ABOUT MEConsultant Living in HamburgCo-Founder of 3 years Scala, 10 years Java background
@Typesafe
testmunk
Follow @markusjura Follow @markusjura 233 followers
ROUTESVERB PATH CONTROLLER_METHOD
GET / controllers.Application.index()GET /foo controllers.Application.foo()
Declarative, type-safe URL Mapping
ASYNCHRONOUS REQUESTimport play.libs.F.*;
private static Integer calc() { return (5134 * 5789) / 349;}
public static Promise<Result> basicPromise() { Promise<Integer> promise = Promise.promise(() -> calc()); return promise.map(i -> ok("Result is: " + i));}
HTTP REQUESTpublic static Promise<Result> getPage() { final Promise<WSResponse> promise = WS.url("http://google.com").get(); return promise.map(response -> ok(response.getBody()));}
CONCURRENT HTTP REQUESTSpublic static Promise<Result> composition() { final Promise<WSResponse> googlePromise = WS.url("http://google.com").get(); final Promise<WSResponse> twitterPromise = WS.url("http://twitter.com").get();
return googlePromise.flatMap(google -> twitterPromise.map(twitter -> ok(google.getBody() + twitter.getBody())));}
WEBSOCKETS CLIENT CODEws = new WebSocket("ws://url/echo")ws.onmessage = (event) -> alert(event.data)
ws.onopen = () -> ws.send("Echo")
CoffeeScript
WEBSOCKETS SERVER CODEpublic static WebSocket<JsonNode> echo() { return WebSocket.whenReady((in, out) -> { in.onMessage(out::write); in.onClose(() -> Logger.debug("Connection closed")); });}
Play Controller
Single unified programming model forSimpler concurrencySimpler distributionSimpler fault tolerance
SIMPLER CONCURRENCY
Actors let us write code in a single-threaded illusionNo locks, synchronized or other primitives needed
SIMPLER DISTRIBUTION
Everything in Akka is distributed by defaultAkka goes from remote to local by optimization
SIMPLER FAULT TOLERANCE
Akka decouples communication from failure handling:Supervisors handle failureCallers need not care (they can't anyway)
THANK YOUSlide Deck on Reactive Stocks
GithubActivator Template
Follow @markusjura Follow @markusjura 233 followers