再次优化调度性能
This commit is contained in:
@@ -7,28 +7,57 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class Tunnel {
|
||||
private String name;
|
||||
private IPPort ipport;
|
||||
|
||||
public Tunnel(String name, String ip, int port) throws UnknownHostException {
|
||||
private long delay=-1;
|
||||
public long getDelay() {
|
||||
return delay;
|
||||
}
|
||||
public void setDelay(long delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
private static Map<IPPort,Tunnel> tls=new ConcurrentHashMap<>();
|
||||
private Tunnel(String name, IPPort ipport) throws UnknownHostException {
|
||||
super();
|
||||
this.name = name;
|
||||
this.ipport=new IPPort(ip,port);
|
||||
this.ipport=ipport;
|
||||
}
|
||||
public Tunnel(String s) throws UnknownHostException {
|
||||
public static Tunnel newTunnel(String name, IPPort ipport) throws UnknownHostException {
|
||||
Tunnel tmp=tls.get(ipport);
|
||||
if(tmp!=null) {
|
||||
return tmp;
|
||||
}
|
||||
tmp=new Tunnel(name, ipport);
|
||||
tls.put(ipport, tmp);
|
||||
return tmp;
|
||||
}
|
||||
public static Tunnel newTunnel(String name, String ipport) throws UnknownHostException {
|
||||
|
||||
return newTunnel(name, new IPPort(ipport));
|
||||
}
|
||||
public static Tunnel newTunnel(String name, String ip, int port) throws UnknownHostException {
|
||||
|
||||
return newTunnel(name, new IPPort(ip, port));
|
||||
}
|
||||
|
||||
public static Tunnel newTunnel(String s) throws UnknownHostException {
|
||||
String[]t=s.split("\\$");
|
||||
name=t[0];
|
||||
ipport=new IPPort(t[1]);
|
||||
return newTunnel(t[0], t[1]);
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ipport.getIp().getHostAddress();
|
||||
}
|
||||
@@ -59,7 +88,18 @@ public class Tunnel {
|
||||
Tunnel other = (Tunnel) obj;
|
||||
return Objects.equals(ipport, other.ipport) && Objects.equals(name, other.name);
|
||||
}
|
||||
|
||||
public static void states() {
|
||||
Set<Entry<IPPort, Tunnel>> s=tls.entrySet();
|
||||
for (Iterator iterator = s.iterator(); iterator.hasNext();) {
|
||||
Entry<IPPort, Tunnel> entry = (Entry<IPPort, Tunnel>) iterator.next();
|
||||
Tunnel tll=entry.getValue();
|
||||
System.out.println(tll.getName()+" "+((tll.getDelay()==-1)?"δ֪":tll.getDelay()/1000000+"ms")+" Á¬½ÓÊý"+tll.ati);
|
||||
}
|
||||
}
|
||||
private AtomicInteger ati=new AtomicInteger(0);
|
||||
public AtomicInteger getCCount() {
|
||||
return ati;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user