SlideShare una empresa de Scribd logo
1 de 9
Descargar para leer sin conexión
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!

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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 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.
 

Similar 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
 

Más 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
 

Más 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

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Último (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

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!