SlideShare a Scribd company logo
1 of 106
Download to read offline
Develop realtime and
distributed web
with Scala and Xitrum
Ngoc Dao
Saigon Xmas 2014
Hanoi New Year 2015
http://www.toptal.com/scala/why-should-i-learn-scala
http://cacm.acm.org/magazines/2014/4/173220-unifying-functional-and-object-
oriented-programming-with-scala/fulltext
Slides will be shared at:
http://www.slideshare.net/ngocdaothanh
This talk is long.
Please ask question immediately when you have one.
For questions/discussions after this talk, please post to:
https://www.facebook.com/groups/720666194693928
You can also post to scala-user group:
https://groups.google.com/d/forum/scala-user
About me
Working at Mobilus in Tokyo: http://mobilus.co.jp/
● Server side
● Android, iOS
Interests:
● Realtime and distributed systems
● Web frameworks
(have been written several for Erlang, Scala, Java)
● Big data, analytics (learning Apache Spark)
Open source:
● https://github.com/ngocdaothanh
● https://github.com/xitrum-framework
● https://github.com/sinetja
● https://github.com/netty
Scala@Japan
● Meetups: ~monthly (in Tokyo)
● Conferences: yearly
○ 2013:
http://scalamatsuri.org/2013/en/program/index.html
○ 2014:
http://scalamatsuri.org/en/program/index.html
http://scalamatsuri.org/en/unconference/index.html
Red Sand Dunes
Phan Thiet
About you
I guess you already know OOP.
Functional programming:
● How many of you have used Ruby?
(somewhat functional, popular)
● Have used a more functional language?
(Lisp, Haskell, Erlang, Clojure, F# etc.)
Scala looks like Java and runs on JVM. It’s convenient if
you already know Java:
● How many of you have used Java?
● Have used Scala?
● Why use Scala? Compare with Java, Ruby, Node.js etc.
● Books, sites
Getting started:
● Install Scala
● Ways to run Scala program: Hello World
Scala = OOP + functional:
● Learn Scala’s functional feature via collections
● Learn Scala’s OOP feature via the Animals exercise
Some tools:
● Development:
○ REPL (Read–Eval–Print Loop), SBT (Scala Build Tool)
○ IDEs: Eclipse, IntelliJ
● Production:
○ xitrum-package
○ Scalive
PART 1/5: Scala overview
● Web app ≈ normal app + routing
● Xitrum:
○ Compare with Scalatra, Lift, Play
○ Basic usage:
■ Add routes to the previous demos
■ respondXxx
○ Swagger UI, Swagger Codegen
○ Metrics
○ i18n
PART 2/5: Use Scala for web
● Compare with Node.js
● Future and future composition
● Actor model and Akka actor
↑ NEW programming paradigm
A language that doesn't change the way you
think about programming is not worth
learning.
○ Actor vs Thread
○ Actor vs Future
○ Some pitfalls
● Akka FSM
PART 3/5: Use Scala for concurrency
● Realtime web
● WebSocket, Socket.IO, SockJS
● Tictactoe web game
PART 4/5: Use Scala for realtime web
PART 5/5: Use Scala for distributed systems
Compare with Redis
Remoting:
● Akka remoting
Clustering:
● Akka clustering
● Glokka
● Hazelcast
Scale Tictactoe to multiple servers
● Why use Scala? Compare with Java, Ruby, Node.js etc.
● Books, sites
Getting started:
● Install Scala
● Ways to run Scala program: Hello World
Scala = OOP + functional:
● Learn Scala’s functional feature via collections
● Learn Scala’s OOP feature via the Animals exercise
Some tools:
● Development:
○ REPL (Read–Eval–Print Loop), SBT (Scala Build Tool)
○ IDEs: Eclipse, IntelliJ
● Production:
○ xitrum-package
○ Scalive
PART 1/5: Scala overview
● Trendy: Used by by Apple, Foursquare, Guardian, LinkedIn,
Netflix, Quora, Sony Pictures Entertainment, Twitter, UK Guardian
etc.
● Compare with Java, Ruby, Node.js etc.
● Language: ≈ Java + Ruby
○ Fast speed of Java + nice syntax of Ruby:
Faster than Ruby + syntax nicer than Java
○ Flexible:
■ Static + dynamic:
Compiled to Java .class or run as script like Ruby
■ OOP of Java + functional of Ruby
http://www.quora.com/Why-is-Swift-so-similar-to-Scala
● Not only a good language: Scala has toys
○ Ecosystem: Can reuse all Java libs
○ Concurrent/parallel: Future, Akka (≈ Erlang)
○ Big data: Apache Spark
Why use Scala?
Books, sites
● http://www.scala-lang.org/documentation/
● http://twitter.github.io/effectivescala/
● https://github.com/lauris/awesome-scala
● https://github.com/akullpp/awesome-java
● Search
Learn Scala “enough” to do projects
How much is “enough”?
Level A1:
Beginning application programmer
● Java-like statements and expressions:
standard operators, method calls,
conditionals, loops, try/catch
● class, object, def, val, var, import, package
● Infix notation for method calls
● Simple closures
● Collections with map, filter, etc
● for-expressions
http://www.scala-lang.org/old/node/8610
Level A2:
Intermediate application programmer
● Pattern matching
● Trait composition
● Recursion, in particular tail recursion
● XML literals
Level A3:
Expert application programmer
● Folds, i.e. methods such as foldLeft,
foldRight
● Streams and other lazy data structures
● Actors
● Combinator parsers
Level L1:
Junior library designer
● Type parameters
● Traits
● Lazy vals
● Control abstraction, currying
● By-name parameters
Level L2:
Senior library designer
● Variance annotations
● Existential types (e.g., to interface with Java
wildcards)
● Self type annotations and the cake pattern
for dependency injection
● Structural types (aka static duck typing)
● Defining map/flatmap/withFilter for new kinds
of for-expressions
● Extractors
Level L3:
Expert library designer
● Early initializers
● Abstract types
● Implicit definitions
● Higher-kinded types
A1 → A2/L1 → A3/L2 → L3
Install Scala
1. Download from
http://www.scala-lang.org/
2. Config PATH:
PATH=path/to/scala-2.11.4/bin:$PATH
REPL (Read–Eval–Print Loop) demo:
scala command
Ways to run Scala program
● println("Hello World")
● Run as script with scala
● Compile with scalac and run with scala
● Compile with scalac and run with java
SBT (Scala Build Tool)
http://www.scala-sbt.org/
● Dependency library manager + build tool
● Like “gem” + “rake” of Ruby
● Like Maven, Gradle
● Has plugins to generate project files for IDEs,
like Eclipse and IntelliJ
● Has plugins to collect and package .jar files,
ready to deploy to production environment
(Make, Ant are just build tools, not dependency library
managers)
Install SBT
1. Download from
http://www.scala-sbt.org/download.html
2. Config PATH:
PATH=path/to/sbt/bin/dir:$PATH
sbt:
java -Xms256M -Xmx512M
-jar `dirname $0`/sbt-launch-0.13.7.jar "$@"
Learn SBT:
http://www.scala-sbt.org/documentation.html
Simple SBT-based project structure
build.sbt
organization := "com.mycompany"
name := "hello"
version := "1.0"
scalaVersion := "2.11.4"
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked")
javacOptions ++= Seq("-source", "1.6", "-target", "1.6")
libraryDependencies += "tv.cntt" %% "xitrum" % "3.21"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.2"
Packaged .jar file:
hello_2.11-1.0.jar
$ sbt tasks
console Starts the Scala interpreter
compile Compiles sources
clean Deletes files produced by the build
run Runs a main class
package Produces project jar file
publish Publishes project jar file to a repository
publish-local Copies project jar file to ~/.ivy2
test Executes all tests
test-only Executes the tests provided as arguments
test-quick Executes the tests that either failed before
SBT plugins
http://www.scala-sbt.org/release/docs/Community-Plugins.html
Generate Eclipse project:
https://github.com/typesafehub/sbteclipse
Generate IntelliJ project:
https://github.com/mpeltonen/sbt-idea
Package project:
https://github.com/xitrum-framework/xitrum-package
Hello World demo
● sbt console
● sbt run
● sbt eclipse
● Run in Eclipse
● Debug in Eclipse
● sbt xitrum-package
● Run with java
● Add dependency library
http://search.maven.org/
● Scalive
Rules of thumb
Use dependency manager:
● Do not download dependency libraries
manually
● Do not commit dependency libraries
IDEs:
● Generate project files for IDEs
● Do not commit project files
Scala = OOP + functional
Unifying Object-Oriented and Functional Programming
http://web.stanford.edu/class/cs94si/OOPFP.pdf
Functional language
● Pass a function as an argument to another
function
=> Convenient syntax
f(123, g)
f(123, {
// ...
})
● Immutable data structures
=> Thread-safe
○ Tail recursion
Learn Scala’s functional feature via
collections
● From a collection, create another collection of same size
=> map
● From a collection, create another collection of larger size
=> flatMap
● From a collection, create another collection of smaller size
=> filter
● From a collection, create one element
=> foldLeft, foldRight, reduce
http://www.scala-lang.org/api/current/index.html#scala.collection.Seq
map
flatMap
filter
foldLeft
Roll
val a = 1
var b = 1
b = 2
val → immutable:
val c = Seq(1, 2, 3)
var → immutable:
var d = Seq(1, 2, 3)
d = Seq(4, 5, 6)
val → mutable:
val e = Array(1, 2, 3)
e(0) = 4
var → mutable:
var f = Array(1, 2, 3)
f = Array(4, 5, 6)
f(0) = 4
val VS var
immutable VS mutable collection
Order of preference (best practice):
● val
● var
● val → immutable: strictly functional
● var → immutable
● val → mutable
● var → mutable: do not use
Some languages only allow val → immutable
Scala is flexible:
var and mutable are OK to use in small, closed scope
For your curiosity: How to write
programs with only constants?
Example problem:
Without var, mutable:
● Generate a collection of positive numbers
that are <= n, and are multiple of 3 or 5.
gen(n: Int): Seq[Int]
● Calculate sum of all numbers in a collection.
sum(nums: Seq[Int]): Int
With var and mutable
import scala.collection.mutable.ArrayBuffer
def gen(n: Int): Seq[Int] = {
val buf = ArrayBuffer[Int]()
var i = 1
while (i <= n) {
if (i % 3 == 0 || i % 5 == 0)
buf.append(i)
i += 1
}
buf
}
def gen(n: Int): Seq[Int] = {
val nums = 1 to n
nums.filter { i =>
i % 3 == 0 || i % 5 == 0
}
}
def gen(n: Int): Seq[Int] = {
for {
i <- 1 to n
if (i % 3 == 0 || i % 5 == 0)
} yield i
}
Without var and mutable
● Use recursion to loop
● Optimize: Use tail recursion
○ Use accumulator
def gen(n: Int): Seq[Int] = {
// Stop condition
if (n < 3) return Seq()
// Recursion
if (n % 3 == 0 || n % 5 == 0)
gen(n - 1) :+ n
else
gen(n - 1)
}
Stackoverflow
if n is big enough
def genAcc(
n: Int, acc: Seq[Int]
): Seq[Int] = {
if (n < 3) return acc
// Tail recursion; Scala compiler will
// convert to “while” loop
if (n % 3 == 0 || n % 5 == 0)
genAcc(n - 1, n +: acc)
else
genAcc(n - 1, acc)
}
def gen(n: Int) = genAcc(n, Seq())
def genAcc(
n: Int, acc: Seq[Int]
): Seq[Int] = {
if (n < 3) return acc
if (n % 3 == 0 || n % 5 == 0)
genAcc(n - 1, n +: acc)
else
genAcc(n - 1, acc)
}
How to write programs with only
constants?
State is stored
at function arguments
State is set/changed
at function call
How I learn an OOP language:
● Learn basic syntax
● Learn collections
● Animals exercise:
abstraction, encapsulation,
inheritance, polymorphism
Learn Scala’s OOP feature via the
Animals exercise
Animals exercise
trait (interface) Animal
● name: String
● talk()
class Cat extends Animal
class Dog extends Animal
class Zoo
● addAnimal(a: Animal)
● talkAll()
scala-lang.org
→ /api/
Companion object
Class
Trait
http://youtu.be/GQxUEAXX_fE
How to read Scaladoc
● Web app ≈ normal app + routing
● Xitrum:
○ Compare with Scalatra, Lift, Play
○ Basic usage:
■ Add routes to the previous demos
■ respondXxx
○ Swagger UI, Swagger Codegen
○ i18n
PART 2/5: Use Scala for web
Web ≈ Routing
function
Input Output
function
Input Output
Web ≈ Routing
A web library/framework is not worth using if its routing feature sucks.
function
Request Response
function
ResponseRequest
Request
Request
Router
Xitrum
http://xitrum-framework.github.io/
Compare with Scalatra, Lift, Play
Demos:
https://github.com/xitrum-framework/xitrum-demos
Skeleton to create new project:
https://github.com/xitrum-framework/xitrum-new
● Basic usage:
○ Add routes to the previous demos
○ respondXxx
● Swagger UI, Swagger Codegen
● Metrics
● i18n
Xitrum
● Compare with Node.js
● Future and future composition
● Actor model and Akka actor
↑ NEW programming paradigm
A language that doesn't change the way you
think about programming is not worth
learning.
○ Actor vs Thread
○ Actor vs Future
○ Some pitfalls
● Akka FSM
PART 3/5: Use Scala for concurrency
Compare with Node.js
Node.js:
● Single thread => Single core
● Complicate to scale to multiple cores or multiple
servers; except for shared-nothing (non-realtime)
systems
● Callback hell
Scala:
● Multiple threads; immutable data structures, future, and
actor provide more safety for multithread programming
● Easy to scale
● No callback hell
Future
http://docs.scala-lang.org/overviews/core/futures.html
Think about Future as a thread pool with some
nice methods to:
● send tasks to it
● get results
● handle failures
● compose the above together
Future composition
f
f
f
f
f
f
f
f1
f2
f3
f
Think about Node.js callback hell!
● Future.sequence
● for comprehension
val taskParams = Seq(123, 456, 789)
val taskFutures: Seq[Future[String]] =
tasks.map { ms =>
future {
Thread.sleep(ms)
s"Result for $ms"
}
}
val gatheredFuture: Future[Seq[String]] =
Future.sequence(taskFutures)
val purchase = for {
usd <- future { con.getValue(USD) }
chf <- future { con.getValue(CHF) }
if isProfitable(usd, chf)
} yield connection.buy(amount, chf)
purchase onSuccess { amount =>
println("Purchased " + amount + " CHF")
}
↑ NEW programming paradigm
A language that doesn't change the way you
think about programming is not worth
learning.
Alan Perlis
(the first recipient of the Turing Award)
Actor model and Akka actor
Benefit of actor in one sentence
C vs Java:
You can use memory without having to release
memory manually.
Thread vs actor:
You can use concurrency without having to
create threads manually.
Don't communicate by sharing memory; share memory by
communicating.
Actor model
● Actor =
states +
mailbox +
behaviors (msg handlers)
● From outside, can’t manipulate actors directly.
● To interact with an actor, must send messages to it.
● Each actor has a mailbox, messages are put to mailbox,
and processed one by one. ← An actor is like a single
threaded process (each actor is like a Node.js process);
it doesn’t do more than one thing at a time.
http://www.cs.tsukuba.ac.jp/~yas/cs/csys-2013/2013-12-03/
Actor vs Thread
Thread:
● Heavy weight: Can only create not too many threads;
usually: 2000~5000
● Shared state ← Source of bugs
● Passive: Have to call object.method() to make the object
alive.
Actor:
● Light weight: Can create millions of actors;
usually: ~2.5 million actors/GB
● Self contained, shared nothing
● Active: Actors are alive by themselves. ← Easy to model
programs that have millions of on-going things (very high
level of concurrency), like MMOG games.
Actor vs Thread
● Thread: n dimensions, hard to reason about.
● Actor: 1D, one thing at a time.
var1
var1
Actor vs Thread
Just like JVM automatically manages memory
for you:
● Actor is a high level logical way to think, to
model programs.
● At lower level, actors run above a thread
pool.
Actor vs Future
Actor:
● Messaging
● Scheduling
● FSM
● Monitoring and supervision
● Location transparency
(actors on one server can send messages to actors on
another server)
=> Easier to scale out to multiple servers/clustering
Future:
● Syntax is easier to write
● Composable
● More typesafe
Akka http://akka.io/
(an implementation of the actor model)
Summary:
https://jraviton.wordpress.com/2015/01/16/lets-brush-up-on-scala-actors/
Demo: Counter
// First, define messages
object Counter {
case class Inc(amount: Int)
case class Dec(amount: Int)
}
import akka.actor.Actor
// Define actor state and message handlers
class Counter(name: String) extends Actor {
// Actor state
private var value = 0
...
...
import Counter._
// Message handlers
def receive = {
case Inc(amount) =>
value += amount
println(s"Value: $value")
case Dec(amount) =>
value -= amount
println(s"Value: $value")
}
}
import akka.actor.{ActorSystem, Props}
// Think of this as a thread pool
val system = ActorSystem("mysystem")
// Create actor reference (actor instance)
val c1 = system.actorOf(
Props(new Counter("mylock"))
)
// Send messages to the actor
c1 ! Counter.Inc(1)
c1 ! Counter.Dec(2)
Some pitfalls
Send mutable msgs between actors.
↑ May lead to bug, if actor A sends msg M to
actor B, state of B incorporates M, then M is
later changed by A.
=> Shared memory
Fix: Use immutable messages.
Some pitfalls
From inside actor:
anObject.foo(new Callback {
def onCallback() {
// Modify actor state directly
}
})
↑ May lead to bug, because the actor’s thread and the
callback’s thread may be 2 different threads. Remember:
An actor is like a single threaded process, can’t do more
than one thing at a time. An actor should be self contained,
shared nothing.
Fix: self ! msgFromCallback
Good read
● Concurrent Programming for Scalable Web
Architectures
http://berb.github.io/diploma-thesis/index.html
● Functions + Messages + Concurrency =
Erlang
http://www.infoq.com/presentations/joe-armstrong-
erlang-qcon08
● Akka doc
http://doc.akka.io/docs/akka/2.3.8/scala.html
Akka FSM
● FSM: Finite State Machine
● Implemented based on actors
● Very good for realtime multiplayer games, to
manage states of game sessions and inter-
player interactions
Example:
Code Lock
https://github.com/ngocdaothanh/code-lock-fsm-akka
● Realtime web
● WebSocket, Socket.IO, SockJS
● Tictactoe web game
PART 4/5: Use Scala for realtime web
HTTP problem:
Server can send data to clients only one time.
Some years ago:
Flash (open TCP socket connection to server)
Now:
WebSocket
https://developer.mozilla.org/en-
US/docs/WebSockets/Writing_WebSocket_clie
nt_applications
Realtime web ≈ server push
var sock = new WebSocket('ws://domain/path');
sock.onopen = function() {
console.log('onopen');
};
sock.onmessage = function(e) {
console.log('onmessage: ' + e.data);
sock.send(e.data);
};
sock.onclose = function() {
console.log('onclose');
};
Server can push data to
clients multiple times
WebSocket problem
New browsers are required:
● Internet Explorer: 10
● Firefox: 6
● Chrome: 4
● Safari: 5
● Opera: 12.10
WebSocket emulators
SockJS: WebSocket-like API
● JavaScript client:
https://github.com/sockjs/sockjs-client
● Protocol:
https://github.com/sockjs/sockjs-protocol
http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html
● Closer to WebSocket, much simpler than Socket.IO
=> Server side support for many languages
Socket.IO: More complicate built-in features, like rooms
● http://socket.io/
● Node.js
SockJS
● Provides WebSocket-like API
● Supports all browsers, e.g. IE 6
● Transports: websocket xhr-streaming xdr-
streaming iframe-eventsource iframe-
htmlfile xhr-polling xdr-polling iframe-xhr-
polling jsonp-polling
● Requires
○ Client side: sockjs.js
○ Server side: SockJS protocol
implementation
var sock = new WebSocket('ws:
//domain/path');
sock.onopen = function() {
};
sock.onmessage = function(e) {
sock.send(e.data);
};
sock.onclose = function() {
};
var sock = new SockJS('http:
//domain/path');
sock.onopen = function() {
};
sock.onmessage = function(e) {
sock.send(e.data);
};
sock.onclose = function() {
};
WebSocket vs SockJS
Tictactoe web game
https://github.com/xitrum-framework/xitrum-tictactoe
Tictactoe web game
Exercises:
● Instead of letting player actors send messages directly
to each other, use an intermediate game actor for each
game.
● Let users other than the players watch games.
● Use Scala.js to convert game logic code written in Scala
to JavaScript, to share game logic code between server
side and client side.
http://www.scala-js.org/
● Use Akka FSM instead of become.
Compare with Redis
Remoting:
● Akka remoting
Clustering:
● Akka clustering
● Glokka
● Hazelcast
Scale Tictactoe to multiple servers
PART 5/5: Use Scala for distributed systems
Compare with Redis
Redis:
● Separate process
● Single point of failure
Akka, Hazelcast:
● In-process
=> Faster, easier to use
● Redundancy, failover
Akka remoting
http://doc.akka.io/docs/akka/2.3.8/scala/remoting.html
Akka clustering
http://doc.akka.io/docs/akka/2.3.8/scala/cluster-usage.html
Glokka
https://github.com/xitrum-framework/glokka
A Scala library that allows you to register and
lookup actors by names in an Akka cluster.
Hazelcast
Program ≈ Code + Data
Distributed Program ≈ Distributed Code + Distributed Data
Akka ≈ Distributed Code
Hazelcast ≈ Distributed Data + Distributed Code
http://hazelcast.org/
http://hazelcast.com/
http://docs.hazelcast.org/docs/3.4/manual/html/
● Distributed data structures: Map, Multimap, Queue, Set,
List, Topic (pub/sub), Lock, AtomicLong,
AtomicReference, Semaphore, CountDownLatch,
IdGenerator
● JCache
● Distributed ExecutorService
● Transaction
● MapReduce, Aggregators
● Integration: Hibernate, Servlet session replication,
Spring
● Client: Java, C++, .NET, REST, memcache
Scale Tictactoe to multiple servers
Only need to change Lobby lookup
=> Use Glokka
Config Akka cluster:
config/akka.conf

More Related Content

What's hot

No Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with BootiqueNo Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with BootiqueAndrus Adamchik
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipseMike Slinn
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprisesMike Slinn
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using ScalaNgoc Dao
 
Search and analyze your data with elasticsearch
Search and analyze your data with elasticsearchSearch and analyze your data with elasticsearch
Search and analyze your data with elasticsearchAnton Udovychenko
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the WildTomer Gabel
 
Web development basics (Part-7)
Web development basics (Part-7)Web development basics (Part-7)
Web development basics (Part-7)Rajat Pratap Singh
 
RoR (Ruby on Rails)
RoR (Ruby on Rails)RoR (Ruby on Rails)
RoR (Ruby on Rails)scandiweb
 
Day 2 - Intro to Rails
Day 2 - Intro to RailsDay 2 - Intro to Rails
Day 2 - Intro to RailsBarry Jones
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildwebLeo Zhou
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to RubyBarry Jones
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Mike Slinn
 
Day 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureDay 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureBarry Jones
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
Java EE revisits design patterns
Java EE revisits design patterns Java EE revisits design patterns
Java EE revisits design patterns Alex Theedom
 
Apache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeApache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeAndrus Adamchik
 
Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)bryanbibat
 
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
[Blibli Brown Bag] Nodejs - The Other Side of Javascript[Blibli Brown Bag] Nodejs - The Other Side of Javascript
[Blibli Brown Bag] Nodejs - The Other Side of JavascriptIrfan Maulana
 

What's hot (20)

遇見 Ruby on Rails
遇見 Ruby on Rails遇見 Ruby on Rails
遇見 Ruby on Rails
 
No Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with BootiqueNo Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with Bootique
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
 
Search and analyze your data with elasticsearch
Search and analyze your data with elasticsearchSearch and analyze your data with elasticsearch
Search and analyze your data with elasticsearch
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
 
Day 8 - jRuby
Day 8 - jRubyDay 8 - jRuby
Day 8 - jRuby
 
Web development basics (Part-7)
Web development basics (Part-7)Web development basics (Part-7)
Web development basics (Part-7)
 
RoR (Ruby on Rails)
RoR (Ruby on Rails)RoR (Ruby on Rails)
RoR (Ruby on Rails)
 
Day 2 - Intro to Rails
Day 2 - Intro to RailsDay 2 - Intro to Rails
Day 2 - Intro to Rails
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0
 
Day 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureDay 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application Architecture
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
Java EE revisits design patterns
Java EE revisits design patterns Java EE revisits design patterns
Java EE revisits design patterns
 
Apache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeApache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM Alternative
 
Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)
 
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
[Blibli Brown Bag] Nodejs - The Other Side of Javascript[Blibli Brown Bag] Nodejs - The Other Side of Javascript
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
 

Similar to Learn Scala for realtime web with Xitrum

Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNManish Pandit
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark Summit
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScriptJorg Janke
 
Node.js Course 1 of 2 - Introduction and first steps
Node.js Course 1 of 2 - Introduction and first stepsNode.js Course 1 of 2 - Introduction and first steps
Node.js Course 1 of 2 - Introduction and first stepsManuel Eusebio de Paz Carmona
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistpmanvi
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsMiles Sabin
 
Scala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusScala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusBoldRadius Solutions
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Apache Spark Tutorial
Apache Spark TutorialApache Spark Tutorial
Apache Spark TutorialAhmet Bulut
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuHavoc Pennington
 
Spark + H20 = Machine Learning at scale
Spark + H20 = Machine Learning at scaleSpark + H20 = Machine Learning at scale
Spark + H20 = Machine Learning at scaleMateusz Dymczyk
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayLuka Zakrajšek
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scalascalaconfjp
 

Similar to Learn Scala for realtime web with Xitrum (20)

Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
Node.js Course 1 of 2 - Introduction and first steps
Node.js Course 1 of 2 - Introduction and first stepsNode.js Course 1 of 2 - Introduction and first steps
Node.js Course 1 of 2 - Introduction and first steps
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologist
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
 
Scala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusScala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadius
 
Scala Introduction
Scala IntroductionScala Introduction
Scala Introduction
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Apache Spark Tutorial
Apache Spark TutorialApache Spark Tutorial
Apache Spark Tutorial
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on Heroku
 
Spark + H20 = Machine Learning at scale
Spark + H20 = Machine Learning at scaleSpark + H20 = Machine Learning at scale
Spark + H20 = Machine Learning at scale
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
 
DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scala
 

More from Ngoc Dao

Model with actors and implement with Akka
Model with actors and implement with AkkaModel with actors and implement with Akka
Model with actors and implement with AkkaNgoc Dao
 
BIG DATA サービス と ツール
BIG DATA サービス と ツールBIG DATA サービス と ツール
BIG DATA サービス と ツールNgoc Dao
 
Actor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka FundamentalsActor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka FundamentalsNgoc Dao
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS IntroNgoc Dao
 
Easy distributed load test with Tsung
Easy distributed load test with TsungEasy distributed load test with Tsung
Easy distributed load test with TsungNgoc Dao
 
Cloud Erlang
Cloud ErlangCloud Erlang
Cloud ErlangNgoc Dao
 
Xitrum internals
Xitrum internalsXitrum internals
Xitrum internalsNgoc Dao
 
Những lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần applicationNhững lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần applicationNgoc Dao
 
Erlang Web
Erlang WebErlang Web
Erlang WebNgoc Dao
 
Nitrogen Web Framework
Nitrogen Web FrameworkNitrogen Web Framework
Nitrogen Web FrameworkNgoc Dao
 
スポイトができるまで
スポイトができるまでスポイトができるまで
スポイトができるまでNgoc Dao
 
Camellia General
Camellia GeneralCamellia General
Camellia GeneralNgoc Dao
 
Nhập môn BDD
Nhập môn BDDNhập môn BDD
Nhập môn BDDNgoc Dao
 
何でRuby
何でRuby何でRuby
何でRubyNgoc Dao
 
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua NgocSinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua NgocNgoc Dao
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua GSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua GNgoc Dao
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua NgocSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua NgocNgoc Dao
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua HungSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua HungNgoc Dao
 

More from Ngoc Dao (18)

Model with actors and implement with Akka
Model with actors and implement with AkkaModel with actors and implement with Akka
Model with actors and implement with Akka
 
BIG DATA サービス と ツール
BIG DATA サービス と ツールBIG DATA サービス と ツール
BIG DATA サービス と ツール
 
Actor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka FundamentalsActor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka Fundamentals
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
 
Easy distributed load test with Tsung
Easy distributed load test with TsungEasy distributed load test with Tsung
Easy distributed load test with Tsung
 
Cloud Erlang
Cloud ErlangCloud Erlang
Cloud Erlang
 
Xitrum internals
Xitrum internalsXitrum internals
Xitrum internals
 
Những lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần applicationNhững lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần application
 
Erlang Web
Erlang WebErlang Web
Erlang Web
 
Nitrogen Web Framework
Nitrogen Web FrameworkNitrogen Web Framework
Nitrogen Web Framework
 
スポイトができるまで
スポイトができるまでスポイトができるまで
スポイトができるまで
 
Camellia General
Camellia GeneralCamellia General
Camellia General
 
Nhập môn BDD
Nhập môn BDDNhập môn BDD
Nhập môn BDD
 
何でRuby
何でRuby何でRuby
何でRuby
 
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua NgocSinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua GSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua NgocSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua HungSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
 

Recently uploaded

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Learn Scala for realtime web with Xitrum

  • 1. Develop realtime and distributed web with Scala and Xitrum Ngoc Dao Saigon Xmas 2014 Hanoi New Year 2015
  • 3. Slides will be shared at: http://www.slideshare.net/ngocdaothanh This talk is long. Please ask question immediately when you have one. For questions/discussions after this talk, please post to: https://www.facebook.com/groups/720666194693928 You can also post to scala-user group: https://groups.google.com/d/forum/scala-user
  • 4. About me Working at Mobilus in Tokyo: http://mobilus.co.jp/ ● Server side ● Android, iOS Interests: ● Realtime and distributed systems ● Web frameworks (have been written several for Erlang, Scala, Java) ● Big data, analytics (learning Apache Spark) Open source: ● https://github.com/ngocdaothanh ● https://github.com/xitrum-framework ● https://github.com/sinetja ● https://github.com/netty
  • 5. Scala@Japan ● Meetups: ~monthly (in Tokyo) ● Conferences: yearly ○ 2013: http://scalamatsuri.org/2013/en/program/index.html ○ 2014: http://scalamatsuri.org/en/program/index.html http://scalamatsuri.org/en/unconference/index.html
  • 7. About you I guess you already know OOP. Functional programming: ● How many of you have used Ruby? (somewhat functional, popular) ● Have used a more functional language? (Lisp, Haskell, Erlang, Clojure, F# etc.) Scala looks like Java and runs on JVM. It’s convenient if you already know Java: ● How many of you have used Java? ● Have used Scala?
  • 8. ● Why use Scala? Compare with Java, Ruby, Node.js etc. ● Books, sites Getting started: ● Install Scala ● Ways to run Scala program: Hello World Scala = OOP + functional: ● Learn Scala’s functional feature via collections ● Learn Scala’s OOP feature via the Animals exercise Some tools: ● Development: ○ REPL (Read–Eval–Print Loop), SBT (Scala Build Tool) ○ IDEs: Eclipse, IntelliJ ● Production: ○ xitrum-package ○ Scalive PART 1/5: Scala overview
  • 9. ● Web app ≈ normal app + routing ● Xitrum: ○ Compare with Scalatra, Lift, Play ○ Basic usage: ■ Add routes to the previous demos ■ respondXxx ○ Swagger UI, Swagger Codegen ○ Metrics ○ i18n PART 2/5: Use Scala for web
  • 10. ● Compare with Node.js ● Future and future composition ● Actor model and Akka actor ↑ NEW programming paradigm A language that doesn't change the way you think about programming is not worth learning. ○ Actor vs Thread ○ Actor vs Future ○ Some pitfalls ● Akka FSM PART 3/5: Use Scala for concurrency
  • 11. ● Realtime web ● WebSocket, Socket.IO, SockJS ● Tictactoe web game PART 4/5: Use Scala for realtime web
  • 12. PART 5/5: Use Scala for distributed systems Compare with Redis Remoting: ● Akka remoting Clustering: ● Akka clustering ● Glokka ● Hazelcast Scale Tictactoe to multiple servers
  • 13.
  • 14. ● Why use Scala? Compare with Java, Ruby, Node.js etc. ● Books, sites Getting started: ● Install Scala ● Ways to run Scala program: Hello World Scala = OOP + functional: ● Learn Scala’s functional feature via collections ● Learn Scala’s OOP feature via the Animals exercise Some tools: ● Development: ○ REPL (Read–Eval–Print Loop), SBT (Scala Build Tool) ○ IDEs: Eclipse, IntelliJ ● Production: ○ xitrum-package ○ Scalive PART 1/5: Scala overview
  • 15. ● Trendy: Used by by Apple, Foursquare, Guardian, LinkedIn, Netflix, Quora, Sony Pictures Entertainment, Twitter, UK Guardian etc. ● Compare with Java, Ruby, Node.js etc. ● Language: ≈ Java + Ruby ○ Fast speed of Java + nice syntax of Ruby: Faster than Ruby + syntax nicer than Java ○ Flexible: ■ Static + dynamic: Compiled to Java .class or run as script like Ruby ■ OOP of Java + functional of Ruby http://www.quora.com/Why-is-Swift-so-similar-to-Scala ● Not only a good language: Scala has toys ○ Ecosystem: Can reuse all Java libs ○ Concurrent/parallel: Future, Akka (≈ Erlang) ○ Big data: Apache Spark Why use Scala?
  • 16. Books, sites ● http://www.scala-lang.org/documentation/ ● http://twitter.github.io/effectivescala/ ● https://github.com/lauris/awesome-scala ● https://github.com/akullpp/awesome-java ● Search
  • 17. Learn Scala “enough” to do projects How much is “enough”?
  • 18. Level A1: Beginning application programmer ● Java-like statements and expressions: standard operators, method calls, conditionals, loops, try/catch ● class, object, def, val, var, import, package ● Infix notation for method calls ● Simple closures ● Collections with map, filter, etc ● for-expressions http://www.scala-lang.org/old/node/8610
  • 19. Level A2: Intermediate application programmer ● Pattern matching ● Trait composition ● Recursion, in particular tail recursion ● XML literals
  • 20. Level A3: Expert application programmer ● Folds, i.e. methods such as foldLeft, foldRight ● Streams and other lazy data structures ● Actors ● Combinator parsers
  • 21. Level L1: Junior library designer ● Type parameters ● Traits ● Lazy vals ● Control abstraction, currying ● By-name parameters
  • 22. Level L2: Senior library designer ● Variance annotations ● Existential types (e.g., to interface with Java wildcards) ● Self type annotations and the cake pattern for dependency injection ● Structural types (aka static duck typing) ● Defining map/flatmap/withFilter for new kinds of for-expressions ● Extractors
  • 23. Level L3: Expert library designer ● Early initializers ● Abstract types ● Implicit definitions ● Higher-kinded types A1 → A2/L1 → A3/L2 → L3
  • 24.
  • 25. Install Scala 1. Download from http://www.scala-lang.org/ 2. Config PATH: PATH=path/to/scala-2.11.4/bin:$PATH REPL (Read–Eval–Print Loop) demo: scala command
  • 26. Ways to run Scala program ● println("Hello World") ● Run as script with scala ● Compile with scalac and run with scala ● Compile with scalac and run with java
  • 27.
  • 28. SBT (Scala Build Tool) http://www.scala-sbt.org/ ● Dependency library manager + build tool ● Like “gem” + “rake” of Ruby ● Like Maven, Gradle ● Has plugins to generate project files for IDEs, like Eclipse and IntelliJ ● Has plugins to collect and package .jar files, ready to deploy to production environment (Make, Ant are just build tools, not dependency library managers)
  • 29. Install SBT 1. Download from http://www.scala-sbt.org/download.html 2. Config PATH: PATH=path/to/sbt/bin/dir:$PATH sbt: java -Xms256M -Xmx512M -jar `dirname $0`/sbt-launch-0.13.7.jar "$@" Learn SBT: http://www.scala-sbt.org/documentation.html
  • 31. build.sbt organization := "com.mycompany" name := "hello" version := "1.0" scalaVersion := "2.11.4" scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked") javacOptions ++= Seq("-source", "1.6", "-target", "1.6") libraryDependencies += "tv.cntt" %% "xitrum" % "3.21" libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.2" Packaged .jar file: hello_2.11-1.0.jar
  • 32. $ sbt tasks console Starts the Scala interpreter compile Compiles sources clean Deletes files produced by the build run Runs a main class package Produces project jar file publish Publishes project jar file to a repository publish-local Copies project jar file to ~/.ivy2 test Executes all tests test-only Executes the tests provided as arguments test-quick Executes the tests that either failed before
  • 33. SBT plugins http://www.scala-sbt.org/release/docs/Community-Plugins.html Generate Eclipse project: https://github.com/typesafehub/sbteclipse Generate IntelliJ project: https://github.com/mpeltonen/sbt-idea Package project: https://github.com/xitrum-framework/xitrum-package
  • 34. Hello World demo ● sbt console ● sbt run ● sbt eclipse ● Run in Eclipse ● Debug in Eclipse ● sbt xitrum-package ● Run with java ● Add dependency library http://search.maven.org/ ● Scalive
  • 35. Rules of thumb Use dependency manager: ● Do not download dependency libraries manually ● Do not commit dependency libraries IDEs: ● Generate project files for IDEs ● Do not commit project files
  • 36.
  • 37. Scala = OOP + functional Unifying Object-Oriented and Functional Programming http://web.stanford.edu/class/cs94si/OOPFP.pdf
  • 38. Functional language ● Pass a function as an argument to another function => Convenient syntax f(123, g) f(123, { // ... }) ● Immutable data structures => Thread-safe ○ Tail recursion
  • 39. Learn Scala’s functional feature via collections ● From a collection, create another collection of same size => map ● From a collection, create another collection of larger size => flatMap ● From a collection, create another collection of smaller size => filter ● From a collection, create one element => foldLeft, foldRight, reduce http://www.scala-lang.org/api/current/index.html#scala.collection.Seq
  • 40. map
  • 44. val a = 1 var b = 1 b = 2 val → immutable: val c = Seq(1, 2, 3) var → immutable: var d = Seq(1, 2, 3) d = Seq(4, 5, 6) val → mutable: val e = Array(1, 2, 3) e(0) = 4 var → mutable: var f = Array(1, 2, 3) f = Array(4, 5, 6) f(0) = 4
  • 45. val VS var immutable VS mutable collection Order of preference (best practice): ● val ● var ● val → immutable: strictly functional ● var → immutable ● val → mutable ● var → mutable: do not use Some languages only allow val → immutable Scala is flexible: var and mutable are OK to use in small, closed scope
  • 46. For your curiosity: How to write programs with only constants? Example problem: Without var, mutable: ● Generate a collection of positive numbers that are <= n, and are multiple of 3 or 5. gen(n: Int): Seq[Int] ● Calculate sum of all numbers in a collection. sum(nums: Seq[Int]): Int
  • 47. With var and mutable import scala.collection.mutable.ArrayBuffer def gen(n: Int): Seq[Int] = { val buf = ArrayBuffer[Int]() var i = 1 while (i <= n) { if (i % 3 == 0 || i % 5 == 0) buf.append(i) i += 1 } buf }
  • 48. def gen(n: Int): Seq[Int] = { val nums = 1 to n nums.filter { i => i % 3 == 0 || i % 5 == 0 } } def gen(n: Int): Seq[Int] = { for { i <- 1 to n if (i % 3 == 0 || i % 5 == 0) } yield i }
  • 49. Without var and mutable ● Use recursion to loop ● Optimize: Use tail recursion ○ Use accumulator
  • 50. def gen(n: Int): Seq[Int] = { // Stop condition if (n < 3) return Seq() // Recursion if (n % 3 == 0 || n % 5 == 0) gen(n - 1) :+ n else gen(n - 1) } Stackoverflow if n is big enough
  • 51. def genAcc( n: Int, acc: Seq[Int] ): Seq[Int] = { if (n < 3) return acc // Tail recursion; Scala compiler will // convert to “while” loop if (n % 3 == 0 || n % 5 == 0) genAcc(n - 1, n +: acc) else genAcc(n - 1, acc) } def gen(n: Int) = genAcc(n, Seq())
  • 52. def genAcc( n: Int, acc: Seq[Int] ): Seq[Int] = { if (n < 3) return acc if (n % 3 == 0 || n % 5 == 0) genAcc(n - 1, n +: acc) else genAcc(n - 1, acc) } How to write programs with only constants? State is stored at function arguments State is set/changed at function call
  • 53.
  • 54. How I learn an OOP language: ● Learn basic syntax ● Learn collections ● Animals exercise: abstraction, encapsulation, inheritance, polymorphism Learn Scala’s OOP feature via the Animals exercise
  • 55. Animals exercise trait (interface) Animal ● name: String ● talk() class Cat extends Animal class Dog extends Animal class Zoo ● addAnimal(a: Animal) ● talkAll()
  • 57.
  • 58. ● Web app ≈ normal app + routing ● Xitrum: ○ Compare with Scalatra, Lift, Play ○ Basic usage: ■ Add routes to the previous demos ■ respondXxx ○ Swagger UI, Swagger Codegen ○ i18n PART 2/5: Use Scala for web
  • 59. Web ≈ Routing function Input Output function Input Output
  • 60. Web ≈ Routing A web library/framework is not worth using if its routing feature sucks. function Request Response function ResponseRequest Request Request Router
  • 61. Xitrum http://xitrum-framework.github.io/ Compare with Scalatra, Lift, Play Demos: https://github.com/xitrum-framework/xitrum-demos Skeleton to create new project: https://github.com/xitrum-framework/xitrum-new
  • 62. ● Basic usage: ○ Add routes to the previous demos ○ respondXxx ● Swagger UI, Swagger Codegen ● Metrics ● i18n Xitrum
  • 63.
  • 64. ● Compare with Node.js ● Future and future composition ● Actor model and Akka actor ↑ NEW programming paradigm A language that doesn't change the way you think about programming is not worth learning. ○ Actor vs Thread ○ Actor vs Future ○ Some pitfalls ● Akka FSM PART 3/5: Use Scala for concurrency
  • 65. Compare with Node.js Node.js: ● Single thread => Single core ● Complicate to scale to multiple cores or multiple servers; except for shared-nothing (non-realtime) systems ● Callback hell Scala: ● Multiple threads; immutable data structures, future, and actor provide more safety for multithread programming ● Easy to scale ● No callback hell
  • 66. Future http://docs.scala-lang.org/overviews/core/futures.html Think about Future as a thread pool with some nice methods to: ● send tasks to it ● get results ● handle failures ● compose the above together
  • 67. Future composition f f f f f f f f1 f2 f3 f Think about Node.js callback hell! ● Future.sequence ● for comprehension
  • 68. val taskParams = Seq(123, 456, 789) val taskFutures: Seq[Future[String]] = tasks.map { ms => future { Thread.sleep(ms) s"Result for $ms" } } val gatheredFuture: Future[Seq[String]] = Future.sequence(taskFutures)
  • 69. val purchase = for { usd <- future { con.getValue(USD) } chf <- future { con.getValue(CHF) } if isProfitable(usd, chf) } yield connection.buy(amount, chf) purchase onSuccess { amount => println("Purchased " + amount + " CHF") }
  • 70.
  • 71. ↑ NEW programming paradigm A language that doesn't change the way you think about programming is not worth learning. Alan Perlis (the first recipient of the Turing Award) Actor model and Akka actor
  • 72. Benefit of actor in one sentence C vs Java: You can use memory without having to release memory manually. Thread vs actor: You can use concurrency without having to create threads manually. Don't communicate by sharing memory; share memory by communicating.
  • 73. Actor model ● Actor = states + mailbox + behaviors (msg handlers) ● From outside, can’t manipulate actors directly. ● To interact with an actor, must send messages to it. ● Each actor has a mailbox, messages are put to mailbox, and processed one by one. ← An actor is like a single threaded process (each actor is like a Node.js process); it doesn’t do more than one thing at a time. http://www.cs.tsukuba.ac.jp/~yas/cs/csys-2013/2013-12-03/
  • 74. Actor vs Thread Thread: ● Heavy weight: Can only create not too many threads; usually: 2000~5000 ● Shared state ← Source of bugs ● Passive: Have to call object.method() to make the object alive. Actor: ● Light weight: Can create millions of actors; usually: ~2.5 million actors/GB ● Self contained, shared nothing ● Active: Actors are alive by themselves. ← Easy to model programs that have millions of on-going things (very high level of concurrency), like MMOG games.
  • 75. Actor vs Thread ● Thread: n dimensions, hard to reason about. ● Actor: 1D, one thing at a time. var1 var1
  • 76. Actor vs Thread Just like JVM automatically manages memory for you: ● Actor is a high level logical way to think, to model programs. ● At lower level, actors run above a thread pool.
  • 77. Actor vs Future Actor: ● Messaging ● Scheduling ● FSM ● Monitoring and supervision ● Location transparency (actors on one server can send messages to actors on another server) => Easier to scale out to multiple servers/clustering Future: ● Syntax is easier to write ● Composable ● More typesafe
  • 78. Akka http://akka.io/ (an implementation of the actor model) Summary: https://jraviton.wordpress.com/2015/01/16/lets-brush-up-on-scala-actors/
  • 79. Demo: Counter // First, define messages object Counter { case class Inc(amount: Int) case class Dec(amount: Int) }
  • 80. import akka.actor.Actor // Define actor state and message handlers class Counter(name: String) extends Actor { // Actor state private var value = 0 ...
  • 81. ... import Counter._ // Message handlers def receive = { case Inc(amount) => value += amount println(s"Value: $value") case Dec(amount) => value -= amount println(s"Value: $value") } }
  • 82. import akka.actor.{ActorSystem, Props} // Think of this as a thread pool val system = ActorSystem("mysystem") // Create actor reference (actor instance) val c1 = system.actorOf( Props(new Counter("mylock")) ) // Send messages to the actor c1 ! Counter.Inc(1) c1 ! Counter.Dec(2)
  • 83. Some pitfalls Send mutable msgs between actors. ↑ May lead to bug, if actor A sends msg M to actor B, state of B incorporates M, then M is later changed by A. => Shared memory Fix: Use immutable messages.
  • 84. Some pitfalls From inside actor: anObject.foo(new Callback { def onCallback() { // Modify actor state directly } }) ↑ May lead to bug, because the actor’s thread and the callback’s thread may be 2 different threads. Remember: An actor is like a single threaded process, can’t do more than one thing at a time. An actor should be self contained, shared nothing. Fix: self ! msgFromCallback
  • 85. Good read ● Concurrent Programming for Scalable Web Architectures http://berb.github.io/diploma-thesis/index.html ● Functions + Messages + Concurrency = Erlang http://www.infoq.com/presentations/joe-armstrong- erlang-qcon08 ● Akka doc http://doc.akka.io/docs/akka/2.3.8/scala.html
  • 86.
  • 87. Akka FSM ● FSM: Finite State Machine ● Implemented based on actors ● Very good for realtime multiplayer games, to manage states of game sessions and inter- player interactions Example: Code Lock https://github.com/ngocdaothanh/code-lock-fsm-akka
  • 88.
  • 89. ● Realtime web ● WebSocket, Socket.IO, SockJS ● Tictactoe web game PART 4/5: Use Scala for realtime web
  • 90. HTTP problem: Server can send data to clients only one time. Some years ago: Flash (open TCP socket connection to server) Now: WebSocket https://developer.mozilla.org/en- US/docs/WebSockets/Writing_WebSocket_clie nt_applications Realtime web ≈ server push
  • 91. var sock = new WebSocket('ws://domain/path'); sock.onopen = function() { console.log('onopen'); }; sock.onmessage = function(e) { console.log('onmessage: ' + e.data); sock.send(e.data); }; sock.onclose = function() { console.log('onclose'); }; Server can push data to clients multiple times
  • 92. WebSocket problem New browsers are required: ● Internet Explorer: 10 ● Firefox: 6 ● Chrome: 4 ● Safari: 5 ● Opera: 12.10
  • 93. WebSocket emulators SockJS: WebSocket-like API ● JavaScript client: https://github.com/sockjs/sockjs-client ● Protocol: https://github.com/sockjs/sockjs-protocol http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html ● Closer to WebSocket, much simpler than Socket.IO => Server side support for many languages Socket.IO: More complicate built-in features, like rooms ● http://socket.io/ ● Node.js
  • 94. SockJS ● Provides WebSocket-like API ● Supports all browsers, e.g. IE 6 ● Transports: websocket xhr-streaming xdr- streaming iframe-eventsource iframe- htmlfile xhr-polling xdr-polling iframe-xhr- polling jsonp-polling ● Requires ○ Client side: sockjs.js ○ Server side: SockJS protocol implementation
  • 95. var sock = new WebSocket('ws: //domain/path'); sock.onopen = function() { }; sock.onmessage = function(e) { sock.send(e.data); }; sock.onclose = function() { }; var sock = new SockJS('http: //domain/path'); sock.onopen = function() { }; sock.onmessage = function(e) { sock.send(e.data); }; sock.onclose = function() { }; WebSocket vs SockJS
  • 97. Tictactoe web game Exercises: ● Instead of letting player actors send messages directly to each other, use an intermediate game actor for each game. ● Let users other than the players watch games. ● Use Scala.js to convert game logic code written in Scala to JavaScript, to share game logic code between server side and client side. http://www.scala-js.org/ ● Use Akka FSM instead of become.
  • 98.
  • 99. Compare with Redis Remoting: ● Akka remoting Clustering: ● Akka clustering ● Glokka ● Hazelcast Scale Tictactoe to multiple servers PART 5/5: Use Scala for distributed systems
  • 100. Compare with Redis Redis: ● Separate process ● Single point of failure Akka, Hazelcast: ● In-process => Faster, easier to use ● Redundancy, failover
  • 103. Glokka https://github.com/xitrum-framework/glokka A Scala library that allows you to register and lookup actors by names in an Akka cluster.
  • 104. Hazelcast Program ≈ Code + Data Distributed Program ≈ Distributed Code + Distributed Data Akka ≈ Distributed Code Hazelcast ≈ Distributed Data + Distributed Code http://hazelcast.org/ http://hazelcast.com/
  • 105. http://docs.hazelcast.org/docs/3.4/manual/html/ ● Distributed data structures: Map, Multimap, Queue, Set, List, Topic (pub/sub), Lock, AtomicLong, AtomicReference, Semaphore, CountDownLatch, IdGenerator ● JCache ● Distributed ExecutorService ● Transaction ● MapReduce, Aggregators ● Integration: Hibernate, Servlet session replication, Spring ● Client: Java, C++, .NET, REST, memcache
  • 106. Scale Tictactoe to multiple servers Only need to change Lobby lookup => Use Glokka Config Akka cluster: config/akka.conf