Node shutdown now uses halt()

This commit is contained in:
aum
2005-04-21 03:10:16 +00:00
committed by zzz
parent 84779002fb
commit 739f694cfe
3 changed files with 36 additions and 5 deletions

View File

@ -157,6 +157,8 @@ public abstract class QNode extends Thread
*/
public String nodeType = "(base)";
public boolean isRunning;
// ----------------------------------------------------------
// CONSTRUCTORS
@ -580,6 +582,13 @@ public abstract class QNode extends Thread
System.out.println("scheduleStartupJobs: c<p="+updateCatalogFromPeers+", isClient="+isClient);
}
public void scheduleShutdown()
{
Hashtable job = new Hashtable();
job.put("cmd", "shutdown");
runAfter(1000, job, "shutdown");
}
public void schedulePeerUploadJob(QDataItem item)
{
String uri = (String)item.get("uri");
@ -790,6 +799,8 @@ public abstract class QNode extends Thread
{
log.info("Starting background tasks");
isRunning = true;
// mark our start time
nodeStartTime = new Date();
@ -833,7 +844,7 @@ public abstract class QNode extends Thread
// fetch items from the job queue, and launch
// threads to execute them
while (true)
while (isRunning)
{
// get a thread slot from the thread pool
try {

View File

@ -341,13 +341,15 @@ public class QServerMethods {
//System.out.println("shutdown: our privkey="+node.privKeyStr);
//System.out.println("shutdown: nodePrivKey="+nodePrivKey);
if (nodePrivKey.equals(node.privKeyStr)) {
res.put("status", "ok");
//node.scheduleShutdown();
// get a runtime
System.out.println("Node at "+node.dataDir+" shutting down");
//System.out.println("Node at "+node.dataDir+" shutting down");
Runtime r = Runtime.getRuntime();
// and terminate the vm
r.exit(0);
//r.halt(0);
//r.exit(0);
r.halt(0);
}
else {
res.put("status", "error");

View File

@ -62,6 +62,9 @@ class QWorkerThread extends Thread {
else if (cmd.equals("test")) {
doTest();
}
else if (cmd.equals("shutdown")) {
doShutdown();
}
else {
node.log.error("workerthread.run: unrecognised command '"+cmd+"'");
System.out.println("workerthread.run: unrecognised command '"+cmd+"'");
@ -90,6 +93,21 @@ class QWorkerThread extends Thread {
System.out.println("TESTJOB: msg='"+msg+"'");
}
public void doShutdown() throws Exception {
try {
new File(node.jobsDir + node.sep + jobTime).delete();
new File(node.jobsDir + node.sep + jobTime + ".desc").delete();
} catch (Exception e) {
e.printStackTrace();
}
SimpleFile f = new SimpleFile("/tmp/eeee", "rws");
f.write("xxx");
node.isRunning = false;
Runtime.getRuntime().halt(0);
}
public void doLocalPutItem() throws Exception {
Hashtable metadata = (Hashtable)job.get("metadata");
String path = (String)job.get("localDataFilePath");