Your SlideShare is downloading. ×
0
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Scalamen and OT
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Scalamen and OT

125

Published on

How Oberthur use Scala, Akka and Docker.

How Oberthur use Scala, Akka and Docker.

Published in: Software
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
125
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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
  • 5. Scala Developers
  • 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
  • 9. 3 juin 2014 9
  • 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.
  • 38. DockerDOCKER Application APACHECAMEL/SPRAY AKKA SYSTEM STM Postgress
  • 39. 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

×