I'm developing in java a distributed system where a server collect statistics from a net of edge nodes (that receive measurements from sensors). I have to implement an architecture for data collection where edge nodes are organized as a tree. The tree root is the edge node responsible of sending statistics to server, leaves are nodes who receive measurements from sensors, intermediate nodes of the tree are edge nodes who make intermediate aggregation of data for sending them to their parents. The tree structure must be dynamic, nodes can be added and removed everytime: if a leaf exits there are no problem, if an intermediate node exits, his sons have to ask to server who is their new parent, if the root node exits, edge nodes must elect a new root node and comunicate the result to server that will have to re-build the tree.
Do you have any idea of how to implement this structure?
Thanks!