www.pudn.com > net_root.rar > net.java
import java.io.*;
import java.util.*;
import java.lang.*;
class graphdemo
{
public int[][] graph;
graphdemo()
{
graph= new int[11][17]; //graph[0] no value no define no worth
for (int i=0;i=count) break;
}
}
synchronized void refresh(int count,int[][] buffer,int[] bufferown1)
{
m=0;
for(i=0;i=count) break;
}
}
synchronized int[][] readfrom(int count,int n,int[][] buffer)
{
m=0;
for(i=0;i=count) break;
}
return buffer;
}
}
class queuedemo
{
private int i,j;
public StringBuffer[] queue;
queuedemo()
{
queue= new StringBuffer[17];
for(i=1;i<17;i++)
queue[i]= new StringBuffer(50);
}
synchronized void refresh(int n,StringBuffer s)
{
queue[n].delete(0,49);
queue[n].append(s.toString());
}
synchronized StringBuffer readfrom(int n)
{
return queue[n];
}
}
class Routing extends Thread
{
private boolean done=false;
private int number,i,j,m,n,count=0;
private graphdemo g;
private bufferdemo b;
private queuedemo q;
private int[][] buffer= new int[5][18];
private int[] bufferown1= new int[18];
private int[] bufferown2= new int[18];
private StringBuffer queue= new StringBuffer(50);
Routing(int s,graphdemo g,bufferdemo b,queuedemo q)
{ number=s;
this.g=g;
this.b=b;
this.q=q;
}
synchronized void check()
{
for(i=0;i<5;i++)
for(j=0;j<18;j++)
buffer[i][j]=20; // a number big enough
for(i=0;i<18;i++) bufferown1[i]=bufferown2[i]=20; // a number big enough
i=number;// the smallest number for a thread is 1
for(j=0;j=4)
{
String str=queue.substring(2,4);
Integer nn=new Integer(str);
n= nn.intValue();
if(n>16)
System.out.println("The host does not exist!");
else
{
if(bufferown2[n+1]==20)
System.out.println("Router"+number+": can not reach the destination!");
else{
q.refresh(bufferown2[n+1],queue);
System.out.println("Router"+number+":goto"+bufferown2[n+1]+"\n");
}
}
}
queue.delete(0,49);
}
public synchronized void printbufferown()
{
for(i=0;i<18;i++)
System.out.print(bufferown1[i]);
System.out.println(" ");
for(i=0;i<18;i++)
System.out.print(bufferown2[i]);
System.out.println(" "); }
synchronized boolean ok()
{
return(!done);
}
public void run()
{
check();
while(ok())
{
computepath();
sendpath();
processqueue();
try{
Thread.sleep(100);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
public class net
{
public static void main(String args[])
{
int x,y=0;
graphdemo g= new graphdemo();
bufferdemo b= new bufferdemo();
queuedemo q= new queuedemo();
Routing r1= new Routing(1,g,b,q);
Routing r2= new Routing(2,g,b,q);
Routing r3= new Routing(3,g,b,q);
Routing r4= new Routing(4,g,b,q);
Routing r5= new Routing(5,g,b,q);
Routing r6= new Routing(6,g,b,q);
Routing r7= new Routing(7,g,b,q);
Routing r8= new Routing(8,g,b,q);
Routing r9= new Routing(9,g,b,q);
Routing r10= new Routing(10,g,b,q);
r1.start();
r2.start();
r3.start();
r4.start();
r5.start();
r6.start();
r7.start();
r8.start();
r9.start();
r10.start();
for(int i=0;i<7;i++)
{
System.out.println("Printout refreshed Routing Table every 0.1 second(second0."+i+"):");
for(x=0;x<40;x++)
{
for(y=0;y