增加启动xtcp frpc功能
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.kne.cloud.network.mport.IPPort;
|
||||
import org.kne.cloud.network.mport.ServiceElement;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
public class ProxyJson {
|
||||
private File f;
|
||||
private List<ProxyElement> pls=new ArrayList<>();
|
||||
public List<ProxyElement> getPls() {
|
||||
return pls;
|
||||
}
|
||||
public ProxyJson(File f,STJson def) throws IOException {
|
||||
super();
|
||||
this.f = f;
|
||||
if(!f.exists()||f.length()==0l) {
|
||||
f.createNewFile();
|
||||
JsonWriter jw=null;
|
||||
try {
|
||||
jw=new JsonWriter(new FileWriter(f));
|
||||
jw.setIndent(" ");
|
||||
jw.beginObject();
|
||||
jw.name("services");
|
||||
jw.beginArray();
|
||||
for (Iterator<ServiceElement> iterator = def.getServices().iterator(); iterator.hasNext();) {
|
||||
ServiceElement proxye = (ServiceElement) iterator.next();
|
||||
jw.beginObject();
|
||||
jw.name("name");
|
||||
jw.value(proxye.name);
|
||||
jw.name("protocol");
|
||||
jw.value(proxye.protocol);
|
||||
jw.name("localaddress");
|
||||
jw.value(proxye.ipport.toString());
|
||||
jw.name("bindaddress");
|
||||
jw.value("0.0.0.0:"+proxye.ipport.getPort());
|
||||
jw.endObject();
|
||||
}
|
||||
jw.endArray();
|
||||
jw.endObject();
|
||||
}finally{
|
||||
if(jw!=null)
|
||||
jw.close();
|
||||
}
|
||||
}
|
||||
JsonReader jr=null;
|
||||
try {
|
||||
jr=new JsonReader(new FileReader(f));
|
||||
jr.beginObject();
|
||||
while(jr.hasNext()) {
|
||||
String name=jr.nextName();
|
||||
switch(name) {
|
||||
case "services":
|
||||
jr.beginArray();
|
||||
while(jr.hasNext()) {
|
||||
jr.beginObject();
|
||||
ProxyElement pe=new ProxyElement();
|
||||
ServiceElement se=new ServiceElement();
|
||||
pe.setSe(se);
|
||||
while(jr.hasNext()) {
|
||||
String n3=jr.nextName();
|
||||
switch(n3) {
|
||||
case "name":
|
||||
se.name=jr.nextString();
|
||||
break;
|
||||
case "protocol":
|
||||
se.protocol=jr.nextString();
|
||||
break;
|
||||
case "localaddress":
|
||||
se.ipport=new IPPort (jr.nextString());
|
||||
break;
|
||||
case "bindaddress":
|
||||
pe.setIpport(new IPPort (jr.nextString()));
|
||||
break;
|
||||
default:
|
||||
jr.skipValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
pls.add(pe);
|
||||
jr.endObject();
|
||||
}
|
||||
jr.endArray();
|
||||
break;
|
||||
default:
|
||||
jr.skipValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
jr.endObject();
|
||||
}finally {
|
||||
if(jr!=null)
|
||||
jr.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user