summaryrefslogtreecommitdiffstats
path: root/gearman/controllerWorker/ControllerWorker/Shutdown.java
diff options
context:
space:
mode:
authorBjörn Geiger2011-08-31 16:36:30 +0200
committerBjörn Geiger2011-08-31 16:36:30 +0200
commita48ca69d5dc7fd00b43c1678fc1d96c3274ab1f5 (patch)
treeb6767f5c8a596f805c256c5c7950b10edd607b16 /gearman/controllerWorker/ControllerWorker/Shutdown.java
parentkleine änderung (diff)
downloadpoolctrl-a48ca69d5dc7fd00b43c1678fc1d96c3274ab1f5.tar.gz
poolctrl-a48ca69d5dc7fd00b43c1678fc1d96c3274ab1f5.tar.xz
poolctrl-a48ca69d5dc7fd00b43c1678fc1d96c3274ab1f5.zip
Client und State nun als eigenes Objekt, Shutdown.java noch nicht ganz angepasst
Diffstat (limited to 'gearman/controllerWorker/ControllerWorker/Shutdown.java')
-rw-r--r--gearman/controllerWorker/ControllerWorker/Shutdown.java127
1 files changed, 49 insertions, 78 deletions
diff --git a/gearman/controllerWorker/ControllerWorker/Shutdown.java b/gearman/controllerWorker/ControllerWorker/Shutdown.java
index 78ab144..8f10e68 100644
--- a/gearman/controllerWorker/ControllerWorker/Shutdown.java
+++ b/gearman/controllerWorker/ControllerWorker/Shutdown.java
@@ -24,7 +24,7 @@ import org.json.simple.JSONValue;
public class Shutdown extends Thread {
private String eventName;
- private Vector<HashMap<String, String>> clients;
+ private Vector<Client> clients;
private final int updateRate;
private long waitTime;
private Vector<String> psWhitelist;
@@ -39,14 +39,12 @@ public class Shutdown extends Thread {
private HashMap<Integer, GearmanJob> psJobs;
private HashMap<Integer, Long> pingShutdownTime;
private HashMap<Integer, Integer> status;
- private HashMap<Integer, String> errors;
- private HashMap<Integer, Boolean> finishedClients;
private Boolean finished;
private Boolean error;
private String[] statusText;
- public Shutdown(String eventName, Vector<HashMap<String, String>> clients,
- int updateRate, long waitTime, Vector<String> psWhitelist,
+ public Shutdown(String eventName, Vector<Client> clients, int updateRate,
+ long waitTime, Vector<String> psWhitelist,
Vector<String> psBlacklist, String gearmanServerAddress,
int gearmanServerPort) {
this.eventName = eventName;
@@ -66,12 +64,9 @@ public class Shutdown extends Thread {
psJobs = new HashMap<Integer, GearmanJob>();
pingShutdownTime = new HashMap<Integer, Long>();
status = new HashMap<Integer, Integer>();
- errors = new HashMap<Integer, String>();
- finishedClients = new HashMap<Integer, Boolean>();
finished = false;
error = false;
statusText = new String[14];
- statusText[0] = "The shutdown process of the client has been started.";
statusText[1] = "The ping has been started.";
statusText[2] = "The client is alive.";
statusText[3] = "The check if a user is logged in has been started.";
@@ -86,11 +81,6 @@ public class Shutdown extends Thread {
statusText[11] = "The user is working.";
statusText[12] = "Shutdown of the client has not been finished, due to an error.";
statusText[13] = "Shutdown of the client has been finished.";
- for (HashMap<String, String> client : clients) {
- int clientID = Integer.parseInt(client.get("id"));
- status.put(clientID, 0); // no work
- finishedClients.put(clientID, false);
- }
}
public void run() {
@@ -126,12 +116,12 @@ public class Shutdown extends Thread {
private Boolean update() throws IllegalStateException, IOException,
InterruptedException, ExecutionException {
- for (HashMap<String, String> client : clients) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
- int clientStatus = status.get(clientID);
+ for (Client client : clients) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
+ int clientState = client.getState();
- switch (clientStatus) {
+ switch (clientState) {
case 0:
ping(client);
@@ -172,9 +162,8 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot send the ping message.");
- errors
- .put(clientID,
- "Sending the ping message has been failed.");
+ client
+ .setError("Sending the ping message has been failed.");
// sending the ping message has been failed
status.put(clientID, 12);
pingJobs.remove(clientID);
@@ -232,9 +221,8 @@ public class Shutdown extends Thread {
System.out
.println(ipAddress
+ " Cannot check if a user is logged in.");
- errors
- .put(clientID,
- "The check if a user is logged in has been failed.");
+ client
+ .setError("The check if a user is logged in has been failed.");
/*
* cannot check if a user is logged in, go in
* errorState
@@ -275,9 +263,8 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot send shutdown command");
- errors
- .put(clientID,
- "Sending the shutdown command has been failed.");
+ client
+ .setError("Sending the shutdown command has been failed.");
/*
* cannot send shutdown command, go in /
* errorState
@@ -342,9 +329,8 @@ public class Shutdown extends Thread {
System.out
.println(ipAddress
+ " Cannot send the ping after shutdown message.");
- errors
- .put(clientID,
- "Sending the ping after shutdown message has been failed.");
+ client
+ .setError("Sending the ping after shutdown message has been failed.");
/*
* sending the ping after shutdown message
* has been failed
@@ -357,8 +343,8 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " is alive after shutdown");
- errors.put(clientID,
- "Client is still alive after shutdown.");
+ client
+ .setError("Client is still alive after shutdown.");
// still alive, go in errorState
status.put(clientID, 12);
pingShutdownJobs.remove(clientID);
@@ -389,7 +375,7 @@ public class Shutdown extends Thread {
.parse(result);
if (!resultObj.containsKey("err")) {
JSONArray ps = (JSONArray) resultObj.get("ps");
- //boolean whitelistFound = false;
+ // boolean whitelistFound = false;
boolean blacklistFound = false;
for (String blackEntry : psBlacklist) {
@@ -398,11 +384,11 @@ public class Shutdown extends Thread {
}
}
- /*for (String whiteEntry : psWhitelist) {
- if (ps.toString().contains(whiteEntry)) {
- whitelistFound = true;
- }
- }*/
+ /*
+ * for (String whiteEntry : psWhitelist) { if
+ * (ps.toString().contains(whiteEntry)) {
+ * whitelistFound = true; } }
+ */
if (blacklistFound) {
/*
@@ -427,9 +413,8 @@ public class Shutdown extends Thread {
} else {
System.out.println(ipAddress
+ " Cannot check if user is working.");
- errors
- .put(clientID,
- "The check if a user is working has been failed.");
+ client
+ .setError("The check if a user is working has been failed.");
/*
* cannot check if user is working, go in
* errorState
@@ -445,25 +430,25 @@ public class Shutdown extends Thread {
case 11:
System.out.println(ipAddress + " User has been working");
- errors.put(clientID, "The user has been working.");
+ client.setError("The user has been working.");
// user has been working, go in errorState
status.put(clientID, 12);
break;
case 12:
- if (!finishedClients.get(clientID)) {
+ if (!client.isFinished()) {
System.out.println(ipAddress + " Shutdown failed"); // errorState
- finishedClients.put(clientID, true);
+ client.finish();
error = true;
}
break;
case 13:
- if (!finishedClients.get(clientID)) {
+ if (!client.isFinished()) {
System.out.println(ipAddress + " Shutdown finished"); // successState
- finishedClients.put(clientID, true);
+ client.finish();
}
break;
@@ -472,10 +457,8 @@ public class Shutdown extends Thread {
}
boolean allFinished = false;
- for (HashMap<String, String> client : clients) {
- int clientID = Integer.parseInt(client.get("id"));
- boolean clientFinished = finishedClients.get(clientID);
- if (clientFinished) {
+ for (Client client : clients) {
+ if (client.isFinished()) {
allFinished = true;
} else {
allFinished = false;
@@ -490,9 +473,9 @@ public class Shutdown extends Thread {
}
}
- private void ping(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
+ private void ping(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("ping", ipAddress.getBytes(),
"ping" + clientID);
@@ -504,9 +487,9 @@ public class Shutdown extends Thread {
System.out.println("ping " + ipAddress);
}
- private void who(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
+ private void who(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("who", ipAddress.getBytes(),
"who" + clientID);
@@ -518,9 +501,9 @@ public class Shutdown extends Thread {
System.out.println("who " + ipAddress);
}
- private void doShutdown(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
+ private void doShutdown(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("doShutdown", ipAddress
.getBytes(), "doShutdown" + clientID);
@@ -532,9 +515,9 @@ public class Shutdown extends Thread {
System.out.println("doShutdown " + ipAddress);
}
- private void pingShutdown(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
+ private void pingShutdown(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("ping", ipAddress.getBytes(),
"ping" + clientID);
@@ -546,9 +529,9 @@ public class Shutdown extends Thread {
System.out.println("ping " + ipAddress);
}
- private void ps(HashMap<String, String> client) {
- String ipAddress = client.get("ip");
- int clientID = Integer.parseInt(client.get("id"));
+ private void ps(Client client) {
+ String ipAddress = client.getIp();
+ int clientID = client.getId();
GearmanJob job = GearmanJobImpl.createJob("ps", ipAddress.getBytes(),
"ps" + clientID);
@@ -560,18 +543,6 @@ public class Shutdown extends Thread {
System.out.println("ps " + ipAddress);
}
- public String getStatusText(HashMap<String, String> client) {
- int clientID = Integer.parseInt(client.get("id"));
- int clientStatus = status.get(clientID);
- return statusText[clientStatus];
- }
-
- public String getError(HashMap<String, String> client) {
- int clientID = Integer.parseInt(client.get("id"));
- String clientError = errors.get(clientID);
- return clientError;
- }
-
public Boolean isFinished() {
return finished && !error;
}
@@ -580,7 +551,7 @@ public class Shutdown extends Thread {
return finished && error;
}
- public Vector<HashMap<String, String>> getClients() {
+ public Vector<Client> getClients() {
return clients;
}