+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

vijaygarg1init2227200

master
1.2 KiB33 linesraw
1package name;
2import java.rmi.*;
3import java.rmi.server.UnicastRemoteObject;
4import java.net.*;
5public class NameServiceImpl extends UnicastRemoteObject
6        implements NameService {
7    NameTable table;
8    public NameServiceImpl() throws RemoteException {
9	table = new NameTable();
10    }
11    public synchronized InetSocketAddress search(String s) throws RemoteException {
12        return table.search(s);
13    }
14    public synchronized InetSocketAddress blockingFind(String s) throws RemoteException {
15        return table.blockingFind(s);
16    }
17    public synchronized int insert(String s, String hostName, int portNumber)
18            throws RemoteException {
19            return table.insert(s, hostName, portNumber);
20    }
21    public static void main(String args[]) {
22        // create security manager
23        System.setSecurityManager(new RMISecurityManager());
24        try {
25            NameServiceImpl obj = new NameServiceImpl();
26            Naming.rebind("MyNameServer", obj);
27            System.out.println("MyNameServer bound in registry");
28        } catch (Exception e) {
29            System.out.println("NameServiceImpl err: " + e.getMessage());
30        }
31    }
32}
33