Beruflich Dokumente
Kultur Dokumente
Impement a java program to find the coordinator among the processes based on
the status and priority of the particular process by showing the different stages of
the leader election using bull algorithm.
Code:
import java.io.*;
import java.util.Scanner;
class Anele{
static int n;
n = in.nextInt();
int i,j,k,l,m;
for(i=0;i<n;i++)
System.out.println("Status:");
sta[i]=in.nextInt();
System.out.println("Priority");
pro[i] = in.nextInt();
}
System.out.println("Which process will initiate election?");
elect(ele);
ele = ele-1;
co = ele+1;
for(int i=0;i<n;i++)
if(pro[ele]<pro[i])
if(sta[i]==1)
elect(i+1);
}
2.We have a cluster implemented in ring topology. Write an algorithm to choose the
coordinator node and also a secondary coordinator node if first one goes down.
import java.util.Scanner;
class Process {
int processId;
boolean active;
public RingElection() {
consoleInput = new Scanner(System.in);
}
}
}
}
}
private int getMax(){
int max = 0, indexOfMax = 0;
for(int i = 0; i < NosOfProcess; i++){
if(process[i].active && max <= process[i].processId ) {
max = process[i].processId;
indexOfMax = i;
}
}
return indexOfMax;
}