Question

in erlang otp when making a gen_server:call(), you have to send in the name of the node, to which you are making the call.

Lets say I have this usecase:

I have two nodes: 'node1' and 'node2' running. I can use those nodes to make gen_server:call() to each other.

Now lets say I added 2 more nodes: 'node3' and 'node4' and pinged each other so that all nodes can see and make gen_server:calls to each other.

How do the erlang pros handle the dynamic adding of new nodes like that so that they know the new node names to enter into the gen_server calls, or is it a requirement to know beforehand the names of all the nodes so that they are hardcoded in somewhere like the sys.config?

Was it helpful?

Solution

you can use: erlang:nodes() to get a "now" view of the node list

Also, you can use: net_kernel:monitor_nodes(true) to be notified as nodes come and go (via ping / crash / etc)

To see if your module is running on that node you can either call the gen_server with some kind of ping callback

That, or you can use the rpc module to call erlang:whereis(name) on the foreign node.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top