This document provides an agenda for a Scala programming conference taking place in Madrid from November 27-28, 2015. The conference will cover topics including Akka actors, futures, and transitioning from Java to Scala. One session is titled "Akka voló sobre el nido del Future" (Akka flew over the Future's nest) presented by Javier Santos and David Vallejo. Another session is titled "Caminando de Java a Scala en menos de 2 horas" (Walking from Java to Scala in less than 2 hours).
Codemotion akka persistence, cqrs%2 fes y otras siglas del montónJavier Santos Paniego
¿Qué me dices?¿Que puedo separar la parte de acciones de las vistas de mi aplicación?¿Que además puedo hacerlo escalable usando Akka-persistence?¿Basado en eventos?
En esta charla, el equipo de Scalera esperamos enseñaros cómo funciona la aproximación CQRS (recientemente implantada en sistemas como Lagom de Lightbend) para crear aplicaciones altamente escalables y resilient, usando Akka persistence como herramienta para poder guardar el estado de tu aplicación de manera distribuida y basada en eventos.
Si no te ha sonado a anuncio de tele-tienda pasivo-agresivo y aún te quedan ganas de descubrir que significan todas estas siglas raras, esta es tu charla.
https://github.com/leobenkel/Zparkio
Slides presented during the ScalaSF meetup on Thursday, March 26, 2020.
https://www.meetup.com/SF-Scala/events/268998404/
ZparkIO was on version 0.7.0 at the time, so things might be out of date.
Codemotion akka persistence, cqrs%2 fes y otras siglas del montónJavier Santos Paniego
¿Qué me dices?¿Que puedo separar la parte de acciones de las vistas de mi aplicación?¿Que además puedo hacerlo escalable usando Akka-persistence?¿Basado en eventos?
En esta charla, el equipo de Scalera esperamos enseñaros cómo funciona la aproximación CQRS (recientemente implantada en sistemas como Lagom de Lightbend) para crear aplicaciones altamente escalables y resilient, usando Akka persistence como herramienta para poder guardar el estado de tu aplicación de manera distribuida y basada en eventos.
Si no te ha sonado a anuncio de tele-tienda pasivo-agresivo y aún te quedan ganas de descubrir que significan todas estas siglas raras, esta es tu charla.
https://github.com/leobenkel/Zparkio
Slides presented during the ScalaSF meetup on Thursday, March 26, 2020.
https://www.meetup.com/SF-Scala/events/268998404/
ZparkIO was on version 0.7.0 at the time, so things might be out of date.
Aggregate programming is a novel paradigm that addresses, at the core, many issues commonly found in the development of large-scale, situated, self-adaptive systems. It is a particular macro-programming approach where a developer expresses the behaviour of the system at the aggregate-level, by targeting the distributed computational machine which is given by the entire set of (possibly mobile and heterogeneous) networked devices pervading the environment. It is the model that takes care of turning a system-level behaviour specification into the concrete, device-centric programs executed locally by each component.
Aggregate computing is formally grounded in the field calculus, a minimal functional language that works with computational fields, i.e., distributed data structures mapping devices (digital representatives of space-time portions) to computational objects. Fields are a useful unifying abstraction for drawing a connection between the physical and the computational world, and between the local and global programming viewpoints. This approach is compositional, allowing to define layers of building blocks of increasing abstraction, and is also amenable to formal analyses.
In this talk, I will present scafi (SCAla with computational FIels), an aggregate computing framework for the Scala programming language which provides (i) an internal DSL for expressing aggregate computations as well as (ii) a library support for the configuration and execution of aggregate systems. There is no need to learn ad-hoc external DSLs anymore: with scafi, Scala programmers can instantaneously start playing with this new, intriguing development approach!
These slides are about parallel sorting algorithms. In which four types of sorting algorithms are discussed with the comparison between their sequential and parallel ways. The four algorithms which are included are: Bubble sort, merge sort, Bitonic sort and Shear sort.
(chapter 7) A Concise and Practical Introduction to Programming Algorithms in...Frank Nielsen
These are the slides accompanying the textbook:
A Concise and Practical Introduction to Programming Algorithms in Java
by Frank Nielsen
Published by Springer-Verlag (2009), Undergraduate textbook in computer science (UTiCS series)
ISBN: 978-1-84882-338-9
http://www.lix.polytechnique.fr/~nielsen/JavaProgramming/
http://link.springer.com/book/10.1007%2F978-1-84882-339-6
Intro to JavaScript - Week 4: Object and ArrayJeongbae Oh
Intro to Programming with JavaScript Seminar, Fall 2017 semester
Week 4: Object and Array
Led by Jeongbae Oh, in conjunction with YCC (Yonsei Computer Club) @ Yonsei University
This seminar intends to introduce newcomers to programming using JavaScript, one of the most versatile languages of the modern world.
Digital Publishing for Scale: The Economist and GoC4Media
Video and slides synchronized, mp3 and slide download available at URL https://bit.ly/2CALlGE.
Kathryn Jonas talks about The Economist’s struggles and victories in transitioning to Go and how Go has uniquely fit their digital publishing goals. Filmed at qconnewyork.com.
Kathryn Jonas is the Lead Engineer for the Content Platform at The Economist. She has lead projects for organizations in Beijing, London, and New York, applying technology to diverse challenges such as mission impact evaluation, editorial transparency and trust, and online learning and collaboration.
GENeral Admission: A Consumer Behavior Approach in Marketing to the Millennia...Vino Mazzei
A white paper I wrote based on insights gathered from a survey on the contemporary classical music audience. This paper focuses on participants aged 21-30 years.
Aggregate programming is a novel paradigm that addresses, at the core, many issues commonly found in the development of large-scale, situated, self-adaptive systems. It is a particular macro-programming approach where a developer expresses the behaviour of the system at the aggregate-level, by targeting the distributed computational machine which is given by the entire set of (possibly mobile and heterogeneous) networked devices pervading the environment. It is the model that takes care of turning a system-level behaviour specification into the concrete, device-centric programs executed locally by each component.
Aggregate computing is formally grounded in the field calculus, a minimal functional language that works with computational fields, i.e., distributed data structures mapping devices (digital representatives of space-time portions) to computational objects. Fields are a useful unifying abstraction for drawing a connection between the physical and the computational world, and between the local and global programming viewpoints. This approach is compositional, allowing to define layers of building blocks of increasing abstraction, and is also amenable to formal analyses.
In this talk, I will present scafi (SCAla with computational FIels), an aggregate computing framework for the Scala programming language which provides (i) an internal DSL for expressing aggregate computations as well as (ii) a library support for the configuration and execution of aggregate systems. There is no need to learn ad-hoc external DSLs anymore: with scafi, Scala programmers can instantaneously start playing with this new, intriguing development approach!
These slides are about parallel sorting algorithms. In which four types of sorting algorithms are discussed with the comparison between their sequential and parallel ways. The four algorithms which are included are: Bubble sort, merge sort, Bitonic sort and Shear sort.
(chapter 7) A Concise and Practical Introduction to Programming Algorithms in...Frank Nielsen
These are the slides accompanying the textbook:
A Concise and Practical Introduction to Programming Algorithms in Java
by Frank Nielsen
Published by Springer-Verlag (2009), Undergraduate textbook in computer science (UTiCS series)
ISBN: 978-1-84882-338-9
http://www.lix.polytechnique.fr/~nielsen/JavaProgramming/
http://link.springer.com/book/10.1007%2F978-1-84882-339-6
Intro to JavaScript - Week 4: Object and ArrayJeongbae Oh
Intro to Programming with JavaScript Seminar, Fall 2017 semester
Week 4: Object and Array
Led by Jeongbae Oh, in conjunction with YCC (Yonsei Computer Club) @ Yonsei University
This seminar intends to introduce newcomers to programming using JavaScript, one of the most versatile languages of the modern world.
Digital Publishing for Scale: The Economist and GoC4Media
Video and slides synchronized, mp3 and slide download available at URL https://bit.ly/2CALlGE.
Kathryn Jonas talks about The Economist’s struggles and victories in transitioning to Go and how Go has uniquely fit their digital publishing goals. Filmed at qconnewyork.com.
Kathryn Jonas is the Lead Engineer for the Content Platform at The Economist. She has lead projects for organizations in Beijing, London, and New York, applying technology to diverse challenges such as mission impact evaluation, editorial transparency and trust, and online learning and collaboration.
GENeral Admission: A Consumer Behavior Approach in Marketing to the Millennia...Vino Mazzei
A white paper I wrote based on insights gathered from a survey on the contemporary classical music audience. This paper focuses on participants aged 21-30 years.
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)Igalia
By Daniel Ehrenberg.
JavaScript decorators were created in 2014 as a collaboration among the JavaScript ecosystem, and you've been able to use them in TypeScript and Babel. But they didn't make it into the JavaScript standard yet: not ES6, or any of the later versions, so far. We're working on standardizing decorators in TC39, the JavaScript standards committee, but some changes are required from the initial version.
In this talk, Daniel will explain what TC39 is and how we work. We'll look at some newer language feature proposals, such as Temporal and immutable records and tuples, and follow how decorators have been proceeding through the TC39 process, including why and how they're changing. TC39 could use your help in moving JavaScript forward.
(c) Full Stack Fest 2019
Sitges, Barcelona
September 4—6, 2019
https://2019.fullstackfest.com/
Debugging and Profiling C++ Template MetaprogramsPlatonov Sergey
Template metaprogramming is an emerging new direction in C++ programming for executing algorithms in compilation time. Despite all of its already proven benefits and numerous successful applications, it is yet to be accepted in industrial projects. One reason is the lack of professional software tools supporting the development of template metaprograms. A strong analogue exists between traditional runtime programs and compile-time metaprograms. This connection presents the possibility for creating development tools similar to those already used when writing runtime programs. This paper introduces Templight, a debugging framework that reveals the steps executed by the compiler during the compilation of C++ programs with templates. Templight’s features include following the instantiation chain, setting breakpoints, and inspecting metaprogram information. This framework aims to take a step forward to help template metaprogramming become more accepted in the software industry.
Some notes about programming in Scala: it covers Scala syntax and semantics, programming techniques, idioms, patterns. Many Scala features are introduced, from basic to intermediate and advanced. These are not introductory notes, but they assume a working knowledge with some other programming language (Java, C#, C++), object-oriented programming (OOP) concepts, and functional programming (FP) concepts.
Similar to Codemotion akka voló sobre el nido del future (20)
Forklift Classes Overview by Intella PartsIntella Parts
Discover the different forklift classes and their specific applications. Learn how to choose the right forklift for your needs to ensure safety, efficiency, and compliance in your operations.
For more technical information, visit our website https://intellaparts.com
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...ssuser7dcef0
Power plants release a large amount of water vapor into the
atmosphere through the stack. The flue gas can be a potential
source for obtaining much needed cooling water for a power
plant. If a power plant could recover and reuse a portion of this
moisture, it could reduce its total cooling water intake
requirement. One of the most practical way to recover water
from flue gas is to use a condensing heat exchanger. The power
plant could also recover latent heat due to condensation as well
as sensible heat due to lowering the flue gas exit temperature.
Additionally, harmful acids released from the stack can be
reduced in a condensing heat exchanger by acid condensation. reduced in a condensing heat exchanger by acid condensation.
Condensation of vapors in flue gas is a complicated
phenomenon since heat and mass transfer of water vapor and
various acids simultaneously occur in the presence of noncondensable
gases such as nitrogen and oxygen. Design of a
condenser depends on the knowledge and understanding of the
heat and mass transfer processes. A computer program for
numerical simulations of water (H2O) and sulfuric acid (H2SO4)
condensation in a flue gas condensing heat exchanger was
developed using MATLAB. Governing equations based on
mass and energy balances for the system were derived to
predict variables such as flue gas exit temperature, cooling
water outlet temperature, mole fraction and condensation rates
of water and sulfuric acid vapors. The equations were solved
using an iterative solution technique with calculations of heat
and mass transfer coefficients and physical properties.
The Internet of Things (IoT) is a revolutionary concept that connects everyday objects and devices to the internet, enabling them to communicate, collect, and exchange data. Imagine a world where your refrigerator notifies you when you’re running low on groceries, or streetlights adjust their brightness based on traffic patterns – that’s the power of IoT. In essence, IoT transforms ordinary objects into smart, interconnected devices, creating a network of endless possibilities.
Here is a blog on the role of electrical and electronics engineers in IOT. Let's dig in!!!!
For more such content visit: https://nttftrg.com/
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Understanding Inductive Bias in Machine LearningSUTEJAS
This presentation explores the concept of inductive bias in machine learning. It explains how algorithms come with built-in assumptions and preferences that guide the learning process. You'll learn about the different types of inductive bias and how they can impact the performance and generalizability of machine learning models.
The presentation also covers the positive and negative aspects of inductive bias, along with strategies for mitigating potential drawbacks. We'll explore examples of how bias manifests in algorithms like neural networks and decision trees.
By understanding inductive bias, you can gain valuable insights into how machine learning models work and make informed decisions when building and deploying them.
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
Advancements in technology unveil a myriad of electrical and electronic breakthroughs geared towards efficiently harnessing limited resources to meet human energy demands. The optimization of hybrid solar PV panels and pumped hydro energy supply systems plays a pivotal role in utilizing natural resources effectively. This initiative not only benefits humanity but also fosters environmental sustainability. The study investigated the design optimization of these hybrid systems, focusing on understanding solar radiation patterns, identifying geographical influences on solar radiation, formulating a mathematical model for system optimization, and determining the optimal configuration of PV panels and pumped hydro storage. Through a comparative analysis approach and eight weeks of data collection, the study addressed key research questions related to solar radiation patterns and optimal system design. The findings highlighted regions with heightened solar radiation levels, showcasing substantial potential for power generation and emphasizing the system's efficiency. Optimizing system design significantly boosted power generation, promoted renewable energy utilization, and enhanced energy storage capacity. The study underscored the benefits of optimizing hybrid solar PV panels and pumped hydro energy supply systems for sustainable energy usage. Optimizing the design of solar PV panels and pumped hydro energy supply systems as examined across diverse climatic conditions in a developing country, not only enhances power generation but also improves the integration of renewable energy sources and boosts energy storage capacities, particularly beneficial for less economically prosperous regions. Additionally, the study provides valuable insights for advancing energy research in economically viable areas. Recommendations included conducting site-specific assessments, utilizing advanced modeling tools, implementing regular maintenance protocols, and enhancing communication among system components.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
Student information management system project report ii.pdf
Codemotion akka voló sobre el nido del future
1. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Akka voló sobre el nido del Future
Javier Santos
David Vallejo
2. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
About us
David Vallejo @dvnavarro
« It’s not a bug – it’s an
undocumented feature.»
Anonymous
Javier Santos @jpaniego
«Hay dos formas de programar sin
errores; solo la tercera funciona»
Alan J Perlis
3. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Introduction: A functional world
● Purely functional: whole world could be implemented
in a single functional line
● Functional features
○ Robust
○ Debuggable
○ Predictable
○ Pluggable
4. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Introduction: A functional world
● Example
type Context = (Input,Output,Error)
type Action = Context => (Context,Event)
def main(
actions: Iterable[Action],
context: Context):(Context,Seq[Event]) = {
((context,Seq.empty[Event]) /: actions) {
case ((context,events),action) =>
action.apply(context) match {
case (context,event) => (context, events :+ event)
}
}
}
5. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
6. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Introduction: A functional world
● Problem? World actions are not precalculated.
What happens to I/O?
● World can be considered as
○ asynchronous: Things may happen at same time
○ reactive: Things may happen due to
■ actions: that trigger …
■ ...events: action consequences.
7. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Introduction: Runnable & Callable
● java.lang.Runnable
trait Runnable {
def run(): Unit
}
● java.util.concurrent.Callable
trait Callable[V] {
def call(): V
}
8. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Introduction: Threads
● Scala’s concurrency model is built on Java’s
● java.lang.Thread
val myThread = new Thread(new Runnable {
def run(){
println(“hi”)
}
}
myThread.start()
● Thread improvements (ExecutorService ~ Thread pool)
● Anyway, Threads abstraction level is too low
9. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
What about Scala and threads?
10. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Overview
● By default, non-blocking operations
● They will hold a T value at some point
● So a future may be uncompleted(it has no value yet) or
completed
● Completion will be treated as a scala.util.Try value
It will have two possible values:
○ Success(t: T)
○ Failure(t: Throwable)
11. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Overview
● Future example
import scala.concurrent._
import ExecutionContext.Implicits.global
val firstPrimeNumbers: Future[List[Int]] = Future {
List(1,2,3,5,7,11,13)
//what if 'calculateFirstPrimeNumbers(100000000)'…
}
res0: Future[List[Int]]
12. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Overview
● Failing Future example
import scala.concurrent._
import ExecutionContext.Implicits.global
val thisWillFail: Future[Int] = Future(2 / 0)
res0: Future[Int]
13. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: ExecutionContext
● A future, once it’s completed, it never changes of value
● An ExecutionContext
○ executes tasks submitted to them.
○ They can be seen as thread pools.
○ Most of future ops require an implicit
ExecutionContext.
14. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Expecting results
● Expecting results.
○ Blocker way (discouraged but sometimes
mandatory).
○ Non-blocker way: using callbacks
15. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Blocking - Await
● Blocking: Await.result / Await.ready
import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
val f: Future[Int] = Future{
Thread.sleep(10000)
2
}
println(Await.result(f,12.seconds))
//2
16. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Blocking - Await
● Blocking: Await (Problem: Not enough time)
import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
val f: Future[Int] = Future{
Thread.sleep(10000)
2
}
println(Await.result(f,5.seconds))
java.util.concurrent.TimeoutException: Futures timed out after
[5 seconds]
17. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Non-blocking - Callbacks
● Non-Blocking: callbacks
import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global
val f: Future[Int] = Future{
Thread.sleep(10000)
2
}
f.onComplete( n => println(n) )
//at some point, “Success(2)” will appear
Non-blocking
18. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Callbacks
● Callbacks will be executed asynchronously when future
is completed
● type Callback = Try[T] => Unit
● Try[T] ~ Either[Throwable,T]
○ Left(throwable) ~ Failure(throwable)
○ Right(t) ~ Success(t)
19. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Callbacks
● onComplete
f.onComplete( (t: Try[Int]) => println(t) )
//Success(2)
● onSuccess
f.onSuccess( n => println(n) )
//2
● onFailure
f.onFailure( throwable => println(throwable.getMessage) )
//it will never print an error (because it equals Success(2))
20. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Operations
● map
def getFirstMillionOfPrimes(): Future[List[Int]] = ???
getFirstMillionOfPrimes().map(
(list: List[Int]) => list.head)
res0: Future[Int]
22. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Monad behavior
● Composition
○ Future is like a monad
■ Point Function: Future.apply
■ Bind Function: flatMap
■ Some math properties and so...
○ Since Future has map,flatMap,filter methods;
it can be composed easily in a for-comprehension
23. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
24. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Composition
● Problem
var result: String = “”
val f1: Future[Unit] = Future{
result += “Hi ”
}
val f2: Future[Unit] = Future{
result += “ everyone”
}
● result value? “Hi everyone”? “ everyoneHi”?
25. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
26. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Composition
● for-comprehension is your friend
for {
primes <- getFirstMillionPrimes()
primesString <- concatenate(primes)
} yield primesString
res0: Future[String]
Future[List[Int]]
Future[String]
27. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Recovering from failure
● recover
val f: Future[Int] = Future{
1 / 0
}.recover{
case e: ArithmeticException => 0
}
28. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Recovering from failure
● recoverWith
val f: Future[Int] = Future{
1 / 0
}.recoverWith{
case e: ArithmeticException => Future(0)
}
29. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future: Recovering from failure
● fallbackTo
val f1: Future[Int] = Future{
1 / 0
}
val f2: Future[Int] = Future(0)
val f = f1 fallbackTo f2
30. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Promise: Overview
● Futures can be created by
○ Future.apply
○ Promises
● You can think about it like
○ Future ~ Read future value
○ Promise ~ Write future value
● Promises are single-assigned (just once. Immutable as
futures)
31. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Promise: Baggage & claim
Menu
order
Menu
Being
Cooked
Ticket
Menu ready
32. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Promise: Baggage & claim
Begin
completion
Future[T]
p.success
or
p.failure
Try[T]
Promise[T]
33. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Promise: example
val r: T = produceSomething()
p success r
doSomethingElse()
startDoingSomething()
f onSuccess {
case r: T => handleResult()
}
val p = promise[T]
val f = p.future
Producer Consumer
34. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Promise: completion
● complete
val p = promise[Int]
p.complete(Try(2))
● completeWith
val p = promise[Int]
p.completeWith(Future(2))
35. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Future alternatives
● Scalaz futures
● Scala’s async library
36. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Tones of slides and however...
Futures/Promises
Akka actors
37. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
38. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Akka: main concepts
● Actors, actors everywhere
● Asynchronous messages
● Event-driven processes
● Distributed systems
39. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Akka: Actors
● Black box
● State without race condition
● Messages to update the state
40. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Akka: Actors
class MyFirstActor extends Actor {
override def receive = {
case _ => println("Hello World!")
}
}
41. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Akka: Send a message
● Tell message
actor ! "Hi"
● Ask message
actor ? "Are you there"
42. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Akka: Ask pattern
implicit val timeout = Timeout(5 seconds)
val f: Future[String] =
(actorRef ? AreYouThere).mapTo[String]
43. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Akka: An example
44. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Akka: Services user
service
contact
service
address
service
System
GetUser(id)
GetContacts(name)
GetAddress(name)
Option[User]
List[Contact]
Address
UserInfo
45. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Akka: Ask Pattern & For
Comprehension
class UserServiceActor extends Actor {
val users: Map[String, User] =
Map("1" -> User("John"), "2" -> User("Jack"))
override def receive = {
case GetUser(userId: String) =>
sender ! users.get(userId)
}
}
46. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Akka: Ask Pattern & For
Comprehension
def getInfo(userId: String): Future[UserInfo] =
for {
Some(user) <- (usersActor ? GetUser(userId))
.mapTo[Option[User]]
contacts <- (contactsActor.?(GetContacts(user.name))
(Timeout(5 seconds),context.self))
.mapTo[List[Contact]]
address <- (addressesActor ? GetAddress(user.name))
.mapTo[Address]
} yield UserInfo(user, contacts, address)
47. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
48. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
scalera.es
@scalerablog
49. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
50. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Primeros pasos con Akka:
Olvídate de los threads
27 NOVEMBER
TRACK D
18:00
51. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Caminando de Java a Scala en
menos de 2 horas
28 NOVEMBER
TRACK B
9:30
52. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
53. MADRID · NOV 27-28 · 2015
Scala Programming @ Madrid
Akka voló sobre el nido del Future
Javier Santos
David Vallejo