last condition doesn't validate.
package com.codegym.task.task32.task3208;
import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
/*
RMI (part 2)
*/
public class Solution {
public static Registry registry;
// Pretend we're starting an RMI client as the CLIENT_THREAD thread
public static Thread CLIENT_THREAD = new Thread(new Runnable() {
@Override
public void run() {
try {
for (String bindingName : registry.list()) {
Animal service = (Animal) registry.lookup(bindingName);
service.printName();
service.speak();
}
System.exit(0);
} catch (RemoteException e) {
e.printStackTrace();
} catch (NotBoundException e) {
e.printStackTrace();
}
}
});
// Pretend we're starting an RMI server as the SERVER_THREAD thread
public static Thread SERVER_THREAD = new Thread(new Runnable() {
@Override
public void run() {
//write your code here
Animal cat = new Cat("Cat");
Animal dog = new Dog("Dog");
try {
registry = LocateRegistry.createRegistry(2099);
Remote catRemote = UnicastRemoteObject.exportObject(cat,0);
registry.bind("cat.re",catRemote);
Remote dogRemote = UnicastRemoteObject.exportObject(dog,0);
registry.bind("dog.re",dogRemote);
} catch (RemoteException e) {
e.printStackTrace();
} catch (AlreadyBoundException e) {
e.printStackTrace();
}
}
});
public static void main(String[] args) throws InterruptedException {
// Starting an RMI server thread
SERVER_THREAD.start();
Thread.sleep(1000);
// Start the client
CLIENT_THREAD.start();
}
}