Merge pull request #11 from Rasha-Dj/rasha/naming-service-fix

Rasha/naming service fix
This commit is contained in:
zenon 2021-01-07 12:53:21 +01:00 committed by GitHub
commit cd88e01b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,7 +47,7 @@ public class Nameserver implements INameserver {
// Root Nameserver
nameServerLocal = new NameServerRemote("root");
try {
nameserverRemote = (INameserverRemote) UnicastRemoteObject.exportObject(nameServerLocal, registryPort);
nameserverRemote = (INameserverRemote) UnicastRemoteObject.exportObject(nameServerLocal, 0);
registry = LocateRegistry.createRegistry(registryPort);
registry.rebind(registryName, nameserverRemote);
System.out.println("Nameserver bound.");
@ -62,6 +62,7 @@ public class Nameserver implements INameserver {
try {
registry = LocateRegistry.getRegistry(registryHost, registryPort);
nameserverRemote = (INameserverRemote) registry.lookup(registryName);
UnicastRemoteObject.exportObject(nameServerLocal, 0);
nameserverRemote.registerNameserver(domain, nameServerLocal);
} catch (RemoteException | NotBoundException e) {
e.printStackTrace();
@ -107,20 +108,20 @@ public class Nameserver implements INameserver {
public void shutdown() {
// shell is already interrupted
// so just close other things
try {
UnicastRemoteObject.unexportObject(nameServerLocal, true);
} catch (NoSuchObjectException e) {
e.printStackTrace();
}
if (this.componentId.equals("ns-root")) {
try {
registry.unbind(registryName);
UnicastRemoteObject.unexportObject(nameServerLocal, true);
} catch (RemoteException e) {
e.printStackTrace();
} catch (NotBoundException e) {
this.registry.unbind(registryName);
UnicastRemoteObject.unexportObject(this.registry, true);
} catch(RemoteException | NotBoundException e){
e.printStackTrace();
}
} else {
this.nameservers();
System.out.println("Zone Nameserver...");
}
System.out.println("Nameserver shut down successfully!");
}
public static void main(String[] args) throws Exception {