// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.ArrayList;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class ServerImpl extends UnicastRemoteObject implements Server {
   private ArrayList list;
   public ServerImpl() throws RemoteException {
      list = new ArrayList();
   }
   public String dup(String s) throws RemoteException {
      synchronized(list) {
         for(int i = 0; i < list.size(); i++) {
            Client c = (Client)list.get(i);
            c.notify("Someone is dupping " + s);
         }
      }
      return (s + s);
   }
   public void register(Client c) {
      synchronized(list) {
        list.add(c);
      }
   }
   public static void main(String[] args) {
      try {
         Naming.rebind("test", new ServerImpl());
      } catch (RemoteException e) {
         e.printStackTrace();
      } catch (MalformedURLException e) {
         e.printStackTrace();
      }
   }
}
