summaryrefslogtreecommitdiffstats
path: root/gearman/controllerWorker/ControllerWorker/Boot.java
diff options
context:
space:
mode:
authorBjörn Geiger2011-07-27 12:37:37 +0200
committerBjörn Geiger2011-07-27 12:37:37 +0200
commitceaa8457f82107df480e04397aa1f636f55429cb (patch)
tree8f3003bb5e974f5a0985233eccccfdbf60929a14 /gearman/controllerWorker/ControllerWorker/Boot.java
parentminor (diff)
downloadpoolctrl-ceaa8457f82107df480e04397aa1f636f55429cb.tar.gz
poolctrl-ceaa8457f82107df480e04397aa1f636f55429cb.tar.xz
poolctrl-ceaa8457f82107df480e04397aa1f636f55429cb.zip
verschiedene Korrekturen
Diffstat (limited to 'gearman/controllerWorker/ControllerWorker/Boot.java')
-rw-r--r--gearman/controllerWorker/ControllerWorker/Boot.java109
1 files changed, 77 insertions, 32 deletions
diff --git a/gearman/controllerWorker/ControllerWorker/Boot.java b/gearman/controllerWorker/ControllerWorker/Boot.java
index 8481612..74aa828 100644
--- a/gearman/controllerWorker/ControllerWorker/Boot.java
+++ b/gearman/controllerWorker/ControllerWorker/Boot.java
@@ -20,24 +20,27 @@ import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
public class Boot extends Thread {
- private Vector<HashMap<String, String>> clients;
- private GearmanClient gearmanClient;
- private final GearmanJobServerConnection gearmanConnection;
private long beginTime;
private long timeTaken;
private long timeLeft;
private Boolean finished;
- private Boolean finishedWithErrors;
+ private Boolean error;
+ private final int updateRate;
+ private final long updatePeriod;
- static HashMap<Integer, GearmanJob> PING_JOBS = new HashMap<Integer, GearmanJob>();
- static HashMap<Integer, GearmanJob> WOL_JOBS = new HashMap<Integer, GearmanJob>();
- static HashMap<Integer, GearmanJob> SSH_JOBS = new HashMap<Integer, GearmanJob>();
- static HashMap<Integer, Integer> STATUS = new HashMap<Integer, Integer>();
- static final int UPDATE_RATE = 1; // updates per second
- static final long UPDATE_PERIOD = 1000000000L / UPDATE_RATE; // nanoseconds
+ private HashMap<Integer, GearmanJob> pingJobs;
+ private HashMap<Integer, GearmanJob> wolJobs;
+ private HashMap<Integer, GearmanJob> sshJobs;
+ private HashMap<Integer, Integer> status;
+ private HashMap<Integer, Integer> errors;
+
+ private Vector<HashMap<String, String>> clients;
+
+ private final GearmanJobServerConnection gearmanConnection;
+ private GearmanClient gearmanClient;
public Boot(String serverAddress, int port,
- Vector<HashMap<String, String>> clients) {
+ Vector<HashMap<String, String>> clients, int updateRate) {
this.gearmanConnection = new GearmanNIOJobServerConnection(
serverAddress, port);
this.gearmanClient = new GearmanClientImpl();
@@ -45,10 +48,17 @@ public class Boot extends Thread {
this.clients = clients;
for (HashMap<String, String> client : clients) {
int clientID = Integer.parseInt(client.get("id"));
- STATUS.put(clientID, 0); // no work
+ status.put(clientID, 0); // no work
}
this.finished = false;
- this.finishedWithErrors = false;
+ this.error = false;
+ this.pingJobs = new HashMap<Integer, GearmanJob>();
+ this.wolJobs = new HashMap<Integer, GearmanJob>();
+ this.sshJobs = new HashMap<Integer, GearmanJob>();
+ this.status = new HashMap<Integer, Integer>();
+ this.errors = new HashMap<Integer, Integer>();
+ this.updateRate = updateRate; // updates per second
+ this.updatePeriod = 1000000000L / this.updateRate; // nanoseconds
}
public void run() {
@@ -62,7 +72,7 @@ public class Boot extends Thread {
beginTime = System.nanoTime();
run = update();
timeTaken = System.nanoTime() - beginTime;
- timeLeft = (UPDATE_PERIOD - timeTaken) / 1000000;
+ timeLeft = (updatePeriod - timeTaken) / 1000000;
if (timeLeft < 10)
timeLeft = 10;
Thread.sleep(timeLeft);
@@ -82,9 +92,9 @@ public class Boot extends Thread {
String ipAddress = client.get("ip");
String macAddress = client.get("mac");
int clientID = Integer.parseInt(client.get("id"));
- int status = STATUS.get(clientID);
+ int clientStatus = status.get(clientID);
- switch (status) {
+ switch (clientStatus) {
case 0:
ping(client);
@@ -92,7 +102,7 @@ public class Boot extends Thread {
break;
case 1:
- GearmanJob pingJob = PING_JOBS.get(clientID);
+ GearmanJob pingJob = pingJobs.get(clientID);
if (pingJob != null) {
GearmanJobStatus jobStatus = gearmanClient
@@ -110,12 +120,12 @@ public class Boot extends Thread {
if (alive.equals("true")) {
System.out.println(ipAddress + " alive");
- STATUS.put(clientID, 2); // alive
- PING_JOBS.remove(clientID);
+ status.put(clientID, 2); // alive
+ pingJobs.remove(clientID);
} else {
System.out.println(ipAddress + " not alive");
- STATUS.put(clientID, 3); // not alive
- PING_JOBS.remove(clientID);
+ status.put(clientID, 3); // not alive
+ pingJobs.remove(clientID);
}
}
}
@@ -134,7 +144,7 @@ public class Boot extends Thread {
break;
case 4:
- GearmanJob wolJob = WOL_JOBS.get(clientID);
+ GearmanJob wolJob = wolJobs.get(clientID);
if (wolJob != null) {
GearmanJobStatus jobStatus = gearmanClient
.getJobStatus(wolJob);
@@ -147,8 +157,8 @@ public class Boot extends Thread {
if (result.equals("Magic packet send.")) {
System.out
.println(macAddress + "Magic packet send");
- STATUS.put(clientID, 5); // magic packet send
- WOL_JOBS.remove(clientID);
+ status.put(clientID, 5); // magic packet send
+ wolJobs.remove(clientID);
}
}
}
@@ -164,8 +174,11 @@ public class Boot extends Thread {
break;
}
- if (status == 20) {
+ if (clientStatus == 20) {
+ allFinished = true;
+ } else if (clientStatus == 19) {
allFinished = true;
+ this.error = true;
} else {
allFinished = false;
}
@@ -186,8 +199,8 @@ public class Boot extends Thread {
"ping" + clientID);
gearmanClient.submit(job);
- STATUS.put(clientID, 1); // ping started
- PING_JOBS.put(clientID, job);
+ status.put(clientID, 1); // ping started
+ pingJobs.put(clientID, job);
System.out.println("ping " + ipAddress);
}
@@ -200,8 +213,8 @@ public class Boot extends Thread {
"wol" + clientID);
gearmanClient.submit(job);
- STATUS.put(clientID, 4); // wake on lan started
- WOL_JOBS.put(clientID, job);
+ status.put(clientID, 4); // wake on lan started
+ wolJobs.put(clientID, job);
System.out.println("wake on lan " + macAddress);
}
@@ -214,17 +227,49 @@ public class Boot extends Thread {
"ssh" + clientID);
gearmanClient.submit(job);
- STATUS.put(clientID, 6); // ssh started
- SSH_JOBS.put(clientID, job);
+ status.put(clientID, 6); // ssh started
+ sshJobs.put(clientID, job);
System.out.println("ssh " + ipAddress);
}
+ public Vector<HashMap<String, String>> getClients() {
+ return clients;
+ }
+
+ public GearmanClient getGearmanClient() {
+ return gearmanClient;
+ }
+
+ public GearmanJobServerConnection getGearmanConnection() {
+ return gearmanConnection;
+ }
+
+ public HashMap<Integer, GearmanJob> getPingJobs() {
+ return pingJobs;
+ }
+
+ public HashMap<Integer, GearmanJob> getWolJobs() {
+ return wolJobs;
+ }
+
+ public HashMap<Integer, GearmanJob> getSshJobs() {
+ return sshJobs;
+ }
+
+ public HashMap<Integer, Integer> getStatus() {
+ return status;
+ }
+
+ public HashMap<Integer, Integer> getErrors() {
+ return errors;
+ }
+
public Boolean isFinished() {
return finished;
}
public Boolean isFinishedWithErrors() {
- return finishedWithErrors;
+ return finished && error;
}
}