Stop passing a request handler to the initial caps.RegisterHandler in EventQueueGetModule since this is immediatley replaced by a poll server handler.

This allows us to comment out a bunch of code and simplify the codebase and readability.
iar_mods
Justin Clark-Casey (justincc) 2011-11-24 21:27:35 +00:00
parent 0174e326e3
commit 63c137820b
2 changed files with 165 additions and 161 deletions

View File

@ -98,14 +98,17 @@ namespace OpenSim.Framework.Capabilities
{ {
get { return m_httpListener.UseSSL; } get { return m_httpListener.UseSSL; }
} }
public string SSLCommonName public string SSLCommonName
{ {
get { return m_httpListener.SSLCommonName; } get { return m_httpListener.SSLCommonName; }
} }
public CapsHandlers CapsHandlers public CapsHandlers CapsHandlers
{ {
get { return m_capsHandlers; } get { return m_capsHandlers; }
} }
public Dictionary<string, string> ExternalCapsHandlers public Dictionary<string, string> ExternalCapsHandlers
{ {
get { return m_externalCapsHandlers; } get { return m_externalCapsHandlers; }
@ -157,11 +160,7 @@ namespace OpenSim.Framework.Capabilities
/// <summary> /// <summary>
/// Remove all CAPS service handlers. /// Remove all CAPS service handlers.
///
/// </summary> /// </summary>
/// <param name="httpListener"></param>
/// <param name="path"></param>
/// <param name="restMethod"></param>
public void DeregisterHandlers() public void DeregisterHandlers()
{ {
if (m_capsHandlers != null) if (m_capsHandlers != null)

View File

@ -346,12 +346,16 @@ namespace OpenSim.Region.ClientStack.Linden
} }
// Register this as a caps handler // Register this as a caps handler
// FIXME: Confusingly, we need to register separate as a capability so that the client is told about
// EventQueueGet when it receive capability information, but then we replace the rest handler immediately
// afterwards with the poll service. So for now, we'll pass a null instead to simplify code reading, but
// really it should be possible to directly register the poll handler as a capability.
caps.RegisterHandler("EventQueueGet", caps.RegisterHandler("EventQueueGet",
new RestHTTPHandler("POST", capsBase + EventQueueGetUUID.ToString() + "/", new RestHTTPHandler("POST", capsBase + EventQueueGetUUID.ToString() + "/", null));
delegate(Hashtable m_dhttpMethod) // delegate(Hashtable m_dhttpMethod)
{ // {
return ProcessQueue(m_dhttpMethod, agentID, caps); // return ProcessQueue(m_dhttpMethod, agentID, caps);
})); // }));
// This will persist this beyond the expiry of the caps handlers // This will persist this beyond the expiry of the caps handlers
MainServer.Instance.AddPollServiceHTTPHandler( MainServer.Instance.AddPollServiceHTTPHandler(
@ -382,6 +386,8 @@ namespace OpenSim.Region.ClientStack.Linden
public Hashtable GetEvents(UUID requestID, UUID pAgentId, string request) public Hashtable GetEvents(UUID requestID, UUID pAgentId, string request)
{ {
m_log.DebugFormat("[EVENT QUEUE GET MODULE]: Invoked GetEvents() for {0}", pAgentId);
Queue<OSD> queue = TryGetQueue(pAgentId); Queue<OSD> queue = TryGetQueue(pAgentId);
OSD element; OSD element;
lock (queue) lock (queue)
@ -465,167 +471,166 @@ namespace OpenSim.Region.ClientStack.Linden
return responsedata; return responsedata;
} }
public Hashtable ProcessQueue(Hashtable request, UUID agentID, Caps caps) // public Hashtable ProcessQueue(Hashtable request, UUID agentID, Caps caps)
{ // {
// TODO: this has to be redone to not busy-wait (and block the thread), // // TODO: this has to be redone to not busy-wait (and block the thread),
// TODO: as soon as we have a non-blocking way to handle HTTP-requests. // // TODO: as soon as we have a non-blocking way to handle HTTP-requests.
//
// if (m_log.IsDebugEnabled) //// if (m_log.IsDebugEnabled)
// { //// {
// String debug = "[EVENTQUEUE]: Got request for agent {0} in region {1} from thread {2}: [ "; //// String debug = "[EVENTQUEUE]: Got request for agent {0} in region {1} from thread {2}: [ ";
// foreach (object key in request.Keys) //// foreach (object key in request.Keys)
//// {
//// debug += key.ToString() + "=" + request[key].ToString() + " ";
//// }
//// m_log.DebugFormat(debug + " ]", agentID, m_scene.RegionInfo.RegionName, System.Threading.Thread.CurrentThread.Name);
//// }
//
// Queue<OSD> queue = TryGetQueue(agentID);
// OSD element;
//
// lock (queue)
// element = queue.Dequeue(); // 15s timeout
//
// Hashtable responsedata = new Hashtable();
//
// int thisID = 0;
// lock (m_ids)
// thisID = m_ids[agentID];
//
// if (element == null)
// {
// //m_log.ErrorFormat("[EVENTQUEUE]: Nothing to process in " + m_scene.RegionInfo.RegionName);
// if (thisID == -1) // close-request
// { // {
// debug += key.ToString() + "=" + request[key].ToString() + " "; // m_log.ErrorFormat("[EVENTQUEUE]: 404 in " + m_scene.RegionInfo.RegionName);
// responsedata["int_response_code"] = 404; //501; //410; //404;
// responsedata["content_type"] = "text/plain";
// responsedata["keepalive"] = false;
// responsedata["str_response_string"] = "Closed EQG";
// return responsedata;
// } // }
// m_log.DebugFormat(debug + " ]", agentID, m_scene.RegionInfo.RegionName, System.Threading.Thread.CurrentThread.Name); // responsedata["int_response_code"] = 502;
// responsedata["content_type"] = "text/plain";
// responsedata["keepalive"] = false;
// responsedata["str_response_string"] = "Upstream error: ";
// responsedata["error_status_text"] = "Upstream error:";
// responsedata["http_protocol_version"] = "HTTP/1.0";
// return responsedata;
// } // }
//
Queue<OSD> queue = TryGetQueue(agentID); // OSDArray array = new OSDArray();
OSD element; // if (element == null) // didn't have an event in 15s
// {
lock (queue) // // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say!
element = queue.Dequeue(); // 15s timeout // array.Add(EventQueueHelper.KeepAliveEvent());
// //m_log.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName);
Hashtable responsedata = new Hashtable(); // }
// else
int thisID = 0; // {
lock (m_ids) // array.Add(element);
thisID = m_ids[agentID]; //
// if (element is OSDMap)
if (element == null) // {
{ // OSDMap ev = (OSDMap)element;
//m_log.ErrorFormat("[EVENTQUEUE]: Nothing to process in " + m_scene.RegionInfo.RegionName); // m_log.DebugFormat(
if (thisID == -1) // close-request // "[EVENT QUEUE GET MODULE]: Eq OUT {0} to {1}",
{ // ev["message"], m_scene.GetScenePresence(agentID).Name);
m_log.ErrorFormat("[EVENTQUEUE]: 404 in " + m_scene.RegionInfo.RegionName); // }
responsedata["int_response_code"] = 404; //501; //410; //404; //
responsedata["content_type"] = "text/plain"; // lock (queue)
responsedata["keepalive"] = false; // {
responsedata["str_response_string"] = "Closed EQG"; // while (queue.Count > 0)
return responsedata; // {
} // element = queue.Dequeue();
responsedata["int_response_code"] = 502; //
responsedata["content_type"] = "text/plain"; // if (element is OSDMap)
responsedata["keepalive"] = false; // {
responsedata["str_response_string"] = "Upstream error: "; // OSDMap ev = (OSDMap)element;
responsedata["error_status_text"] = "Upstream error:"; // m_log.DebugFormat(
responsedata["http_protocol_version"] = "HTTP/1.0"; // "[EVENT QUEUE GET MODULE]: Eq OUT {0} to {1}",
return responsedata; // ev["message"], m_scene.GetScenePresence(agentID).Name);
} // }
//
OSDArray array = new OSDArray(); // array.Add(element);
if (element == null) // didn't have an event in 15s // thisID++;
{ // }
// Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say! // }
array.Add(EventQueueHelper.KeepAliveEvent()); // }
//m_log.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName); //
} // OSDMap events = new OSDMap();
else // events.Add("events", array);
{ //
array.Add(element); // events.Add("id", new OSDInteger(thisID));
// lock (m_ids)
if (element is OSDMap) // {
{ // m_ids[agentID] = thisID + 1;
OSDMap ev = (OSDMap)element; // }
m_log.DebugFormat( //
"[EVENT QUEUE GET MODULE]: Eq OUT {0} to {1}", // responsedata["int_response_code"] = 200;
ev["message"], m_scene.GetScenePresence(agentID).Name); // responsedata["content_type"] = "application/xml";
} // responsedata["keepalive"] = false;
// responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(events);
lock (queue) //
{ // m_log.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", agentID, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
while (queue.Count > 0) //
{ // return responsedata;
element = queue.Dequeue(); // }
if (element is OSDMap)
{
OSDMap ev = (OSDMap)element;
m_log.DebugFormat(
"[EVENT QUEUE GET MODULE]: Eq OUT {0} to {1}",
ev["message"], m_scene.GetScenePresence(agentID).Name);
}
array.Add(element);
thisID++;
}
}
}
OSDMap events = new OSDMap();
events.Add("events", array);
events.Add("id", new OSDInteger(thisID));
lock (m_ids)
{
m_ids[agentID] = thisID + 1;
}
responsedata["int_response_code"] = 200;
responsedata["content_type"] = "application/xml";
responsedata["keepalive"] = false;
responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(events);
m_log.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", agentID, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
return responsedata;
}
public Hashtable EventQueuePoll(Hashtable request) public Hashtable EventQueuePoll(Hashtable request)
{ {
return new Hashtable(); return new Hashtable();
} }
public Hashtable EventQueuePath2(Hashtable request) // public Hashtable EventQueuePath2(Hashtable request)
{ // {
string capuuid = (string)request["uri"]; //path.Replace("/CAPS/EQG/",""); // string capuuid = (string)request["uri"]; //path.Replace("/CAPS/EQG/","");
// pull off the last "/" in the path. // // pull off the last "/" in the path.
Hashtable responsedata = new Hashtable(); // Hashtable responsedata = new Hashtable();
capuuid = capuuid.Substring(0, capuuid.Length - 1); // capuuid = capuuid.Substring(0, capuuid.Length - 1);
capuuid = capuuid.Replace("/CAPS/EQG/", ""); // capuuid = capuuid.Replace("/CAPS/EQG/", "");
UUID AvatarID = UUID.Zero; // UUID AvatarID = UUID.Zero;
UUID capUUID = UUID.Zero; // UUID capUUID = UUID.Zero;
//
// parse the path and search for the avatar with it registered // // parse the path and search for the avatar with it registered
if (UUID.TryParse(capuuid, out capUUID)) // if (UUID.TryParse(capuuid, out capUUID))
{ // {
lock (m_QueueUUIDAvatarMapping) // lock (m_QueueUUIDAvatarMapping)
{ // {
if (m_QueueUUIDAvatarMapping.ContainsKey(capUUID)) // if (m_QueueUUIDAvatarMapping.ContainsKey(capUUID))
{ // {
AvatarID = m_QueueUUIDAvatarMapping[capUUID]; // AvatarID = m_QueueUUIDAvatarMapping[capUUID];
} // }
} // }
//
if (AvatarID != UUID.Zero) // if (AvatarID != UUID.Zero)
{ // {
return ProcessQueue(request, AvatarID, m_scene.CapsModule.GetCapsForUser(AvatarID)); // return ProcessQueue(request, AvatarID, m_scene.CapsModule.GetCapsForUser(AvatarID));
} // }
else // else
{ // {
responsedata["int_response_code"] = 404; // responsedata["int_response_code"] = 404;
responsedata["content_type"] = "text/plain"; // responsedata["content_type"] = "text/plain";
responsedata["keepalive"] = false; // responsedata["keepalive"] = false;
responsedata["str_response_string"] = "Not Found"; // responsedata["str_response_string"] = "Not Found";
responsedata["error_status_text"] = "Not Found"; // responsedata["error_status_text"] = "Not Found";
responsedata["http_protocol_version"] = "HTTP/1.0"; // responsedata["http_protocol_version"] = "HTTP/1.0";
return responsedata; // return responsedata;
// return 404 // // return 404
} // }
} // }
else // else
{ // {
responsedata["int_response_code"] = 404; // responsedata["int_response_code"] = 404;
responsedata["content_type"] = "text/plain"; // responsedata["content_type"] = "text/plain";
responsedata["keepalive"] = false; // responsedata["keepalive"] = false;
responsedata["str_response_string"] = "Not Found"; // responsedata["str_response_string"] = "Not Found";
responsedata["error_status_text"] = "Not Found"; // responsedata["error_status_text"] = "Not Found";
responsedata["http_protocol_version"] = "HTTP/1.0"; // responsedata["http_protocol_version"] = "HTTP/1.0";
return responsedata; // return responsedata;
// return 404 // // return 404
} // }
// }
}
public OSD EventQueueFallBack(string path, OSD request, string endpoint) public OSD EventQueueFallBack(string path, OSD request, string endpoint)
{ {