SlideShare a Scribd company logo
A quick introduction to
OTP Applications
using a
Gen_server example
on Erlang/OTP R15B
Baed on the official online manuals and a gen_server example from http://www.rustyrazorblade.
com/2009/04/erlang-understanding-gen_server/
files and source code
0 directories, 5 files
├── demo.script
├── demo_application.app
├── demo_application.erl
├── demo_supervisor.erl
└── demo_gen_server.erl
%% -*- erlang -*-
main(_Strings)->
% compile all the .erl files to .beam files
make:all(),
% start demo_application
application:start(demo_application),
% run demo_gen_server:add/1
Output = demo_gen_server:add(10),
io:format(
"nnInitial demo_gen_server state was 0;
adding 10; returned: ~pnn",
[Output]
),
halt().
demo.script
{ application,
demo_application,
[ { mod,
{ demo_application,
[]
}
},
{ applications,
[ kernel,
stdlib
]
}
]
}.
demo_application.app
-module(demo_application).
-behaviour(application).
-export([start/2, stop/1]).
-compile(native).
start(_Type,_Args) ->
demo_supervisor:start_link().
stop(State) ->
{ok,State}.
demo_application.erl
-module(demo_supervisor).
-behaviour(supervisor).
-export([start_link/0, init/1]).
-compile(native).
start_link() ->
supervisor:start_link(
{ local,
demo_supervisor_instance1
},
demo_supervisor,
[]
).
init(_Args) ->
{ ok,
{ { one_for_one,
1,
60
},
[ { demo_gen_server_child_id,
{ demo_gen_server,
start_link,
[]
},
permanent,
brutal_kill,
worker,
[ demo_gen_server ]
}
]
}
}.
demo_supervisor.erl
-module(demo_gen_server).
-export( [ start_link/0,
add/1,
subtract/1,
init/1,
handle_call/3
]
).
-compile(native).
start_link()->
gen_server:start_link(
{ local,
demo_gen_server_instance2
},
demo_gen_server,
[],
[]
).
init(_Args) -> {ok, 0}.
add(Num) ->
gen_server:call(
demo_gen_server_instance1,
{add, Num}
).
subtract(Num) ->
gen_server:call(
demo_gen_server_instance1,
{subtract, Num}
).
handle_call({add, Num}, _From, State) ->
{reply, State + Num, State + Num};
handle_call({subtract, Num}, _From, State) ->
{reply, State - Num, State - Num}.
demo_gen_server.erl
a quick demo
0 directories, 5 files
├── demo.script
├── demo_application.app
├── demo_application.erl
├── demo_supervisor.erl
└── demo_gen_server.erl
PROMPT: escript demo.script
Recompile: demo_application
Recompile: demo_gen_server
Recompile: demo_supervisor
Initial demo_gen_server state was 0;
adding 10; returned: 10
PROMPT:
PROMPT: erl
Erlang R15B (erts-5.9) [source] [64-bit]
[smp:2:2] [async-threads:0] [hipe]
[kernel-poll:false]
Eshell V5.9 (abort with ^G)
1> make:all().
Recompile: demo_application
Recompile: demo_gen_server
Recompile: demo_supervisor
up_to_date
2> application:start(demo_application).
ok
3> demo_gen_server:add(10).
10
4> q().
ok
5>
PROMPT:
Method 2:
start the Erlang shell,
then manually run the commands from demo.
script.
Method 1:
just run
demo.script.
Current
Working
Directory
tear down
0 directories, 5 files
├── demo.script
├── demo_application.app
├── demo_application.erl
├── demo_supervisor.erl
└── demo_gen_server.erl
make:all().
This searches the current working directory, compiles any .erl files to
.beam files if the latter do not already exist, and recompiles any .erl
files which have changed since their existing .beam files were
compiled.
application:start(demo_application).
This reads demo_application.app, which is an application configuration
file, then attempts to compile, load, and start the application.
The internal events are expanded on the next slide.
demo_gen_server:add(10).
The "callback" module demo_gen_server implements the stock OTP
"behaviour" module gen_server, and is now instantiated as a process in
a supervision tree.
The internal events are expanded on the next slide.
ancestor system
processes
(try running
observer:start()
to view)
demo_supervisor
demo_
gen_server
overview
0 directories, 5 files
├── demo.script
├── demo_application.app
├── demo_application.erl
├── demo_supervisor.erl
└── demo_gen_server.erl
loading & starting
(1) calling: (behaviour module:function) application:start(demo_application)
(2) (1) calls: behaviour module:function) application:load(demo_application)
(3) (2) reads: (configuration file) demo_application.app
(4) (3) points to: (callback module) demo_application
(5) (1) calls: (callback module:function) demo_application:start/2
(6) (5) calls: (callback module:function) demo_supervisor:start_link/0
(7) (6) calls: (behaviour module:function) supervisor:start_link/2,3
(8) (7) calls: (callback module:function) demo_supervisor:init/1
(9) (8) points to: (callback module:function) demo_gen_server:start_link/0
(10) (7) calls: (callback module:function) demo_gen_server:start_link/0
(11) (10) calls: (behaviour module:function) gen_server:start_link/3,4
(12) (11) calls: (callback module:function) demo_gen_server:init/1
... and the application is started!
The process is probably even more complicated, further under the hood, but this should suffice for
introductions.
0 directories, 5 files
├── demo.script
├── demo_application.app
├── demo_application.erl
├── demo_supervisor.erl
└── demo_gen_server.erl
using/calling/doing
(1) calling: (callback module:function) demo_gen_server:add(10)
(2) (1) calls: (behaviour module:function) gen_server:call/2,3
(3) (2) calls: (callback module:function) demo_gen_server:handle_call/3
... then work is done, and a result is returned!

More Related Content

What's hot

Introducing Elixir and OTP at the Erlang BASH
Introducing Elixir and OTP at the Erlang BASHIntroducing Elixir and OTP at the Erlang BASH
Introducing Elixir and OTP at the Erlang BASH
devbash
 
Basics of ANT
Basics of ANTBasics of ANT
Test your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practiceTest your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practice
Sebastian Marek
 
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging modulePython Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging module
P3 InfoTech Solutions Pvt. Ltd.
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
varuntaliyan
 
Software Testing
Software TestingSoftware Testing
Software Testing
Lambert Lum
 
Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016
Rouven Weßling
 
Beyond Unit Testing
Beyond Unit TestingBeyond Unit Testing
Beyond Unit Testing
Steve Loughran
 
Cell processor lab
Cell processor labCell processor lab
Cell processor lab
coolmirza143
 
What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?
Rouven Weßling
 
Anti Debugging
Anti DebuggingAnti Debugging
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to hero
Jeremy Cook
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
Mindfire Solutions
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsql
afa reg
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2
LiviaLiaoFontech
 
BEAMing With Joy
BEAMing With JoyBEAMing With Joy
BEAMing With Joy
⌨️ Steven Proctor
 
Elixir and OTP
Elixir and OTPElixir and OTP
Elixir and OTP
Pedro Medeiros
 
Python-nose: A unittest-based testing framework for Python that makes writing...
Python-nose: A unittest-based testing framework for Python that makes writing...Python-nose: A unittest-based testing framework for Python that makes writing...
Python-nose: A unittest-based testing framework for Python that makes writing...
Timo Stollenwerk
 
Exploiting stack overflow 101
Exploiting stack overflow 101Exploiting stack overflow 101
Exploiting stack overflow 101
n|u - The Open Security Community
 
Pyunit
PyunitPyunit
Pyunit
Ikuru Kanuma
 

What's hot (20)

Introducing Elixir and OTP at the Erlang BASH
Introducing Elixir and OTP at the Erlang BASHIntroducing Elixir and OTP at the Erlang BASH
Introducing Elixir and OTP at the Erlang BASH
 
Basics of ANT
Basics of ANTBasics of ANT
Basics of ANT
 
Test your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practiceTest your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practice
 
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging modulePython Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging module
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016
 
Beyond Unit Testing
Beyond Unit TestingBeyond Unit Testing
Beyond Unit Testing
 
Cell processor lab
Cell processor labCell processor lab
Cell processor lab
 
What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?
 
Anti Debugging
Anti DebuggingAnti Debugging
Anti Debugging
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to hero
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsql
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2
 
BEAMing With Joy
BEAMing With JoyBEAMing With Joy
BEAMing With Joy
 
Elixir and OTP
Elixir and OTPElixir and OTP
Elixir and OTP
 
Python-nose: A unittest-based testing framework for Python that makes writing...
Python-nose: A unittest-based testing framework for Python that makes writing...Python-nose: A unittest-based testing framework for Python that makes writing...
Python-nose: A unittest-based testing framework for Python that makes writing...
 
Exploiting stack overflow 101
Exploiting stack overflow 101Exploiting stack overflow 101
Exploiting stack overflow 101
 
Pyunit
PyunitPyunit
Pyunit
 

Viewers also liked

Finite State Machines - Why the fear?
Finite State Machines - Why the fear?Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
Mahesh Paolini-Subramanya
 
References
ReferencesReferences
References
Rebekah Evermon
 
2016 práctica calameo william
2016 práctica calameo william2016 práctica calameo william
2016 práctica calameo william
william alejandro castiblanco monroy
 
Computer science
Computer scienceComputer science
Computer science
Jacollege CSdept
 
Unit 2: Booklet (First Draft)
Unit 2: Booklet (First Draft)Unit 2: Booklet (First Draft)
Unit 2: Booklet (First Draft)
phele1994
 
תמונות מתוך ההרצאות
תמונות מתוך ההרצאותתמונות מתוך ההרצאות
תמונות מתוך ההרצאות
galit_gilboa
 
Research Paper Zaahl 2014 corrections
Research Paper Zaahl 2014 correctionsResearch Paper Zaahl 2014 corrections
Research Paper Zaahl 2014 corrections
Charne Zaahl
 
EL FÚTBOL ARGENTINO.Gustavo Albano Abreu.ISBN:9789871775323
EL FÚTBOL ARGENTINO.Gustavo Albano Abreu.ISBN:9789871775323EL FÚTBOL ARGENTINO.Gustavo Albano Abreu.ISBN:9789871775323
EL FÚTBOL ARGENTINO.Gustavo Albano Abreu.ISBN:9789871775323
Marcial Pons Argentina
 
PERUBAHAN FISIOLOGI MASA NIFAS
PERUBAHAN FISIOLOGI MASA NIFASPERUBAHAN FISIOLOGI MASA NIFAS
PERUBAHAN FISIOLOGI MASA NIFAS
pjj_kemenkes
 
Nuevas Tecnologías, debes de realizar:
Nuevas Tecnologías, debes de realizar:Nuevas Tecnologías, debes de realizar:
Nuevas Tecnologías, debes de realizar:
yiraliza hernandez
 
Resultados del cuestionario proyecto afrocolombianidad dirigido a estudiantes
Resultados del cuestionario proyecto afrocolombianidad dirigido a estudiantesResultados del cuestionario proyecto afrocolombianidad dirigido a estudiantes
Resultados del cuestionario proyecto afrocolombianidad dirigido a estudiantes
marlosa75
 
Actividad 7
Actividad 7Actividad 7
Actividad 7
Juan Cockmejia
 
Anh co hien bai boc
Anh co hien bai bocAnh co hien bai boc
Anh co hien bai boc
vumanhthanganchau
 
15 16
15 16 15 16
15 16
Juan Soto
 
Ed6620 edmodo presentation
Ed6620 edmodo presentationEd6620 edmodo presentation
Ed6620 edmodo presentation
Roxanne Gibbons
 
Unitat 05 geografia_2a_part
Unitat 05 geografia_2a_partUnitat 05 geografia_2a_part
Unitat 05 geografia_2a_part
escolalapau
 
production diary
production diary production diary
production diary
A_Melodie
 
Презентація:Матеріали до уроків
Презентація:Матеріали до уроківПрезентація:Матеріали до уроків
Презентація:Матеріали до уроків
sveta7940
 
Food and health
Food and healthFood and health
Food and health
Luciano Santos
 

Viewers also liked (20)

Finite State Machines - Why the fear?
Finite State Machines - Why the fear?Finite State Machines - Why the fear?
Finite State Machines - Why the fear?
 
References
ReferencesReferences
References
 
2016 práctica calameo william
2016 práctica calameo william2016 práctica calameo william
2016 práctica calameo william
 
Computer science
Computer scienceComputer science
Computer science
 
Unit 2: Booklet (First Draft)
Unit 2: Booklet (First Draft)Unit 2: Booklet (First Draft)
Unit 2: Booklet (First Draft)
 
תמונות מתוך ההרצאות
תמונות מתוך ההרצאותתמונות מתוך ההרצאות
תמונות מתוך ההרצאות
 
Research Paper Zaahl 2014 corrections
Research Paper Zaahl 2014 correctionsResearch Paper Zaahl 2014 corrections
Research Paper Zaahl 2014 corrections
 
EL FÚTBOL ARGENTINO.Gustavo Albano Abreu.ISBN:9789871775323
EL FÚTBOL ARGENTINO.Gustavo Albano Abreu.ISBN:9789871775323EL FÚTBOL ARGENTINO.Gustavo Albano Abreu.ISBN:9789871775323
EL FÚTBOL ARGENTINO.Gustavo Albano Abreu.ISBN:9789871775323
 
PERUBAHAN FISIOLOGI MASA NIFAS
PERUBAHAN FISIOLOGI MASA NIFASPERUBAHAN FISIOLOGI MASA NIFAS
PERUBAHAN FISIOLOGI MASA NIFAS
 
Nuevas Tecnologías, debes de realizar:
Nuevas Tecnologías, debes de realizar:Nuevas Tecnologías, debes de realizar:
Nuevas Tecnologías, debes de realizar:
 
งานนำเสนอ
งานนำเสนองานนำเสนอ
งานนำเสนอ
 
Resultados del cuestionario proyecto afrocolombianidad dirigido a estudiantes
Resultados del cuestionario proyecto afrocolombianidad dirigido a estudiantesResultados del cuestionario proyecto afrocolombianidad dirigido a estudiantes
Resultados del cuestionario proyecto afrocolombianidad dirigido a estudiantes
 
Actividad 7
Actividad 7Actividad 7
Actividad 7
 
Anh co hien bai boc
Anh co hien bai bocAnh co hien bai boc
Anh co hien bai boc
 
15 16
15 16 15 16
15 16
 
Ed6620 edmodo presentation
Ed6620 edmodo presentationEd6620 edmodo presentation
Ed6620 edmodo presentation
 
Unitat 05 geografia_2a_part
Unitat 05 geografia_2a_partUnitat 05 geografia_2a_part
Unitat 05 geografia_2a_part
 
production diary
production diary production diary
production diary
 
Презентація:Матеріали до уроків
Презентація:Матеріали до уроківПрезентація:Матеріали до уроків
Презентація:Матеріали до уроків
 
Food and health
Food and healthFood and health
Food and health
 

Similar to OTP application (with gen server child) - simple example

Rupicon 2014 Action pack
Rupicon 2014 Action packRupicon 2014 Action pack
Rupicon 2014 Action pack
rupicon
 
Experimentos lab
Experimentos labExperimentos lab
Experimentos lab
George Madson Dias Santos
 
OpenERP Technical Memento V0.7.3
OpenERP Technical Memento V0.7.3OpenERP Technical Memento V0.7.3
OpenERP Technical Memento V0.7.3
Borni DHIFI
 
Test Drive Development in Ruby On Rails
Test Drive Development in Ruby On RailsTest Drive Development in Ruby On Rails
Test Drive Development in Ruby On Rails
Nyros Technologies
 
Session10-PHP Misconfiguration
Session10-PHP MisconfigurationSession10-PHP Misconfiguration
Session10-PHP Misconfiguration
zakieh alizadeh
 
Re-Design with Elixir/OTP
Re-Design with Elixir/OTPRe-Design with Elixir/OTP
Re-Design with Elixir/OTP
Mustafa TURAN
 
(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i
Nico Ludwig
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
Su Zin Kyaw
 
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands OnjBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On
Mauricio (Salaboy) Salatino
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
Rabble .
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
Brendan Sera-Shriar
 
Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0
Quang Ngoc
 
11i Logs
11i Logs11i Logs
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
Nerd Tzanetopoulos
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
Haehnchen
 
Configuration Management and Transforming Legacy Applications in the Enterpri...
Configuration Management and Transforming Legacy Applications in the Enterpri...Configuration Management and Transforming Legacy Applications in the Enterpri...
Configuration Management and Transforming Legacy Applications in the Enterpri...
Docker, Inc.
 
Dive into Play Framework
Dive into Play FrameworkDive into Play Framework
Dive into Play Framework
Maher Gamal
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in details
Max Klymyshyn
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfony
Sayed Ahmed
 
Swift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for DevelopersSwift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for Developers
Azilen Technologies Pvt. Ltd.
 

Similar to OTP application (with gen server child) - simple example (20)

Rupicon 2014 Action pack
Rupicon 2014 Action packRupicon 2014 Action pack
Rupicon 2014 Action pack
 
Experimentos lab
Experimentos labExperimentos lab
Experimentos lab
 
OpenERP Technical Memento V0.7.3
OpenERP Technical Memento V0.7.3OpenERP Technical Memento V0.7.3
OpenERP Technical Memento V0.7.3
 
Test Drive Development in Ruby On Rails
Test Drive Development in Ruby On RailsTest Drive Development in Ruby On Rails
Test Drive Development in Ruby On Rails
 
Session10-PHP Misconfiguration
Session10-PHP MisconfigurationSession10-PHP Misconfiguration
Session10-PHP Misconfiguration
 
Re-Design with Elixir/OTP
Re-Design with Elixir/OTPRe-Design with Elixir/OTP
Re-Design with Elixir/OTP
 
(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands OnjBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
 
Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0
 
11i Logs
11i Logs11i Logs
11i Logs
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 
Configuration Management and Transforming Legacy Applications in the Enterpri...
Configuration Management and Transforming Legacy Applications in the Enterpri...Configuration Management and Transforming Legacy Applications in the Enterpri...
Configuration Management and Transforming Legacy Applications in the Enterpri...
 
Dive into Play Framework
Dive into Play FrameworkDive into Play Framework
Dive into Play Framework
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in details
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfony
 
Swift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for DevelopersSwift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for Developers
 

More from YangJerng Hwa

Structuring Marketing Teams
Structuring Marketing TeamsStructuring Marketing Teams
Structuring Marketing Teams
YangJerng Hwa
 
Architecturing the software stack at a small business
Architecturing the software stack at a small businessArchitecturing the software stack at a small business
Architecturing the software stack at a small business
YangJerng Hwa
 
Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)
YangJerng Hwa
 
JavaScript - Promises study notes- 2019-11-30
JavaScript  - Promises study notes- 2019-11-30JavaScript  - Promises study notes- 2019-11-30
JavaScript - Promises study notes- 2019-11-30
YangJerng Hwa
 
2019 10-09 google ads analysis - eyeballing without proper math
2019 10-09 google ads analysis - eyeballing without proper math2019 10-09 google ads analysis - eyeballing without proper math
2019 10-09 google ads analysis - eyeballing without proper math
YangJerng Hwa
 
2019 malaysia car accident - total loss - diy third-party claim - simplifie...
2019   malaysia car accident - total loss - diy third-party claim - simplifie...2019   malaysia car accident - total loss - diy third-party claim - simplifie...
2019 malaysia car accident - total loss - diy third-party claim - simplifie...
YangJerng Hwa
 
2019 09 tech publishers in malaysia
2019 09 tech publishers in malaysia2019 09 tech publishers in malaysia
2019 09 tech publishers in malaysia
YangJerng Hwa
 
2019 09 web components
2019 09 web components2019 09 web components
2019 09 web components
YangJerng Hwa
 
Appendix - arc of development
Appendix  - arc of developmentAppendix  - arc of development
Appendix - arc of development
YangJerng Hwa
 
A Docker Diagram
A Docker DiagramA Docker Diagram
A Docker Diagram
YangJerng Hwa
 
A Software Problem (and a maybe-solution)
A Software Problem (and a maybe-solution)A Software Problem (and a maybe-solution)
A Software Problem (and a maybe-solution)
YangJerng Hwa
 
Deep learning job pitch - personal bits
Deep learning job pitch - personal bitsDeep learning job pitch - personal bits
Deep learning job pitch - personal bits
YangJerng Hwa
 
Monolithic docker pattern
Monolithic docker patternMonolithic docker pattern
Monolithic docker pattern
YangJerng Hwa
 
What people think about Philosophers & Management Consultants
What people think about Philosophers & Management ConsultantsWhat people think about Philosophers & Management Consultants
What people think about Philosophers & Management Consultants
YangJerng Hwa
 
Process for Terminating Employees in Malaysia
Process for Terminating Employees in MalaysiaProcess for Terminating Employees in Malaysia
Process for Terminating Employees in Malaysia
YangJerng Hwa
 
Pour-over Coffee with the EK43
Pour-over Coffee with the EK43Pour-over Coffee with the EK43
Pour-over Coffee with the EK43
YangJerng Hwa
 
ERTS diagram
ERTS diagramERTS diagram
ERTS diagram
YangJerng Hwa
 
Intro to Stock Trading for Programmers
Intro to Stock Trading for ProgrammersIntro to Stock Trading for Programmers
Intro to Stock Trading for Programmers
YangJerng Hwa
 
A Haphazard Petcha Kutcha
A Haphazard Petcha KutchaA Haphazard Petcha Kutcha
A Haphazard Petcha Kutcha
YangJerng Hwa
 

More from YangJerng Hwa (19)

Structuring Marketing Teams
Structuring Marketing TeamsStructuring Marketing Teams
Structuring Marketing Teams
 
Architecturing the software stack at a small business
Architecturing the software stack at a small businessArchitecturing the software stack at a small business
Architecturing the software stack at a small business
 
Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)
 
JavaScript - Promises study notes- 2019-11-30
JavaScript  - Promises study notes- 2019-11-30JavaScript  - Promises study notes- 2019-11-30
JavaScript - Promises study notes- 2019-11-30
 
2019 10-09 google ads analysis - eyeballing without proper math
2019 10-09 google ads analysis - eyeballing without proper math2019 10-09 google ads analysis - eyeballing without proper math
2019 10-09 google ads analysis - eyeballing without proper math
 
2019 malaysia car accident - total loss - diy third-party claim - simplifie...
2019   malaysia car accident - total loss - diy third-party claim - simplifie...2019   malaysia car accident - total loss - diy third-party claim - simplifie...
2019 malaysia car accident - total loss - diy third-party claim - simplifie...
 
2019 09 tech publishers in malaysia
2019 09 tech publishers in malaysia2019 09 tech publishers in malaysia
2019 09 tech publishers in malaysia
 
2019 09 web components
2019 09 web components2019 09 web components
2019 09 web components
 
Appendix - arc of development
Appendix  - arc of developmentAppendix  - arc of development
Appendix - arc of development
 
A Docker Diagram
A Docker DiagramA Docker Diagram
A Docker Diagram
 
A Software Problem (and a maybe-solution)
A Software Problem (and a maybe-solution)A Software Problem (and a maybe-solution)
A Software Problem (and a maybe-solution)
 
Deep learning job pitch - personal bits
Deep learning job pitch - personal bitsDeep learning job pitch - personal bits
Deep learning job pitch - personal bits
 
Monolithic docker pattern
Monolithic docker patternMonolithic docker pattern
Monolithic docker pattern
 
What people think about Philosophers & Management Consultants
What people think about Philosophers & Management ConsultantsWhat people think about Philosophers & Management Consultants
What people think about Philosophers & Management Consultants
 
Process for Terminating Employees in Malaysia
Process for Terminating Employees in MalaysiaProcess for Terminating Employees in Malaysia
Process for Terminating Employees in Malaysia
 
Pour-over Coffee with the EK43
Pour-over Coffee with the EK43Pour-over Coffee with the EK43
Pour-over Coffee with the EK43
 
ERTS diagram
ERTS diagramERTS diagram
ERTS diagram
 
Intro to Stock Trading for Programmers
Intro to Stock Trading for ProgrammersIntro to Stock Trading for Programmers
Intro to Stock Trading for Programmers
 
A Haphazard Petcha Kutcha
A Haphazard Petcha KutchaA Haphazard Petcha Kutcha
A Haphazard Petcha Kutcha
 

Recently uploaded

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 

OTP application (with gen server child) - simple example

  • 1. A quick introduction to OTP Applications using a Gen_server example on Erlang/OTP R15B Baed on the official online manuals and a gen_server example from http://www.rustyrazorblade. com/2009/04/erlang-understanding-gen_server/
  • 3. 0 directories, 5 files ├── demo.script ├── demo_application.app ├── demo_application.erl ├── demo_supervisor.erl └── demo_gen_server.erl %% -*- erlang -*- main(_Strings)-> % compile all the .erl files to .beam files make:all(), % start demo_application application:start(demo_application), % run demo_gen_server:add/1 Output = demo_gen_server:add(10), io:format( "nnInitial demo_gen_server state was 0; adding 10; returned: ~pnn", [Output] ), halt(). demo.script { application, demo_application, [ { mod, { demo_application, [] } }, { applications, [ kernel, stdlib ] } ] }. demo_application.app -module(demo_application). -behaviour(application). -export([start/2, stop/1]). -compile(native). start(_Type,_Args) -> demo_supervisor:start_link(). stop(State) -> {ok,State}. demo_application.erl -module(demo_supervisor). -behaviour(supervisor). -export([start_link/0, init/1]). -compile(native). start_link() -> supervisor:start_link( { local, demo_supervisor_instance1 }, demo_supervisor, [] ). init(_Args) -> { ok, { { one_for_one, 1, 60 }, [ { demo_gen_server_child_id, { demo_gen_server, start_link, [] }, permanent, brutal_kill, worker, [ demo_gen_server ] } ] } }. demo_supervisor.erl -module(demo_gen_server). -export( [ start_link/0, add/1, subtract/1, init/1, handle_call/3 ] ). -compile(native). start_link()-> gen_server:start_link( { local, demo_gen_server_instance2 }, demo_gen_server, [], [] ). init(_Args) -> {ok, 0}. add(Num) -> gen_server:call( demo_gen_server_instance1, {add, Num} ). subtract(Num) -> gen_server:call( demo_gen_server_instance1, {subtract, Num} ). handle_call({add, Num}, _From, State) -> {reply, State + Num, State + Num}; handle_call({subtract, Num}, _From, State) -> {reply, State - Num, State - Num}. demo_gen_server.erl
  • 5. 0 directories, 5 files ├── demo.script ├── demo_application.app ├── demo_application.erl ├── demo_supervisor.erl └── demo_gen_server.erl PROMPT: escript demo.script Recompile: demo_application Recompile: demo_gen_server Recompile: demo_supervisor Initial demo_gen_server state was 0; adding 10; returned: 10 PROMPT: PROMPT: erl Erlang R15B (erts-5.9) [source] [64-bit] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.9 (abort with ^G) 1> make:all(). Recompile: demo_application Recompile: demo_gen_server Recompile: demo_supervisor up_to_date 2> application:start(demo_application). ok 3> demo_gen_server:add(10). 10 4> q(). ok 5> PROMPT: Method 2: start the Erlang shell, then manually run the commands from demo. script. Method 1: just run demo.script. Current Working Directory
  • 7. 0 directories, 5 files ├── demo.script ├── demo_application.app ├── demo_application.erl ├── demo_supervisor.erl └── demo_gen_server.erl make:all(). This searches the current working directory, compiles any .erl files to .beam files if the latter do not already exist, and recompiles any .erl files which have changed since their existing .beam files were compiled. application:start(demo_application). This reads demo_application.app, which is an application configuration file, then attempts to compile, load, and start the application. The internal events are expanded on the next slide. demo_gen_server:add(10). The "callback" module demo_gen_server implements the stock OTP "behaviour" module gen_server, and is now instantiated as a process in a supervision tree. The internal events are expanded on the next slide. ancestor system processes (try running observer:start() to view) demo_supervisor demo_ gen_server overview
  • 8. 0 directories, 5 files ├── demo.script ├── demo_application.app ├── demo_application.erl ├── demo_supervisor.erl └── demo_gen_server.erl loading & starting (1) calling: (behaviour module:function) application:start(demo_application) (2) (1) calls: behaviour module:function) application:load(demo_application) (3) (2) reads: (configuration file) demo_application.app (4) (3) points to: (callback module) demo_application (5) (1) calls: (callback module:function) demo_application:start/2 (6) (5) calls: (callback module:function) demo_supervisor:start_link/0 (7) (6) calls: (behaviour module:function) supervisor:start_link/2,3 (8) (7) calls: (callback module:function) demo_supervisor:init/1 (9) (8) points to: (callback module:function) demo_gen_server:start_link/0 (10) (7) calls: (callback module:function) demo_gen_server:start_link/0 (11) (10) calls: (behaviour module:function) gen_server:start_link/3,4 (12) (11) calls: (callback module:function) demo_gen_server:init/1 ... and the application is started! The process is probably even more complicated, further under the hood, but this should suffice for introductions.
  • 9. 0 directories, 5 files ├── demo.script ├── demo_application.app ├── demo_application.erl ├── demo_supervisor.erl └── demo_gen_server.erl using/calling/doing (1) calling: (callback module:function) demo_gen_server:add(10) (2) (1) calls: (behaviour module:function) gen_server:call/2,3 (3) (2) calls: (callback module:function) demo_gen_server:handle_call/3 ... then work is done, and a result is returned!