6 import java.rmi.server.*;
\r
7 import java.rmi.registry.*;
\r
11 static private Registry $reg = null;
\r
12 static private MyDNS $myObject = null;
\r
13 static private MyDNS $root = null;
\r
14 static private Properties $prop = new Properties();
\r
17 static public void main(String[] $args)throws Exception{
\r
18 if($args.length > 1){
\r
19 System.out.println("usage: java Nameserver.Main [<my zone>]");
\r
23 System.out.println("Nameserver starting...");
\r
24 InputStream $in = ClassLoader.getSystemResourceAsStream("registry.properties");
\r
26 System.err.println("ERROR: Properties file not found!");
\r
32 //if no arguments given -> start registry - me is root!
\r
33 if($args.length == 0){
\r
34 System.out.println("ICH bin root, ich darf das!");
\r
35 $reg = LocateRegistry.createRegistry(Integer.parseInt($prop.getProperty("registry.port")));
\r
36 $myObject = new MyDNSImpl();
\r
37 UnicastRemoteObject.exportObject($myObject, 0);
\r
38 $reg.bind("rmi://"+$prop.getProperty("registry.host")+":"+$prop.getProperty("registry.port")+"/"+$prop.getProperty("ro_id"), $myObject);
\r
39 System.out.println($reg);
\r
40 System.out.println(Arrays.toString($reg.list()));
\r
41 System.out.println("MyDNS-ROOT-Object created and registered.");
\r
43 $reg = LocateRegistry.getRegistry($prop.getProperty("registry.host"), Integer.parseInt($prop.getProperty("registry.port")));
\r
44 $root = (MyDNS) $reg.lookup("rmi://"+$prop.getProperty("registry.host")+":"+$prop.getProperty("registry.port")+"/"+$prop.getProperty("ro_id"));
\r
45 $myObject = new MyDNSImpl($args[0]);
\r
46 UnicastRemoteObject.exportObject($myObject, 0);
\r
47 $root.regServiceRecord($myObject);
\r
48 System.out.println("MyDNS-Object created and registered.");
\r
51 System.out.println("Nameserver idle... Hit ENTER for shutdown.");
\r
53 Helper.readByte(System.in);
\r
56 }catch(Exception $e){
\r
57 System.err.println($e.getMessage());
\r
59 System.out.println("Nameserver shutting down...");
\r
60 if($root != null)$root.unregServiceRecord($myObject);
\r
61 UnicastRemoteObject.unexportObject($myObject, true);
\r
62 }catch(Exception $e){
\r
63 System.err.println($e.getMessage());
\r