forked from KNEMC/KLALB
自动获得节点地址功能
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class KLALBSM {
|
||||
public static List<ServiceElement> services=new ArrayList<ServiceElement>();
|
||||
|
||||
public static List<Tunnel> tunnels=new ArrayList<Tunnel>();
|
||||
public static void main(String[] args) throws IOException {
|
||||
File f=new File("klalbs.ini");
|
||||
if(!f.exists()) {
|
||||
f.createNewFile();
|
||||
ept();
|
||||
return;
|
||||
}
|
||||
if(f.length()<=0) {
|
||||
ept();
|
||||
return;
|
||||
}
|
||||
Scanner scn=new Scanner(f);
|
||||
int remp=scn.nextInt();
|
||||
System.out.println("KNE云负载均衡调度软件服务端V0.1");
|
||||
System.out.println("开放端口:"+remp);
|
||||
int x=0;
|
||||
System.out.println("服务列表:");
|
||||
while(scn.hasNext() ) {
|
||||
String s=scn.next();
|
||||
if(">".equals(s)) {
|
||||
x++;
|
||||
System.out.println("隧道列表:");
|
||||
continue;
|
||||
}
|
||||
switch(x) {
|
||||
case 0:
|
||||
ServiceElement se=new ServiceElement(s);
|
||||
System.out.println(se);
|
||||
services.add(se);
|
||||
break;
|
||||
case 1:
|
||||
Tunnel t=new Tunnel(s);
|
||||
System.out.println(t);
|
||||
tunnels.add(t);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
scn.close();
|
||||
new KLALBServer(remp,services,tunnels);
|
||||
System.out.println("提示:运行时输入reload可以重新加载配置文件,已经建立的TCP连接不受影响(暂不支持修改开放端口)");
|
||||
Scanner scn2=new Scanner(System.in);
|
||||
while(true) {
|
||||
String command=scn2.next();
|
||||
switch(command) {
|
||||
case "reload":
|
||||
synchronized (services) {
|
||||
synchronized(tunnels) {
|
||||
scn=new Scanner(f);
|
||||
services.clear();
|
||||
tunnels.clear();
|
||||
remp=scn.nextInt();
|
||||
x=0;
|
||||
System.out.println("服务列表:");
|
||||
while(scn.hasNext() ) {
|
||||
String s=scn.next();
|
||||
if(">".equals(s)) {
|
||||
x++;
|
||||
System.out.println("隧道列表:");
|
||||
continue;
|
||||
}
|
||||
switch(x) {
|
||||
case 0:
|
||||
ServiceElement se=new ServiceElement(s);
|
||||
System.out.println(se);
|
||||
services.add(se);
|
||||
break;
|
||||
case 1:
|
||||
Tunnel t=new Tunnel(s);
|
||||
System.out.println(t);
|
||||
tunnels.add(t);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
scn.close();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ept() {
|
||||
System.out.println("请填写配置文件后再启动程序!");
|
||||
System.out.println("格式:");
|
||||
System.out.println("开放端口");
|
||||
System.out.println("服务协议1$服务地址1$服务端口1");
|
||||
System.out.println("服务协议2$服务地址2$服务端口2");
|
||||
System.out.println("......");
|
||||
System.out.println("服务协议n$服务地址n$服务端口n");
|
||||
System.out.println(">");
|
||||
System.out.println("隧道名称1$隧道地址1$隧道端口1");
|
||||
System.out.println("隧道名称2$隧道地址2$隧道端口2");
|
||||
System.out.println("......");
|
||||
System.out.println("隧道名称n$隧道地址n$隧道端口n");
|
||||
System.out.println("");
|
||||
System.out.println("按照顺序从上向下匹配,若都不是则匹配最后一个");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user