https://github.com/thiagoesteves/mserver
Multiple gen_server using the same code (different than simple_one_for_one)
https://github.com/thiagoesteves/mserver
gen-servers mserver supervisor supervisor-tree
Last synced: 2 months ago
JSON representation
Multiple gen_server using the same code (different than simple_one_for_one)
- Host: GitHub
- URL: https://github.com/thiagoesteves/mserver
- Owner: thiagoesteves
- License: apache-2.0
- Created: 2020-01-11T18:28:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-20T14:07:47.000Z (over 4 years ago)
- Last Synced: 2025-02-08T04:38:59.490Z (4 months ago)
- Topics: gen-servers, mserver, supervisor, supervisor-tree
- Language: Erlang
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mserver application #
__Authors:__ Thiago Esteves ([`[email protected]`]([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:
```bash
make
```### Use case: Creating Multiples Mservers ###
The user can create as many gen_servers as needed:
```erlang
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.
```erlang
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
```