forked from KNEMC/KLALB
再次优化调度性能
This commit is contained in:
@@ -4,14 +4,18 @@ import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.Socket;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class KLALBServer {
|
||||
WeakHashMap<UUID, IOThreadManager> whm=new WeakHashMap<>();
|
||||
public KLALBServer(int port, List<ServiceElement> services,List<Tunnel> tunnels) throws IOException {
|
||||
public KLALBServer(int port, Map<String,ServiceElement> services,List<Tunnel> tunnels) throws IOException {
|
||||
TCPListener tcpl=new TCPListener(port);
|
||||
tcpl.setCon((s)->{
|
||||
try {
|
||||
@@ -25,10 +29,11 @@ public class KLALBServer {
|
||||
int x=din.read();
|
||||
if(x==0) {
|
||||
synchronized (services) {
|
||||
int counts=services.size();
|
||||
tcc.getDout().writeInt(counts);
|
||||
for (int i = 0; i < counts; i++) {
|
||||
tcc.getDout().writeUTF(services.get(i).toString());
|
||||
tcc.getDout().writeInt(services.size());
|
||||
Collection<ServiceElement> cll=services.values();
|
||||
for (Iterator<ServiceElement> iterator = cll.iterator(); iterator.hasNext();) {
|
||||
ServiceElement tunnel = iterator.next();
|
||||
tcc.getDout().writeUTF(tunnel.toString());
|
||||
}
|
||||
}
|
||||
synchronized (tunnels) {
|
||||
@@ -41,10 +46,21 @@ public class KLALBServer {
|
||||
tcc.getDout().flush();
|
||||
return;
|
||||
}
|
||||
|
||||
String lip=din.readUTF();
|
||||
int lport=din.readInt();
|
||||
String lname=din.readUTF();
|
||||
ServiceElement eas=services.get(lname);
|
||||
System.out.println(eas);
|
||||
|
||||
if(eas==null||(!eas.ipport.equals(new IPPort(lip, lport)))){
|
||||
return;
|
||||
}
|
||||
|
||||
String name = din.readUTF();
|
||||
String ip = din.readUTF();
|
||||
int portx=din.readInt();
|
||||
Tunnel tll=new Tunnel(name, ip, portx);
|
||||
Tunnel tll=Tunnel.newTunnel(name, ip, portx);
|
||||
tcc.setTunnel(tll);
|
||||
|
||||
UUID uid=new UUID(din.readLong(),din.readLong());
|
||||
@@ -55,7 +71,7 @@ public class KLALBServer {
|
||||
nx=whm.get(uid);
|
||||
}else {
|
||||
nx=new IOThreadManager();
|
||||
Socket soc=new Socket("192.168.1.233",8444);
|
||||
Socket soc=new Socket("192.168.1.233",eas.ipport.getPort());
|
||||
nx.setLocal(new TCPConnection(null, soc));
|
||||
nx.startLocal();
|
||||
whm.put(uid, nx);
|
||||
|
||||
Reference in New Issue
Block a user