SlideShare a Scribd company logo
1 of 9
Download to read offline
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 BASHdevbash
 
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 practiceSebastian Marek
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnitvaruntaliyan
 
Software Testing
Software TestingSoftware Testing
Software TestingLambert 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 2016Rouven Weßling
 
Cell processor lab
Cell processor labCell processor lab
Cell processor labcoolmirza143
 
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
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to heroJeremy Cook
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnitMindfire Solutions
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsqlafa reg
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2LiviaLiaoFontech
 
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
 

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

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 correctionsCharne 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:9789871775323Marcial Pons Argentina
 
PERUBAHAN FISIOLOGI MASA NIFAS
PERUBAHAN FISIOLOGI MASA NIFASPERUBAHAN FISIOLOGI MASA NIFAS
PERUBAHAN FISIOLOGI MASA NIFASpjj_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 estudiantesmarlosa75
 
Ed6620 edmodo presentation
Ed6620 edmodo presentationEd6620 edmodo presentation
Ed6620 edmodo presentationRoxanne Gibbons
 
Unitat 05 geografia_2a_part
Unitat 05 geografia_2a_partUnitat 05 geografia_2a_part
Unitat 05 geografia_2a_partescolalapau
 
production diary
production diary production diary
production diary A_Melodie
 
Презентація:Матеріали до уроків
Презентація:Матеріали до уроківПрезентація:Матеріали до уроків
Презентація:Матеріали до уроківsveta7940
 

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 packrupicon
 
OpenERP Technical Memento V0.7.3
OpenERP Technical Memento V0.7.3OpenERP Technical Memento V0.7.3
OpenERP Technical Memento V0.7.3Borni 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 RailsNyros Technologies
 
Session10-PHP Misconfiguration
Session10-PHP MisconfigurationSession10-PHP Misconfiguration
Session10-PHP Misconfigurationzakieh alizadeh
 
Re-Design with Elixir/OTP
Re-Design with Elixir/OTPRe-Design with Elixir/OTP
Re-Design with Elixir/OTPMustafa 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_iNico Ludwig
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsSu 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 OnMauricio (Salaboy) Salatino
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails AppsRabble .
 
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.0Quang Ngoc
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction PresentationNerd 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 laterHaehnchen
 
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 FrameworkMaher Gamal
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in detailsMax Klymyshyn
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfonySayed 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 DevelopersAzilen 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 TeamsYangJerng 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 businessYangJerng 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-30YangJerng 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 mathYangJerng 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 malaysiaYangJerng Hwa
 
2019 09 web components
2019 09 web components2019 09 web components
2019 09 web componentsYangJerng Hwa
 
Appendix - arc of development
Appendix  - arc of developmentAppendix  - arc of development
Appendix - arc of developmentYangJerng 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 bitsYangJerng Hwa
 
Monolithic docker pattern
Monolithic docker patternMonolithic docker pattern
Monolithic docker patternYangJerng 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 ConsultantsYangJerng Hwa
 
Process for Terminating Employees in Malaysia
Process for Terminating Employees in MalaysiaProcess for Terminating Employees in Malaysia
Process for Terminating Employees in MalaysiaYangJerng Hwa
 
Pour-over Coffee with the EK43
Pour-over Coffee with the EK43Pour-over Coffee with the EK43
Pour-over Coffee with the EK43YangJerng Hwa
 
Intro to Stock Trading for Programmers
Intro to Stock Trading for ProgrammersIntro to Stock Trading for Programmers
Intro to Stock Trading for ProgrammersYangJerng Hwa
 
A Haphazard Petcha Kutcha
A Haphazard Petcha KutchaA Haphazard Petcha Kutcha
A Haphazard Petcha KutchaYangJerng 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

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

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!