Initial commit
This commit is contained in:
75
src/com/flaremicro/crossjeeves/CrossJeevesMain.java
Normal file
75
src/com/flaremicro/crossjeeves/CrossJeevesMain.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package com.flaremicro.crossjeeves;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.flaremicro.util.Util;
|
||||
|
||||
public class CrossJeevesMain {
|
||||
public static void main(String[] args) {
|
||||
Map<String, String> parsedArgs = Util.parseArgs(args, true, true);
|
||||
if (parsedArgs.containsKey("host"))
|
||||
{
|
||||
try
|
||||
{
|
||||
int port = Integer.parseInt(parsedArgs.get("host"));
|
||||
CrossJeevesHost host = new CrossJeevesHost(port);
|
||||
host.startHosting();
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
System.out.println("Invalid port specified: " + parsedArgs.get("host"));
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
else if (parsedArgs.containsKey("agent"))
|
||||
{
|
||||
if(!parsedArgs.containsKey("script"))
|
||||
{
|
||||
System.out.println("'script' argument must be specified for agent.");
|
||||
System.exit(1);
|
||||
}
|
||||
String[] agents = parsedArgs.get("agent").split("\\s");
|
||||
List<AgentInfo> agentList = new ArrayList<AgentInfo>();
|
||||
for(String agent : agents)
|
||||
{
|
||||
String agentArgs[] = agent.split("\\+");
|
||||
if(agentArgs.length == 0)
|
||||
{
|
||||
System.out.println("IP must be specified");
|
||||
System.exit(1);
|
||||
}
|
||||
String ipStr = args[0];
|
||||
String portStr = "10801";
|
||||
if(args.length >= 2)
|
||||
portStr = args[1];
|
||||
try
|
||||
{
|
||||
int port = Integer.parseInt(portStr);
|
||||
InetAddress inetAddress = InetAddress.getByName(ipStr);
|
||||
agentList.add(new AgentInfo(inetAddress, port));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
System.out.println("Invalid port specified: " + portStr);
|
||||
System.exit(1);
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
{
|
||||
System.out.println("Unknown host: " + ipStr);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
CrossJeevesClient client = new CrossJeevesClient(agentList, parsedArgs.get("script"));
|
||||
client.beginJob();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Argument 'host' or 'agent' must be specified.");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user