package org.greenstone.p2p;

import java.net.URL;
import java.util.*;

public class GreenstoneTest implements GreenstoneClient
{ String name;
  URL    url;
  
  public GreenstoneTest(String id, String url)
  { try {
      this.url = new URL(url);
    }
    catch (java.net.MalformedURLException malEx)
      { this.url = null;
      }
    this.name = id;
  }

  public void receiveResponse(NameServerAction action, ClientResponse response)
  {
    System.out.println("\n----\nReceived a response:");
    System.out.println(response.toString());
  }

  public void receiveMessage(String message, Map parameters)
  {
  }

  public String getIdentifier()
  { return this.name;
  }

  public URL getURL()
  { return this.url;
  }

  /**
   *  arg[0] => identifier for this machine
   *  arg[1] => a url for this machine
   *  arg[2] => a url for the GDS server
   *
   * e.g. run with:
   * "java org.greenstone.p2p.GreenstoneTest localhost http://localhost http://www.nzdl.org"
   */
  public static void main(String args[])
  { GreenstoneClient client = new GreenstoneTest(args[0], args[1]);
    GreenstoneClient gsdl   = new GreenstoneTest("gsdl", "http://www.gsdl.org");
    
    URL server;
    try
      {
	server = new URL(args[2]);
      }
    catch (java.net.MalformedURLException malEx)
      { server = null;
      }
    
    GreenstoneInterface gsdlIface = new GreenstoneInterface(gsdl);
    gsdlIface.registerWithServer(server);

    GreenstoneInterface iface = new GreenstoneInterface(client);
    iface.registerWithServer(server);

    Map parameters = new HashMap();
    iface.sendMessage("ListServers", parameters);

    iface.sendMessage("DocDelta", parameters);
  }
}