RandomInteger class, which is responsible for generate random integer between a determined range. send/receive object, the former sends UDP message to other nodes while the later receives UDP message from other nodes.
IfPortUsed class, which assigns UDP ports and make sure that each port is unique.
Node class, which is regarded as a node and stores the version of message. It chooses a neighbor randomly to send its message per 0.5~1.5 sec by calling send and receive its neighbor’s message by calling receive. Then it compare the version of message it stores with the one it received from its neighbor just now to update to version, which means the node replace the message if the version of it is older than the one from other node.
Seed class, which executes every 8 seconds to select a node randomly and increment the version number of its message.
PrintInfo class, which prints the version of all the nodes per-sec.
We generate nine ports that are different from each other and then bind them to nine sockets which are assigned to nine nodes. Each node runs on a single thread which create two threads one sends UDP message to its neighbor and another is responsible for receive message and update its version to the higher one. Create a thread to run a seed object which select a node randomly per 8 seconds and update its message version.
Figure1 shows the topology of the cluster, which has nine nodes and eleven edges. Open the command window and run the executable jar file, Figure2 shows the results, as you can see, it updates the message version of one of the nodes and it spreads like epidemics to other nodes in the cluster.
A gossip protocol is a procedure or process of computer-computer communication that is based on the way social networks disseminate information or how epidemics spread
- Adding new message to the cluster.
- The scale of cluster, the loss rate of udp, the sparsity of the graph are adjustable,
- Destroying the hosts and repairing the hosts dynamically.
- Adding more hosts to cluster dynamically
It's almost impossible to create thousands of threads and communicate by UDP, so we use a special way to make it.
- Creating a class named Host and every host is a object of it. It has attributes as follow:
- Id distinguish one host form others
- Friends contains all the host it can reach
- Crashed is the state of host
- Version is the highest version of message the host have
by these attributes are not enough, because it can not sending message, as mentioned before, implementing sending message by threads and UDP is difficult to achieve, so we need another class to help the hosts with sending message.
- Creating a class named God, it contains all the hosts, a message creator who collect the messages from the hosts, a message handler who helps the hosts with handing message. God also has the ability to adding new message to the cluster, randomly make some hosts crash down and repaired.
x-Axis : the epoch
y-Axis : the number of hosts
The line chart shows as cluster running, the numbers of hosts affected by different messages.
By Init, the cluster is created.
If the cluster is running or freezing, Init will clear all the data
and is ready to run.
Adding a new Message to the cluster.
You can add new messages before the cluster run or add new messages when the cluster is already running. The Different message has are showed with different color. Having finished initializing the cluster, all the hosts contains a message numbered -1.Let the cluster run.
After Init or Freeze the cluster, Run is necessary to make cluster alive.
Freeze the cluster
Init and Run the cluster.
Make some hosts can not sending and receiving any message.
The input should be a number, if input is negative or zero, the actions will be ignored, if the number exceed the alive hosts, all the hosts will be destroyed. It's not guaranteed that the graph is still strongly connected.
Revive already destroyed hosts.
The input should be a number, if input is negative or zero, the actions will be ignored, if the number exceed the dead hosts, all the hosts will be alive.
Add more hosts to the cluster
Added hosts will not change the sparsity of cluster.
Save the present configuration to the file.
Load the present configuration to the file.
Create a new cluster
After press the Button OK, If the configuration pane disappear, then the input is legal, otherwise it's illegal.Empty input means use present parameter.