This is my implementation for Bully Algorithm used in Distributed computing
Using peer to peer architecture and java socket programming, Simulating bully algorithm using interprocess communication without using threads or interprocess communication libraries
Multiple instances of your application should run (different processes) and communicate with each other
- check if there's no coordinator in coordinator port
- if there's no coordinator, then current process declares that it's the coordinator
- if there's a coordinator, process sends a message declaring itself,
- Coordinator assigns the new Process a port to listen to
- Coordinator sends a list of alive processes in system to the new process
- Coordinator sends the new process port to the other processes in system
Coordinator sends an alive message for all alive processes each period of time, if any process found that a coordinator failed sends an election message to other processes
Eventually the process with the highest priority - port in our case - wins an election. The winning process will notify all the other running processes that it is the coordinator.
1.Peer
- Bind process to the specified port
- send and receive messages
2.Process
- Has a peer to send and receive messages
- Decode messages to take actions based on bully algorithms, previously explained
- Notify other processes
- Has list of peers of other processes in systems to interact with
3.Message
- a utility class to encapsulate message details
- Has an enum for message type
- Java socket programming