7 public class MyDNSImpl implements MyDNS{
\r
8 private String $myName = null;
\r
9 private final int $myServiceType = 1; //1 == DNS, 2 == FS
\r
10 private HashMap<String,MyBase> $myRecords = new HashMap<String,MyBase>();
\r
13 public MyDNSImpl()throws RemoteException{}
\r
15 public MyDNSImpl(String $pmyName)throws RemoteException{
\r
16 System.out.println("New DNS-Object:"+$pmyName);
\r
20 public String getMyName()throws RemoteException{
\r
23 public int getMyType()throws RemoteException{
\r
24 return $myServiceType;
\r
27 public MyBase getServiceRecord(String $name)throws RemoteException{
\r
28 System.out.println("getServiceRecord for:"+$name);
\r
29 MyBase $temp = $myRecords.get($name);
\r
31 System.out.println("NODE UNKNOWN");
\r
32 throw new RemoteException("NODE UNKNOWN:"+$name);
\r
37 public void regServiceRecord(MyBase $rec)throws RemoteException{
\r
38 String $temp[] = $rec.getMyName().split("\\.");
\r
39 System.out.println("registration attempt from: "+$rec.getMyName());
\r
40 if($myRecords.containsKey($temp[0])){
\r
41 System.out.println("Allready registered!");
\r
42 throw new RemoteException("ALLREADY REGISTERED!");
\r
44 int $lvl = $temp.length;
\r
45 int $mylvl = 0; //rootserver has lvl 0 and no name!
\r
46 if($myName != null)$mylvl = ($myName.split("\\.")).length;
\r
47 System.out.println($lvl+"lvl/mylvl"+$mylvl);
\r
48 if($lvl == $mylvl+1){ //level ok - i take you!
\r
49 $myRecords.put($temp[0], $rec);
\r
50 System.out.println("accepted registration from: "+$rec.getMyName()+" of type:"+$rec.getMyType());
\r
51 }else{ //Your level is deeper - I will pass you to the next node!
\r
52 MyDNS $nextRec = (MyDNS) getServiceRecord($temp[($temp.length-1-$mylvl)]);
\r
53 System.out.println("passing down to: "+$nextRec.getMyName());
\r
54 $nextRec.regServiceRecord($rec);
\r
58 public void unregServiceRecord(MyBase $rec)throws RemoteException{
\r
59 String $temp[] = $rec.getMyName().split("\\.");
\r
60 System.out.println("unregistration attempt from: "+$rec.getMyName());
\r
61 int $lvl = $temp.length;
\r
62 int $mylvl = 0; //rootserver has lvl 0 and no name!
\r
63 if($myName != null)$mylvl = ($myName.split("\\.")).length;
\r
64 if($lvl == $mylvl+1){ //level ok - ill unreg you!
\r
65 if(!$myRecords.containsValue($rec)){
\r
66 System.out.println("Not a registered object");
\r
67 throw new RemoteException("Not a registered object!");
\r
69 $myRecords.remove($temp[0]);
\r
70 System.out.println("sucessful unregistration from: "+$rec.getMyName()+" of type:"+$rec.getMyType());
\r
71 }else{ //Your level is deeper - I will pass you to the next node!
\r
72 MyDNS $nextRec = (MyDNS) getServiceRecord($temp[($temp.length-1-$mylvl)]);
\r
73 System.out.println("passing down to: "+$nextRec.getMyName());
\r
74 $nextRec.unregServiceRecord($rec);
\r