KLALB完全大重写,代码规范了,可以当作网络库使用
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.net.Inet6Address;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class SendTask extends TimerTask {
|
||||
private int maxcount;
|
||||
private int count;
|
||||
private int priority;
|
||||
private Inet6Address address;
|
||||
public SendTask( KLALBController controllker,Inet6Address address,DATATPacket kp,int priority,int maxcount) {
|
||||
super();
|
||||
this.maxcount = maxcount;
|
||||
this.controllker = controllker;
|
||||
this.kp = kp;
|
||||
this.address=address;
|
||||
this.priority=priority;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public KLALBController getControllker() {
|
||||
return controllker;
|
||||
}
|
||||
|
||||
|
||||
public DATATPacket getKp() {
|
||||
return kp;
|
||||
}
|
||||
|
||||
|
||||
private KLALBController controllker;
|
||||
private DATATPacket kp;
|
||||
|
||||
|
||||
public int getMaxcount() {
|
||||
return maxcount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
controllker.sendPacketToAddress((Inet6Address) address,
|
||||
kp, priority+count);
|
||||
} catch (NoRouteToHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
count++;
|
||||
if(count>1) {
|
||||
System.out.println("重传:"+kp);
|
||||
}
|
||||
if(count>=maxcount) {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
public void addToTimer(int timeout) {
|
||||
controllker.getTimer().scheduleAtFixedRate(this, 0, timeout);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user