SlideShare uma empresa Scribd logo
1 de 9
Baixar para ler 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!

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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.
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 

Último (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

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!