package worker;

import java.rmi.*;
import java.net.InetAddress;

import bootstrap.Bootstrap;

public class WorkerRegistration
{
  static Remote stub;

  public static void main(String[] args)
  {
    try {
      System.out.println("Usage: java WorkerRegistration  [host]  [worker name]"  );
      System.out.println("Registering Worker " + args[1]  );
      WorkerImpl worker = new WorkerImpl();
      //Naming.rebind("rmi://localhost:1099/timeservice.TimeService", tsi);

      String host = args[0];
      String port = "1099";
      String srv  = "Bootstrap";
      String url = "rmi://" + host + ":" + port + "/" + srv;
      System.out.println("Looking-up Bootstrap " + url);

      Bootstrap bs = (Bootstrap) Naming.lookup(url); 

      System.out.println("Looking-up Bootstrap done...");
      System.out.println("Bootstrap-Version: " + bs.getVersion() );

      stub = (Remote) worker;

      bs.registerWorker("Worker " + args[1] + " "  + InetAddress.getLocalHost().getHostName(), stub);


      System.out.println("Registration done.");
    } catch (Exception e) {
      System.err.println(e.toString());
      System.exit(1);
    }
  }
}
