SlideShare ist ein Scribd-Unternehmen logo
1 von 40
3 juin 2014 1
Scala and OT
Seeing what is Seen
Leo Bufi Barrameda, Jose Paulo Santiago
May 27, 2014
3 juin 2014 2
• Software Engineer in OT (Oberthur)
• Software Enthusiast
• Working with Scala for 3 years
• Sexiest Programmer (Usually Code wearing
underwear)
About Me
3 juin 2014 3
3 juin 2014 3
3 juin 2014 4
About You Guys
•___ % of Java Developers
•___ % of Ruby Developers
•___ % of PHP Developers
•___ % of .Net Developers
•___ % of Scala Developers
•100% Scala Enthusiast
Java
Ruby
PHP.Net
Scala
Scala Enthusiast
Scala
Developers
June 3, 2014 6
About OT
• The Company
• 1842 – Oberthur Printing Company
• 1984 – Oberthur Technologies
(Secure Printing)
• 2003 – Oberthur Philippines
• 2011 – Acquisition by Advent
International
• Employees
• 6000+ Worldwide
• 200+ in the Philippines
• Customers:
• Telecommunications
• Banks
• Transport
• Governments
• My Personal Experience
• 
Vision: To be the best secure technology company in the world
June 3, 2014 7
About OT – Showcase of Product
June 3, 2014 8
About OT – Showcase of Product in Philippines
3 juin 2014 9
3 juin 2014 10
OT Objectives
• To create a Scalable Applications that can handle millions of transaction per
day.
• To create a multi-tenancy Applications in which every client will have
different procedures and different hardware set up.
• To make a scalable development procedure to scale with the number of
people, number of project.
• Application can run any number of customer on any topology.
3 juin 2014 10
3 juin 2014 11
To Achieve this Goal:
3 juin 2014 12
Scala (SCAlable Language)
• A language that run on JVM
• A programming language that combines the OOP and Functional concepts.
• As an India Guy said, Scala is Java having all the items on the Effective in
Java book + Functional Concepts.
JVM
Converted into ByteCode
SCALA
OOP with Effective in Java ON
Functional Concept
3 juin 2014 13
Why Scala?
• Seamless Java Interop
• Can use the rich existing Java Library.
JVM
SCALA BYTE
CODE
JAVA BYTE
CODE
Calls
Calls
3 juin 2014 14
Seamless Java Interop
• Use Existing Builders like maven and ant
• But why use maven and ant, there is sbt (simple build tool).
• This can use maven repository.
• Don’t use xml, you will use scala to build/define a scala project
object Demo extends Build {
val buildSettings = Defaults.defaultSettings ++ Seq(
organization := "com.demo",
version := "2.0.29",
scalaVersion := "2.9.0-1")
val scalatest = "org.scalatest" % "scalatest_2.9.0" % "1.4.1" % "test"
val commonDeps = Seq(scalatest)
lazy val project = Project(
"demo",
file("."),
settings = buildSettings ++ Seq(libraryDependencies ++= commonDeps))
}
3 juin 2014 15
object BuildSettings { ... }
object Resolvers { ... }
object Dependencies { ...}
object Publishing { ... }
object DemoBuild extends Build {
import BuildSettings._
import Dependencies._
import Publishing._
lazy val root = Project("demo", file("."),
settings =
Project.defaultSettings ++
commonDeps)
.aggregate(subProject1, subProject2)
...
}
3 juin 2014 16
3 juin 2014 17
Why Scala? - Type Inference
• val num = 1 //number is Int
• val hello = "Hello " //helloWorld is String
• Less Boilerplate: Let the type system figure out the type you want.
• Scala is a strongly type language but due to Type Inference it seems not
implicit def makeInteger(value: String) = value.toInt
math.max("500", 200)
implicit class MakeInteger(e: String) {
def makeInteger: Int = e.toInt
}
"500".makeInteger
3 juin 2014 18
Why Scala? - Concurrency and Distribution
• Has Future Support
val compute = future {
Math.PI * 123
}
compute onComplete {
case Success(result) => result
case Failure(exception) => exception
}
3 juin 2014 19
Why Scala? – Future Support
Don’t Wait, REACT!
• Using Future, there will be no non-blocking process. No waiting! What you
need is to REACT once the concrete value/exception is returned.
• Same Principle for Actors/Akka
3 juin 2014 20
Concurrency and Distribution
• Everything is immutable (should be)
• Useful in concurrent applications, can’t be corrupted by thread interference
• All Messages in Akka are immutable (message then to jump from one thread to
other)
• How to use it:
• use val instead of var
• use case class instead of class
3 juin 2014 21
Why Scala? - Traits
• Somewhat similar to interface but can define concrete method definition
• Resolve problem with multiple inheritance by making the evaluation linear.
• Can be use on class instance
3 juin 2014 22
trait Professional {
val name : String
def resume
}
trait SoftwareDev extends Professional {
override def resume = println("Dev : " + name)
}
trait Engineer extends Professional {
override def resume = println("Engineer : " + name)
}
class FreshGraduate(val name: String)
extends SoftwareDev with Engineer
new FreshGraduate("Leiz").resume
//this will print Engineer : Leiz
3 juin 2014 23
Why Scala? – Pattern Matching
• You can make decision construction base on type, value and construct
someValue match {
case Some(s : String) => s
case Some(i : Int) => i
case None => None
case _ =>
}
3 juin 2014 24
Why Scala? – Pattern Matching
• This combine with Partial Function is all awesomeness 
def authenticate: PartialFunction[Any, Any] = {
case Authenticate(user, body) => ....
Body(authorize, body)
}
def body: PartialFunction[Any, Any] = {
case Body(true, body) => //do if authenticated
case Body(false, _) => //do when not authenticated
}
def closeSession: PartialFunction[Any, Any] = {
case Close(user, body) => //process to close the session
Body(successful, body)
}
(authenticate andThen body) orElse (body) orElse (closeSession andThen body)
3 juin 2014 25
Why Scala? – High Order Function
• Function is a first class citizen, you can pass it as parameter, assign it to a
variable etc.
• With this, you can just define behaviour making things more declarative
rather procedural.
def recursion(value: Int, method: Int => Int,
condition: Int => Boolean): Int = condition(value) match {
case true => value
case false => recursion(method(value), method, condition)
}
recursion(0, (i: Int) => i + 7, (i: Int) => i >= 2)
Dispatcher
3 juin 2014 26
Akka
• Very lightweight concurrent entities.
• Immutable Event Driven Model similar to Erlang
• Designing the software is easy: Actor present a Doer or Process Box and
Message as the Intent
ActorRef MailBox
Actor
Invoke Message Put it on the Message Queue
ConsumeMessage
object DemoActor {
def props(magicNumber: Int): Props = Props(new
DemoActor(magicNumber)).withDispatcher("demo-dispatcher")
}
class DemoActor(var magicNumber: Int) extends Actor {
def receive = {
case x: Int =>
magicNumber = magicNumber - 1;
sender ! (x + magicNumber)
}
}
3 juin 2014 28
Why Akka? How we Use it in OT
• Easy Concurrency
• Event/Message-Based Driven System
o Single Execution Flow model
o No Shared mutuble state
o Loose Coupling – behavior is isolated within an actor
o Easy to Test – due to it’s isolated behavior
3 juin 2014 29
Why Akka? How we Use it in OT
• Scaling is easy
• You can scale via configuration
o Dispatchers
demo-dispatcher {
type = Dispatcher
executor = "thread-pool-executor"
thread-pool-executor {
core-pool-size-min = 2
core-pool-size-factor = 2.0
core-pool-size-max = 5
}
throughput = 5
}
3 juin 2014 30
Why Akka? How we Use it in OT
• Scaling is easy
• Router
/demo-actor {
router = round-robin
nr-of-instances = 100
}
STM
3 juin 2014 31
Why Akka? How we Use it in OT
• Software Transactional Memory (STM)
• Haven’t use it directly, it is wrap in Activate Framework
• Less Database access more interaction to memory. All transaction is commited
first on memory before on database.
Application Memory DiskCommits
Commits
Asyncly
3 juin 2014 32
Things we haven’t explore but will do in the future
• Akka Clustering
• We are ambitious, we want to horizontally scale and do redundancy to achieve
zero downtime.
Any Hardware Platform (OS)
3 juin 2014 33
Docker
• Encapsulate your application, which make it runnable with any hardware
environment configuration
• With this we can have the same set up on our dev laptop with our
production env
Docker
Application/Component
3 juin 2014 34
Docker – Useful Commands
• docker pull <image_name>
• docker pull ubuntu
o This will download an image named ubuntu
• docker run <image_name> <command>
• docker run ubuntu apt-get install -y mysql-server
o You had install a mysql server on your base image, Your change have been kept but
are not yet saved.
• docker commit <container_id> <image_name>
• docker commit 67a8d234328342 ubuntu_mysql
o This will create an image base on the current state of container specified
3 juin 2014 35
Docker – Dockerfile
FROM ubuntu
RUN docker run ubuntu apt-get install -y mysql-server
EXPOSE 3306
ENTRYPOINT service mysql start
3 juin 2014 36
Docker – With This:
• Don’t need any IT person to set up a server just to do component testing
• Component, Integration Testing Automation like Crazy 
Git REPO
JENKINS
BUILD
TEST
PUBLISH
DOCKER
APPLICATION
DATABASE
MOCKS
3 juin 2014 37
How Scala, Akka, Docker help OT achieving their goal:
• Scala
• Concurrency is built-in on the language.
• Less Code due to its functional nature, easier to maintain
• All Procedure can be encapsulated in one unit
• Akka
• Makes you worry more on the BL not on the low level concurrency stuff
• Parallelism built-in on the language
• Scaling thru configuration
• Docker
• Component, Integration test on dev station.
• Easy Deployment and no more it works on my end stuff.
DockerDOCKER
Application
APACHECAMEL/SPRAY
AKKA SYSTEM
STM
Postgress
3 juin 2014 403 juin 2014 40
Seeing What is Seen
✔ Seen by everyone 4/27
Hope you don’t be on the Seen Zone
Scala and OT
We are Hiring!
Manila-HR@oberthur.com

Weitere ähnliche Inhalte

Was ist angesagt?

Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
WO Community
 
Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background Tasks
WO Community
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
krasserm
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript Testing
Ran Mizrahi
 

Was ist angesagt? (20)

Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentation
 
Android concurrency
Android concurrencyAndroid concurrency
Android concurrency
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
 
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor ExtensionsConnect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background Tasks
 
Efficient Android Threading
Efficient Android ThreadingEfficient Android Threading
Efficient Android Threading
 
Life in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with djangoLife in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with django
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in android
 
Akka.net versus microsoft orleans
Akka.net versus microsoft orleansAkka.net versus microsoft orleans
Akka.net versus microsoft orleans
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
 
Akka lsug skills matter
Akka lsug skills matterAkka lsug skills matter
Akka lsug skills matter
 
Building Reactive Systems with Akka (in Java 8 or Scala)
Building Reactive Systems with Akka (in Java 8 or Scala)Building Reactive Systems with Akka (in Java 8 or Scala)
Building Reactive Systems with Akka (in Java 8 or Scala)
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript Testing
 
Introduction of failsafe
Introduction of failsafeIntroduction of failsafe
Introduction of failsafe
 
Building reactive distributed systems with Akka
Building reactive distributed systems with Akka Building reactive distributed systems with Akka
Building reactive distributed systems with Akka
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 

Ähnlich wie Scalamen and OT

A data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madisonA data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madison
Terry Bunio
 

Ähnlich wie Scalamen and OT (20)

Stackato v6
Stackato v6Stackato v6
Stackato v6
 
Building a document e-signing workflow with Azure Durable Functions
Building a document e-signing workflow with Azure Durable FunctionsBuilding a document e-signing workflow with Azure Durable Functions
Building a document e-signing workflow with Azure Durable Functions
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept
 
Letest
LetestLetest
Letest
 
Scala, ECS, Docker: Delayed Execution @Coursera
Scala, ECS, Docker: Delayed Execution @CourseraScala, ECS, Docker: Delayed Execution @Coursera
Scala, ECS, Docker: Delayed Execution @Coursera
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
 
Stackato v4
Stackato v4Stackato v4
Stackato v4
 
A data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madisonA data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madison
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipse
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
Zure Azure PaaS Zero to Hero - DevOps training day
Zure Azure PaaS Zero to Hero - DevOps training dayZure Azure PaaS Zero to Hero - DevOps training day
Zure Azure PaaS Zero to Hero - DevOps training day
 
Selenium Automation at Incapsula
Selenium Automation at IncapsulaSelenium Automation at Incapsula
Selenium Automation at Incapsula
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
Scala Frustrations
Scala FrustrationsScala Frustrations
Scala Frustrations
 
Project Orleans - Actor Model framework
Project Orleans - Actor Model frameworkProject Orleans - Actor Model framework
Project Orleans - Actor Model framework
 
Scale up your thinking
Scale up your thinkingScale up your thinking
Scale up your thinking
 
Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015
 

Kürzlich hochgeladen

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Kürzlich hochgeladen (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 

Scalamen and OT

  • 1. 3 juin 2014 1 Scala and OT Seeing what is Seen Leo Bufi Barrameda, Jose Paulo Santiago May 27, 2014
  • 2. 3 juin 2014 2 • Software Engineer in OT (Oberthur) • Software Enthusiast • Working with Scala for 3 years • Sexiest Programmer (Usually Code wearing underwear) About Me
  • 3. 3 juin 2014 3 3 juin 2014 3
  • 4. 3 juin 2014 4 About You Guys •___ % of Java Developers •___ % of Ruby Developers •___ % of PHP Developers •___ % of .Net Developers •___ % of Scala Developers •100% Scala Enthusiast Java Ruby PHP.Net Scala Scala Enthusiast
  • 6. June 3, 2014 6 About OT • The Company • 1842 – Oberthur Printing Company • 1984 – Oberthur Technologies (Secure Printing) • 2003 – Oberthur Philippines • 2011 – Acquisition by Advent International • Employees • 6000+ Worldwide • 200+ in the Philippines • Customers: • Telecommunications • Banks • Transport • Governments • My Personal Experience •  Vision: To be the best secure technology company in the world
  • 7. June 3, 2014 7 About OT – Showcase of Product
  • 8. June 3, 2014 8 About OT – Showcase of Product in Philippines
  • 10. 3 juin 2014 10 OT Objectives • To create a Scalable Applications that can handle millions of transaction per day. • To create a multi-tenancy Applications in which every client will have different procedures and different hardware set up. • To make a scalable development procedure to scale with the number of people, number of project. • Application can run any number of customer on any topology. 3 juin 2014 10
  • 11. 3 juin 2014 11 To Achieve this Goal:
  • 12. 3 juin 2014 12 Scala (SCAlable Language) • A language that run on JVM • A programming language that combines the OOP and Functional concepts. • As an India Guy said, Scala is Java having all the items on the Effective in Java book + Functional Concepts. JVM Converted into ByteCode SCALA OOP with Effective in Java ON Functional Concept
  • 13. 3 juin 2014 13 Why Scala? • Seamless Java Interop • Can use the rich existing Java Library. JVM SCALA BYTE CODE JAVA BYTE CODE Calls Calls
  • 14. 3 juin 2014 14 Seamless Java Interop • Use Existing Builders like maven and ant • But why use maven and ant, there is sbt (simple build tool). • This can use maven repository. • Don’t use xml, you will use scala to build/define a scala project
  • 15. object Demo extends Build { val buildSettings = Defaults.defaultSettings ++ Seq( organization := "com.demo", version := "2.0.29", scalaVersion := "2.9.0-1") val scalatest = "org.scalatest" % "scalatest_2.9.0" % "1.4.1" % "test" val commonDeps = Seq(scalatest) lazy val project = Project( "demo", file("."), settings = buildSettings ++ Seq(libraryDependencies ++= commonDeps)) } 3 juin 2014 15
  • 16. object BuildSettings { ... } object Resolvers { ... } object Dependencies { ...} object Publishing { ... } object DemoBuild extends Build { import BuildSettings._ import Dependencies._ import Publishing._ lazy val root = Project("demo", file("."), settings = Project.defaultSettings ++ commonDeps) .aggregate(subProject1, subProject2) ... } 3 juin 2014 16
  • 17. 3 juin 2014 17 Why Scala? - Type Inference • val num = 1 //number is Int • val hello = "Hello " //helloWorld is String • Less Boilerplate: Let the type system figure out the type you want. • Scala is a strongly type language but due to Type Inference it seems not implicit def makeInteger(value: String) = value.toInt math.max("500", 200) implicit class MakeInteger(e: String) { def makeInteger: Int = e.toInt } "500".makeInteger
  • 18. 3 juin 2014 18 Why Scala? - Concurrency and Distribution • Has Future Support val compute = future { Math.PI * 123 } compute onComplete { case Success(result) => result case Failure(exception) => exception }
  • 19. 3 juin 2014 19 Why Scala? – Future Support Don’t Wait, REACT! • Using Future, there will be no non-blocking process. No waiting! What you need is to REACT once the concrete value/exception is returned. • Same Principle for Actors/Akka
  • 20. 3 juin 2014 20 Concurrency and Distribution • Everything is immutable (should be) • Useful in concurrent applications, can’t be corrupted by thread interference • All Messages in Akka are immutable (message then to jump from one thread to other) • How to use it: • use val instead of var • use case class instead of class
  • 21. 3 juin 2014 21 Why Scala? - Traits • Somewhat similar to interface but can define concrete method definition • Resolve problem with multiple inheritance by making the evaluation linear. • Can be use on class instance
  • 22. 3 juin 2014 22 trait Professional { val name : String def resume } trait SoftwareDev extends Professional { override def resume = println("Dev : " + name) } trait Engineer extends Professional { override def resume = println("Engineer : " + name) } class FreshGraduate(val name: String) extends SoftwareDev with Engineer new FreshGraduate("Leiz").resume //this will print Engineer : Leiz
  • 23. 3 juin 2014 23 Why Scala? – Pattern Matching • You can make decision construction base on type, value and construct someValue match { case Some(s : String) => s case Some(i : Int) => i case None => None case _ => }
  • 24. 3 juin 2014 24 Why Scala? – Pattern Matching • This combine with Partial Function is all awesomeness  def authenticate: PartialFunction[Any, Any] = { case Authenticate(user, body) => .... Body(authorize, body) } def body: PartialFunction[Any, Any] = { case Body(true, body) => //do if authenticated case Body(false, _) => //do when not authenticated } def closeSession: PartialFunction[Any, Any] = { case Close(user, body) => //process to close the session Body(successful, body) } (authenticate andThen body) orElse (body) orElse (closeSession andThen body)
  • 25. 3 juin 2014 25 Why Scala? – High Order Function • Function is a first class citizen, you can pass it as parameter, assign it to a variable etc. • With this, you can just define behaviour making things more declarative rather procedural. def recursion(value: Int, method: Int => Int, condition: Int => Boolean): Int = condition(value) match { case true => value case false => recursion(method(value), method, condition) } recursion(0, (i: Int) => i + 7, (i: Int) => i >= 2)
  • 26. Dispatcher 3 juin 2014 26 Akka • Very lightweight concurrent entities. • Immutable Event Driven Model similar to Erlang • Designing the software is easy: Actor present a Doer or Process Box and Message as the Intent ActorRef MailBox Actor Invoke Message Put it on the Message Queue ConsumeMessage
  • 27. object DemoActor { def props(magicNumber: Int): Props = Props(new DemoActor(magicNumber)).withDispatcher("demo-dispatcher") } class DemoActor(var magicNumber: Int) extends Actor { def receive = { case x: Int => magicNumber = magicNumber - 1; sender ! (x + magicNumber) } }
  • 28. 3 juin 2014 28 Why Akka? How we Use it in OT • Easy Concurrency • Event/Message-Based Driven System o Single Execution Flow model o No Shared mutuble state o Loose Coupling – behavior is isolated within an actor o Easy to Test – due to it’s isolated behavior
  • 29. 3 juin 2014 29 Why Akka? How we Use it in OT • Scaling is easy • You can scale via configuration o Dispatchers demo-dispatcher { type = Dispatcher executor = "thread-pool-executor" thread-pool-executor { core-pool-size-min = 2 core-pool-size-factor = 2.0 core-pool-size-max = 5 } throughput = 5 }
  • 30. 3 juin 2014 30 Why Akka? How we Use it in OT • Scaling is easy • Router /demo-actor { router = round-robin nr-of-instances = 100 }
  • 31. STM 3 juin 2014 31 Why Akka? How we Use it in OT • Software Transactional Memory (STM) • Haven’t use it directly, it is wrap in Activate Framework • Less Database access more interaction to memory. All transaction is commited first on memory before on database. Application Memory DiskCommits Commits Asyncly
  • 32. 3 juin 2014 32 Things we haven’t explore but will do in the future • Akka Clustering • We are ambitious, we want to horizontally scale and do redundancy to achieve zero downtime.
  • 33. Any Hardware Platform (OS) 3 juin 2014 33 Docker • Encapsulate your application, which make it runnable with any hardware environment configuration • With this we can have the same set up on our dev laptop with our production env Docker Application/Component
  • 34. 3 juin 2014 34 Docker – Useful Commands • docker pull <image_name> • docker pull ubuntu o This will download an image named ubuntu • docker run <image_name> <command> • docker run ubuntu apt-get install -y mysql-server o You had install a mysql server on your base image, Your change have been kept but are not yet saved. • docker commit <container_id> <image_name> • docker commit 67a8d234328342 ubuntu_mysql o This will create an image base on the current state of container specified
  • 35. 3 juin 2014 35 Docker – Dockerfile FROM ubuntu RUN docker run ubuntu apt-get install -y mysql-server EXPOSE 3306 ENTRYPOINT service mysql start
  • 36. 3 juin 2014 36 Docker – With This: • Don’t need any IT person to set up a server just to do component testing • Component, Integration Testing Automation like Crazy  Git REPO JENKINS BUILD TEST PUBLISH DOCKER APPLICATION DATABASE MOCKS
  • 37. 3 juin 2014 37 How Scala, Akka, Docker help OT achieving their goal: • Scala • Concurrency is built-in on the language. • Less Code due to its functional nature, easier to maintain • All Procedure can be encapsulated in one unit • Akka • Makes you worry more on the BL not on the low level concurrency stuff • Parallelism built-in on the language • Scaling thru configuration • Docker • Component, Integration test on dev station. • Easy Deployment and no more it works on my end stuff.
  • 39.
  • 40. 3 juin 2014 403 juin 2014 40 Seeing What is Seen ✔ Seen by everyone 4/27 Hope you don’t be on the Seen Zone Scala and OT We are Hiring! Manila-HR@oberthur.com