/Ricart-Agrawala-Mutex

Implementation of Ricart-Agrawala Distributed Mutual Exclusion algorithm with Roucairol-Carvalho Optimization. O.S.F. Carvalho and G. Roucairol. On Mutual Exclusion in Computer Networks (Technical Correspondence). Communications of the ACM, February 1983.

Primary LanguageJava

Ricart-Agrawala Algorithm with Roucairol-Carvalho Optimization

O.S.F. Carvalho and G. Roucairol. On Mutual Exclusion in Computer Networks (Technical Correspondence). Communications of the ACM, February 1983.


Technical Specs

* Java-8
* Ubuntu
* Shell script

AOS & AOSServer Folder contains the source files for Client & Server respectively


Prerequisites

  • Java-8
  • MultiThreading and Socket Programming
  • Basic Data Structures and Protocol understanding

Description:

This is an interesting algorithm which takes <= 2(N-1) messages to enter the critical Section, unlike Lamports Mutex which utilizes 3(N-1). For more details read Project_1 Description.pdf


Important Note

  1. If you run directly after Unzipping the code, the code should run fine. Check the filePaths and if you have password less login setup.

    automates spawning of terminals without physically entering them
  2. The project is created in Eclipse, therefore launcher.sh and launchServer.sh after execution compiles the code to /bin directory. Change the shell scripts if you don't want it to compile the source code.

  3. Changing UIDs to a different order than 0 1 2 3 4 , throws exception.

  4. Authorize, reply deferred, using, waiting information is implemented as arrays for simplicity, not HashMaps.

  5. The Given code will not work in LocalHost. Check the other branch to test it on the Windows LocalMachine

  6. configAOS.txt should have unique DC Machine as their hostname. Code will not work if 2 UIDs have same hostname

  7. File Server HostName and Ports are harcoded in the RicartAgrawala.java for simplicity

  8. ParseConfigFile.java reads lines from readFile.txt in a specified format. Check the code for more understanding.


Execution

  1. Unzip or clone the project.

  2. Update the respective paths in configAOS.txt & configAOSServer.txt to select the paths for your Servers to host the files (Path should be inside the DC Machine). No need to create directories, code takes care of it. Config files guide the shell script to the locations of each node in the network.

  3. As per the project description Executing the code on DC machines is mandatory. Make sure you have password less login setup before you run the Shell script. Details can be found below. ( To access DC Machines you have to be a UTD Student )

  4. Update the paths inside ParseConfigFile.java, readFile.txt.

  5. Config files and shell scripts will only be in your local machine All the code will reside in the Server. Copying the files in csgrads1 will update the code in all DC machines as DC Machine implements Distributed Shared File System

  6. Push the code in csgrads1.utdallas.edu, by using winscp or sftp

  7. Give executable permission to the scripts

     $chmod +x *.sh
    
  8. Compiles the java code ( You can ignore this step, if you are using launcher.sh and launchServer.sh.
    The shell scripts will compile the code and execute )

    $ cd AOS
    $ javac -cp "./bin" -d "./bin" ./src/*.java
    $ cd ../AOSServer
    $ javac -cp "./bin" -d "./bin" ./src/*.java
  9. "launchServer.sh" will setup the terminals for Server
    "launch.sh" sets up the terminals for Clients
    "cleanup.sh" closes all the ssh connections of the terminals

  10. Open a terminal and go into the directory of shell scripts. Obviously, always launch the Servers first.

    $ ./launchServer.sh 
  11. Open a terminal and go into the directory of shell scripts

    $ ./launch.sh
  12. Terminals will pop up and start executing the code. In the end, view your files in the Server. All the respective files will have the same values.

  13. Open a terminal and go into the directory of shell scripts

    $ ./cleanup.sh

This will terminate all the spawned terminals.

  • The Details of the Project Description can be found in Project_1 Description.pdf

Note: $ is a prompt in the terminal: Ignore $ while copying these commands into the terminal

  1. Open the terminal in your local machine, type
  $ cd
  $ cd .ssh

Now you'll be in the .ssh directory

  1. Type
  $ ssh netid@dc01.utdallas.edu
  1. if prompted,
  Are you sure you want to continue connecting (yes/no)? 

Type yes, then enter

  1. enter password

dc01: will be your current system. 

  1. Type
  $ cd .ssh

Now you'll be in dc01/.ssh directory

  1. Type
  $ ssh-keygen -t rsa

 Just press enter for passphrase … … 
The key fingerprint is: … something … , hit enter
The keys randomart image is: … … (special image), hit enter 

  1. type
  $ cat id_rsa.pub >> authorized_keys
  1. type
  $ exit

Now you'll be in .ssh directory in your local Machine.

  1. type
  $ sftp netid@dc01.utdallas.edu

Enter your password

  1. Type
  sftp> cd .ssh

Now you'll be in dc01/.ssh directory

  1. Type
  sftp> get id_rsa

id_rsa file will be copied into your .ssh directory in local machine

  1. Type
  $ exit

Now you'll be in your local machine

  • You dont have to enter password to enter to any dc machine from your local machine now.

Feedback

Some effort in refactoring can make this code really elegant.
So, I'd appreciate any suggestions