summaryrefslogtreecommitdiffstats
path: root/gearman/controllerWorker/ControllerWorker/Shutdown.java
diff options
context:
space:
mode:
authorSebastian Wagner2011-09-02 16:55:04 +0200
committerSebastian Wagner2011-09-02 16:55:04 +0200
commit3713e55b151c86ae563caf843fa37669c848a7f6 (patch)
tree60ea2358d70fe47ffdc2be6b54530aee196edf89 /gearman/controllerWorker/ControllerWorker/Shutdown.java
parentlog4j implemented (diff)
downloadpoolctrl-3713e55b151c86ae563caf843fa37669c848a7f6.tar.gz
poolctrl-3713e55b151c86ae563caf843fa37669c848a7f6.tar.xz
poolctrl-3713e55b151c86ae563caf843fa37669c848a7f6.zip
all client states now in clientstates.java
Diffstat (limited to 'gearman/controllerWorker/ControllerWorker/Shutdown.java')
-rw-r--r--gearman/controllerWorker/ControllerWorker/Shutdown.java80
1 files changed, 24 insertions, 56 deletions
diff --git a/gearman/controllerWorker/ControllerWorker/Shutdown.java b/gearman/controllerWorker/ControllerWorker/Shutdown.java
index 0973491..e8f5751 100644
--- a/gearman/controllerWorker/ControllerWorker/Shutdown.java
+++ b/gearman/controllerWorker/ControllerWorker/Shutdown.java
@@ -25,9 +25,10 @@ import org.json.simple.JSONValue;
import org.apache.log4j.Logger;
public class Shutdown extends Thread {
+ /*
private static final int CLIENT_INITIALIZED = 0;
private static final int PING_INITIALIZED = 1;
- private static final int CLIENT_IS_ALIVE = 2;
+// private static final int CLIENT_IS_ALIVE = 2;
private static final int WHO_INITIALIZED = 3;
private static final int SHUTDOWN_CLIENT = 4;
private static final int SHUTDOWN_INITIALIZED = 5;
@@ -39,6 +40,7 @@ public class Shutdown extends Thread {
private static final int USER_IS_WORKING = 11;
private static final int ERROR = 12;
private static final int SUCCESS = 13;
+ */
static final Logger logger = Logger.getLogger(Shutdown.class);
@@ -141,26 +143,21 @@ public class Shutdown extends Thread {
if (alive.equals("true")) {
logger.info(client.getIp() + " alive");
- //client.changeState(CLIENT_IS_ALIVE, "CLIENT_IS_ALIVE",
- // "The client is alive.");
- client.setState(States.FOO);
+ client.setState(ClientState.CLIENT_IS_ALIVE);
// check
// Users
pingJobs.remove(client.getId());
} else if (alive.equals("false")) {
logger.info(client.getIp() + " not alive");
// not alive, go in successState
- client.changeState(SUCCESS, "SUCCESS",
- "Shutdown of the client has been finished.");
+ client.setState(ClientState.SUCCESS);
pingJobs.remove(client.getId());
}
} else {
logger.error(client.getIp() + " Cannot send the ping message.");
client.setError("Sending the ping message has been failed.");
// sending the ping message has been failed
- client
- .changeState(ERROR, "ERROR",
- "Shutdown of the client has not been finished, due to an error.");
+ client.setState(ClientState.ERROR);
pingJobs.remove(client.getId());
}
}
@@ -197,14 +194,12 @@ public class Shutdown extends Thread {
if (user.isEmpty()) {
logger.info(client.getIp() + " no user is logged in");
// no user is logged in
- client.changeState(SHUTDOWN_CLIENT, "SHUTDOWN_CLIENT",
- "No user is logged in.");
+ client.setState(ClientState.SHUTDOWN_CLIENT);
whoJobs.remove(client.getId());
} else {
logger.info(client.getIp() + " a user is logged in");
// a user is logged in
- client.changeState(USER_IS_LOGGED_IN, "USER_IS_LOGGED_IN",
- "A user is logged in.");
+ client.setState(ClientState.USER_IS_LOGGED_IN);
whoJobs.remove(client.getId());
}
} else {
@@ -215,9 +210,7 @@ public class Shutdown extends Thread {
/*
* cannot check if a user is logged in, go in errorState
*/
- client
- .changeState(ERROR, "ERROR",
- "Shutdown of the client has not been finished, due to an error.");
+ client.setState(ClientState.ERROR);
whoJobs.remove(client.getId());
}
}
@@ -244,9 +237,7 @@ public class Shutdown extends Thread {
JSONObject resultObj = (JSONObject) JSONValue.parse(result);
if (!resultObj.containsKey("err")) {
logger.info(client.getIp() + " Shutdown command sent");
- client.changeState(SHUTDOWN_COMMAND_SENT,
- "SHUTDOWN_COMMAND_SENT",
- "The shutdown command has been sent.");
+ client.setState(ClientState.SHUTDOWN_COMMAND_SENT);
doShutdownJobs.remove(client.getId());
} else {
logger.error(client.getIp() + " Cannot send shutdown command");
@@ -255,9 +246,7 @@ public class Shutdown extends Thread {
/*
* cannot send shutdown command, go in / errorState
*/
- client
- .changeState(ERROR, "ERROR",
- "Shutdown of the client has not been finished, due to an error.");
+ client.setState(ClientState.ERROR);
doShutdownJobs.remove(client.getId());
}
}
@@ -299,17 +288,12 @@ public class Shutdown extends Thread {
String alive = resultObj.get("alive").toString();
if (alive.equals("false")) {
logger.info(client.getIp() + " is not alive anymore");
- // not alive, go in successState
- client.changeState(SUCCESS, "SUCCESS",
- "Shutdown of the client has been finished.");
+ client.setState(ClientState.SUCCESS);
pingShutdownJobs.remove(client.getId());
} else if (alive.equals("true")) {
logger.info(client.getIp()
+ " is still alive after shutdown command");
- client.changeState(PING_SHUTDOWN_AGAIN,
- "PING_SHUTDOWN_AGAIN",
- "Doing ping after shutdown again and again, until client is not alive or "
- + waitTime / 60 + " minutes has been elapsed");
+ client.setState(ClientState.PING_SHUTDOWN_AGAIN);
}
} else {
logger.error(client.getIp()
@@ -319,9 +303,7 @@ public class Shutdown extends Thread {
/*
* sending the ping after shutdown message has been failed
*/
- client
- .changeState(ERROR, "ERROR",
- "Shutdown of the client has not been finished, due to an error.");
+ client.setState(ClientState.ERROR);
pingJobs.remove(client.getId());
}
}
@@ -330,9 +312,7 @@ public class Shutdown extends Thread {
logger.error(client.getIp() + " is alive after shutdown");
client.setError("Client is still alive after shutdown.");
// still alive, go in errorState
- client
- .changeState(ERROR, "ERROR",
- "Shutdown of the client has not been finished, due to an error.");
+ client.setState(ClientState.ERROR);
pingShutdownJobs.remove(client.getId());
}
}
@@ -382,15 +362,13 @@ public class Shutdown extends Thread {
*
* } else {
*/
- client.changeState(USER_IS_WORKING, "USER_IS_WORKING",
- "The user is working.");
+ client.setState(ClientState.USER_IS_WORKING);
psJobs.remove(client.getId());
// }
} else {
logger.info(client.getIp() + " is not working");
// is not working
- client.changeState(SHUTDOWN_CLIENT, "SHUTDOWN_CLIENT",
- "The User is not working.");
+ client.setState(ClientState.SHUTDOWN_CLIENT);
psJobs.remove(client.getId());
}
} else {
@@ -401,9 +379,7 @@ public class Shutdown extends Thread {
/*
* cannot check if user is working, go in errorState
*/
- client
- .changeState(ERROR, "ERROR",
- "Shutdown of the client has not been finished, due to an error.");
+ client.setState(ClientState.ERROR);
psJobs.remove(client.getId());
}
}
@@ -415,10 +391,7 @@ public class Shutdown extends Thread {
case USER_IS_WORKING:
logger.error(client.getIp() + " User has been working");
client.setError("The user has been working.");
- // user has been working, go in errorState
- client.changeState(ERROR, "ERROR",
- "Shutdown of the client has not been finished, due to an error.");
-
+ client.setState(ClientState.ERROR);
break;
case ERROR:
@@ -462,8 +435,7 @@ public class Shutdown extends Thread {
GearmanJob job = GearmanJobImpl.createJob("ping",
client.getIp().getBytes(), "ping" + client.getId());
gearmanClient.submit(job);
- client.changeState(PING_INITIALIZED, "PING_INITIALIZED",
- "The ping has been intialized.");
+ client.setState(ClientState.PING_INITIALIZED);
pingJobs.put(client.getId(), job);
logger.info("ping " + client.getIp());
}
@@ -472,8 +444,7 @@ public class Shutdown extends Thread {
GearmanJob job = GearmanJobImpl.createJob("who", client.getIp().getBytes(),
"who" + client.getId());
gearmanClient.submit(job);
- client.changeState(WHO_INITIALIZED, "WHO_INITIALIZED",
- "The check if a user is logged in has been intialized.");
+ client.setState(ClientState.WHO_INITIALIZED);
whoJobs.put(client.getId(), job);
logger.info("who " + client.getIp());
}
@@ -482,8 +453,7 @@ public class Shutdown extends Thread {
GearmanJob job = GearmanJobImpl.createJob("doShutdown", client.getIp()
.getBytes(), "doShutdown" + client.getId());
gearmanClient.submit(job);
- client.changeState(SHUTDOWN_INITIALIZED, "SHUTDOWN_INITIALIZED",
- "A shutdown of the client has been triggered.");
+ client.setState(ClientState.SHUTDOWN_INITIALIZED);
doShutdownJobs.put(client.getId(), job);
logger.info("doShutdown " + client.getIp());
}
@@ -492,8 +462,7 @@ public class Shutdown extends Thread {
GearmanJob job = GearmanJobImpl.createJob("ping",
client.getIp().getBytes(), "ping" + client.getId());
gearmanClient.submit(job);
- client.changeState(PING_SHUTDOWN_INITIALIZED, "PING_SHUTDOWN_INITIALIZED",
- "The ping after shutdown has been intialized.");
+ client.setState(ClientState.PING_SHUTDOWN_INITIALIZED);
pingShutdownJobs.put(client.getId(), job);
logger.info("ping " + client.getIp());
}
@@ -502,8 +471,7 @@ public class Shutdown extends Thread {
GearmanJob job = GearmanJobImpl.createJob("ps", client.getIp().getBytes(),
"ps" + client.getId());
gearmanClient.submit(job);
- client.changeState(PS_INITIALIZED, "PS_INITIALIZED",
- "The check if the user is working has been intialized.");
+ client.setState(ClientState.PS_INITIALIZED);
psJobs.put(client.getId(), job);
logger.info("ps " + client.getIp());
}