Coder Social home page Coder Social logo

thiagoesteves / mserver Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 8 KB

Multiple gen_server using the same code (different than simple_one_for_one)

License: Apache License 2.0

Makefile 0.78% Erlang 99.22%
mserver supervisor gen-servers supervisor-tree

mserver's Introduction

Mserver application

Authors: Thiago Esteves ([email protected]).

Note

The Mserver application is dependent on GPROC library and rebar3

Introduction

This is just an simple example of how to handle multiple gen_servers that are using the exactly same code and are under the same supervisor (this is a different approach than simple_one_for_one)

Running application

In order to execute the application just call make:

make

Use case: Creating Multiples Mservers

The user can create as many gen_servers as needed:

1> mserver_sup:create_mserver(0).
{ok,<0.149.0>}
2> mserver_sup:create_mserver(1).
{ok,<0.151.0>}
3> mserver_sup:create_mserver(2).
{ok,<0.153.0>}
4> mserver_sup:create_mserver(3).
{ok,<0.155.0>}
5> mserver:find_me(0).
[CALL] I'm here, State: 0
 ok
6> mserver:show_yourself(0).
[CAST] I'm here, State: 0
 ok
7> mserver_sup:remove_mserver(0).
ok
8> mserver:find_me(0).
{error,invalid_mserver}

Supervisor tree

The supervisor tree of all gen_servers created can be easily viewed with the observer, try the sequence of commands below and have a look at the Applications->mserver.

1> mserver_sup:create_mserver(0).
{ok,<0.149.0>}
2> mserver_sup:create_mserver(1).
{ok,<0.151.0>}
3> mserver_sup:create_mserver(2).
{ok,<0.153.0>}
4> mserver_sup:create_mserver(3).
{ok,<0.155.0>}
5> observer:start().
ok

mserver's People

Contributors

thiagoesteves avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.