aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices/OpenGrid.Framework.Manager/GridServerManager.cs
blob: 7ebf66aeb8eac2b58e3812f292e085a28404f893 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections;
using System.Collections.Generic;
using Nwc.XmlRpc;
using System.Threading;
using libsecondlife;

namespace OpenGrid.Framework.Manager {

	public class GridServerManager 
	{
		public static GridManagerCallback thecallback;

		public static string sendkey;
		public static string recvkey;

		public static XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request)
         	{
           		XmlRpcResponse response = new XmlRpcResponse();
            		Hashtable requestData = (Hashtable)request.Params[0];
	    		Hashtable responseData = new Hashtable();
         
			if(requestData.ContainsKey("session_id")) {
				if(GridManagementAgent.SessionExists(new LLUUID((string)requestData["session_id"]))) {
					responseData["msg"]="Shutdown command accepted";
					(new Thread(new ThreadStart(ZOMGServerIsNowTerminallyIll))).Start();
				} else {
					response.IsFault=true;
					responseData["error"]="bad session ID";
				}
			} else {
				response.IsFault=true;
				responseData["error"]="no session ID";
			}

	    		response.Value = responseData;
	    		return response;
		}

		// Brought to by late-night coding
		public static void ZOMGServerIsNowTerminallyIll()
		{
			Console.WriteLine("ZOMG! THIS SERVER IS TERMINALLY ILL - WE GOT A SHUTDOWN REQUEST FROM A GRID MANAGER!!!!");
			Console.WriteLine("We have 3 seconds to live...");
			Thread.Sleep(3000);
			thecallback("shutdown");
		}
	 }
}