An open API service indexing awesome lists of open source software.

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)

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
```