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