Node shutdown now uses halt()
This commit is contained in:
@ -158,6 +158,8 @@ public abstract class QNode extends Thread
|
|||||||
|
|
||||||
public String nodeType = "(base)";
|
public String nodeType = "(base)";
|
||||||
|
|
||||||
|
public boolean isRunning;
|
||||||
|
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
// CONSTRUCTORS
|
// CONSTRUCTORS
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
@ -580,6 +582,13 @@ public abstract class QNode extends Thread
|
|||||||
System.out.println("scheduleStartupJobs: c<p="+updateCatalogFromPeers+", isClient="+isClient);
|
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)
|
public void schedulePeerUploadJob(QDataItem item)
|
||||||
{
|
{
|
||||||
String uri = (String)item.get("uri");
|
String uri = (String)item.get("uri");
|
||||||
@ -790,6 +799,8 @@ public abstract class QNode extends Thread
|
|||||||
{
|
{
|
||||||
log.info("Starting background tasks");
|
log.info("Starting background tasks");
|
||||||
|
|
||||||
|
isRunning = true;
|
||||||
|
|
||||||
// mark our start time
|
// mark our start time
|
||||||
nodeStartTime = new Date();
|
nodeStartTime = new Date();
|
||||||
|
|
||||||
@ -833,7 +844,7 @@ public abstract class QNode extends Thread
|
|||||||
|
|
||||||
// fetch items from the job queue, and launch
|
// fetch items from the job queue, and launch
|
||||||
// threads to execute them
|
// threads to execute them
|
||||||
while (true)
|
while (isRunning)
|
||||||
{
|
{
|
||||||
// get a thread slot from the thread pool
|
// get a thread slot from the thread pool
|
||||||
try {
|
try {
|
||||||
|
@ -341,13 +341,15 @@ public class QServerMethods {
|
|||||||
//System.out.println("shutdown: our privkey="+node.privKeyStr);
|
//System.out.println("shutdown: our privkey="+node.privKeyStr);
|
||||||
//System.out.println("shutdown: nodePrivKey="+nodePrivKey);
|
//System.out.println("shutdown: nodePrivKey="+nodePrivKey);
|
||||||
if (nodePrivKey.equals(node.privKeyStr)) {
|
if (nodePrivKey.equals(node.privKeyStr)) {
|
||||||
// get a runtime
|
|
||||||
System.out.println("Node at "+node.dataDir+" shutting down");
|
|
||||||
Runtime r = Runtime.getRuntime();
|
|
||||||
|
|
||||||
|
res.put("status", "ok");
|
||||||
|
//node.scheduleShutdown();
|
||||||
|
// get a runtime
|
||||||
|
//System.out.println("Node at "+node.dataDir+" shutting down");
|
||||||
|
Runtime r = Runtime.getRuntime();
|
||||||
// and terminate the vm
|
// and terminate the vm
|
||||||
r.exit(0);
|
//r.exit(0);
|
||||||
//r.halt(0);
|
r.halt(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.put("status", "error");
|
res.put("status", "error");
|
||||||
|
@ -62,6 +62,9 @@ class QWorkerThread extends Thread {
|
|||||||
else if (cmd.equals("test")) {
|
else if (cmd.equals("test")) {
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
else if (cmd.equals("shutdown")) {
|
||||||
|
doShutdown();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
node.log.error("workerthread.run: unrecognised command '"+cmd+"'");
|
node.log.error("workerthread.run: unrecognised command '"+cmd+"'");
|
||||||
System.out.println("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+"'");
|
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 {
|
public void doLocalPutItem() throws Exception {
|
||||||
Hashtable metadata = (Hashtable)job.get("metadata");
|
Hashtable metadata = (Hashtable)job.get("metadata");
|
||||||
String path = (String)job.get("localDataFilePath");
|
String path = (String)job.get("localDataFilePath");
|
||||||
|
Reference in New Issue
Block a user