import java.util.*; import java.net.*; public class NameTable { class NameEntry { public String procName; public InetSocketAddress addr; public NameEntry(String pName, String host, int port){ procName = pName; addr = new InetSocketAddress(host, port); } } ArrayList<NameEntry> table = new ArrayList<NameEntry>(); public synchronized InetSocketAddress search(String s) { for (NameEntry entry: table) if (s.equals(entry.procName)) return entry.addr; return null; } public synchronized int insert(String s, String hostName, int portNumber) { InetSocketAddress old = search(s); // is it already there if (old == null) { table.add(new NameEntry(s,hostName, portNumber)); return 1; } else // already there return 0; } public synchronized void clear() { table.clear(); } }