Commit 2577b74a authored by Ali Saeed's avatar Ali Saeed

Update OnElectionAction class to launch grpc server in leader case

parent f0d41f49
package Registration_Discovery;
import org.apache.zookeeper.KeeperException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class OnElectionAction implements OnElectionCallback {
public class OnElectionAction implements OnElectionCallback {
private final ServiceRegistry serviceRegistry;
private final int port;
public OnElectionAction(ServiceRegistry serviceRegistry, int port) {
this.serviceRegistry = serviceRegistry;
this.port = port;
}
@Override
public void onElectedToBeLeader() {
serviceRegistry.unregisterFromCluster();
serviceRegistry.registerForUpdates();
Leader leader = new Leader(port, serviceRegistry);
try {
leader.start();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
GrpcServerLauncher.start();
}
@Override
public void onWorker() {
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment