Refactor to avoid some duplicate code.

0.6.0-stable
Homer Horwitz 2008-09-28 12:44:49 +00:00
parent 0b4415849a
commit 4452121227
2 changed files with 65 additions and 103 deletions

View File

@ -91,6 +91,8 @@ namespace OpenSim.Region.Environment.Modules.Framework
scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
scene.EventManager.OnMakeChildAgent += MakeChildAgent; scene.EventManager.OnMakeChildAgent += MakeChildAgent;
scene.EventManager.OnRegisterCaps += OnRegisterCaps; scene.EventManager.OnRegisterCaps += OnRegisterCaps;
m_log.DebugFormat("[EVENTQUEUE]: Enabled EventQueueGetModule for region {0}", scene.RegionInfo.RegionName);
} }
else else
{ {
@ -171,7 +173,7 @@ namespace OpenSim.Region.Environment.Modules.Framework
private void MakeChildAgent(ScenePresence avatar) private void MakeChildAgent(ScenePresence avatar)
{ {
m_log.DebugFormat("[EVENTQUEUE]: Make Child agent {0}.", avatar.UUID); m_log.DebugFormat("[EVENTQUEUE]: Make Child agent {0} in region {1}.", avatar.UUID, m_scene.RegionInfo.RegionName);
lock (m_ids) lock (m_ids)
{ {
if (m_ids.ContainsKey(avatar.UUID)) if (m_ids.ContainsKey(avatar.UUID))
@ -184,7 +186,7 @@ namespace OpenSim.Region.Environment.Modules.Framework
public void OnRegisterCaps(UUID agentID, Caps caps) public void OnRegisterCaps(UUID agentID, Caps caps)
{ {
m_log.DebugFormat("[EVENTQUEUE] OnRegisterCaps: agentID {0} caps {1} region", agentID, caps, m_scene.RegionInfo.RegionName); m_log.DebugFormat("[EVENTQUEUE] OnRegisterCaps: agentID {0} caps {1} region {2}", agentID, caps, m_scene.RegionInfo.RegionName);
string capsBase = "/CAPS/"; string capsBase = "/CAPS/";
caps.RegisterHandler("EventQueueGet", caps.RegisterHandler("EventQueueGet",
new RestHTTPHandler("POST", capsBase + UUID.Random().ToString(), new RestHTTPHandler("POST", capsBase + UUID.Random().ToString(),
@ -208,97 +210,66 @@ namespace OpenSim.Region.Environment.Modules.Framework
// 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) {
String debug = "[EVENTQUEUE]: Got request for agent {0} in region {1} from thread {2}: [ ";
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);
}
BlockingLLSDQueue queue = GetQueue(agentID); BlockingLLSDQueue queue = GetQueue(agentID);
LLSD element = queue.Dequeue(15000); // 15s timeout LLSD element = queue.Dequeue(15000); // 15s timeout
String debug = "[EVENTQUEUE]: Got request for agent {0} in region {1}: [ ";
foreach (object key in request.Keys)
{
debug += key.ToString() + "=" + request[key].ToString() + " ";
}
m_log.DebugFormat(debug, agentID, m_scene.RegionInfo.RegionName);
Hashtable responsedata = new Hashtable(); Hashtable responsedata = new Hashtable();
int thisID = 0;
lock (m_ids)
thisID = m_ids[agentID];
if (thisID == -1) // close-request
{
responsedata["int_response_code"] = 502;
responsedata["content_type"] = "text/plain";
responsedata["keepalive"] = false;
responsedata["str_response_string"] = "";
return responsedata;
}
LLSDArray array = new LLSDArray();
if (element == null) // didn't have an event in 15s if (element == null) // didn't have an event in 15s
{ {
// Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say! // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say!
element = EventQueueHelper.KeepAliveEvent(); array.Add(EventQueueHelper.KeepAliveEvent());
m_log.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName);
//ScenePresence avatar;
//m_scene.TryGetAvatar(agentID, out avatar);
LLSDArray array = new LLSDArray();
array.Add(element);
int thisID = 0;
lock (m_ids)
thisID = m_ids[agentID];
if (thisID == -1)
{
responsedata = new Hashtable();
responsedata["int_response_code"] = 502;
responsedata["content_type"] = "text/plain";
responsedata["keepalive"] = false;
responsedata["str_response_string"] = "";
return responsedata;
}
while (queue.Count() > 0)
{
array.Add(queue.Dequeue(1));
thisID++;
}
LLSDMap events = new LLSDMap();
events.Add("events", array);
events.Add("id", new LLSDInteger(thisID));
lock (m_ids)
{
m_ids[agentID] = thisID + 1;
}
responsedata = new Hashtable();
responsedata["int_response_code"] = 200;
responsedata["content_type"] = "application/llsd+xml";
responsedata["keepalive"] = true;
responsedata["str_response_string"] = LLSDParser.SerializeXmlString(events);
m_log.DebugFormat("[EVENTQUEUE]: sending fake response for {0} in region{1}: {2}", agentID, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
return responsedata;
} }
else else
{ {
ScenePresence avatar;
m_scene.TryGetAvatar(agentID, out avatar);
LLSDArray array = new LLSDArray();
array.Add(element); array.Add(element);
int thisID = m_ids[agentID];
while (queue.Count() > 0) while (queue.Count() > 0)
{ {
array.Add(queue.Dequeue(1)); array.Add(queue.Dequeue(1));
thisID++; thisID++;
} }
LLSDMap events = new LLSDMap();
events.Add("events", array);
events.Add("id", new LLSDInteger(thisID));
lock (m_ids)
{
m_ids[agentID] = thisID + 1;
}
responsedata = new Hashtable();
responsedata["int_response_code"] = 200;
responsedata["content_type"] = "application/llsd+xml";
responsedata["keepalive"] = true;
responsedata["str_response_string"] = LLSDParser.SerializeXmlString(events);
m_log.DebugFormat("[EVENTQUEUE]: sending fake response for {0} in region{1}: {2}", agentID, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
return responsedata;
} }
LLSDMap events = new LLSDMap();
events.Add("events", array);
events.Add("id", new LLSDInteger(thisID));
lock (m_ids)
{
m_ids[agentID] = thisID + 1;
}
responsedata["int_response_code"] = 200;
responsedata["content_type"] = "application/xml";
responsedata["keepalive"] = true;
responsedata["str_response_string"] = LLSDParser.SerializeXmlString(events);
m_log.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", agentID, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
return responsedata;
} }
} }
} }

View File

@ -36,23 +36,27 @@ namespace OpenSim.Region.Environment
{ {
private EventQueueHelper() {} // no construction possible, it's an utility class private EventQueueHelper() {} // no construction possible, it's an utility class
private static byte[] regionHandleToByteArray(ulong regionHandle)
{
// Reverse endianness of RegionHandle
return new byte[]
{
(byte)((regionHandle >> 56) % 256),
(byte)((regionHandle >> 48) % 256),
(byte)((regionHandle >> 40) % 256),
(byte)((regionHandle >> 32) % 256),
(byte)((regionHandle >> 24) % 256),
(byte)((regionHandle >> 16) % 256),
(byte)((regionHandle >> 8) % 256),
(byte)(regionHandle % 256)
};
}
public static LLSD EnableSimulator(ulong Handle, IPEndPoint endPoint) public static LLSD EnableSimulator(ulong Handle, IPEndPoint endPoint)
{ {
LLSDMap llsdSimInfo = new LLSDMap(3); LLSDMap llsdSimInfo = new LLSDMap(3);
byte[] regionhandle = new byte[8];
int i = 0;
// Reverse endianness of RegionHandle llsdSimInfo.Add("Handle", new LLSDBinary(regionHandleToByteArray(Handle)));
regionhandle[i++] = (byte)((Handle >> 56) % 256);
regionhandle[i++] = (byte)((Handle >> 48) % 256);
regionhandle[i++] = (byte)((Handle >> 40) % 256);
regionhandle[i++] = (byte)((Handle >> 32) % 256);
regionhandle[i++] = (byte)((Handle >> 24) % 256);
regionhandle[i++] = (byte)((Handle >> 16) % 256);
regionhandle[i++] = (byte)((Handle >> 8) % 256);
regionhandle[i++] = (byte)(Handle % 256);
llsdSimInfo.Add("Handle", new LLSDBinary(regionhandle));
llsdSimInfo.Add("IP", new LLSDBinary(endPoint.Address.GetAddressBytes())); llsdSimInfo.Add("IP", new LLSDBinary(endPoint.Address.GetAddressBytes()));
llsdSimInfo.Add("Port", new LLSDInteger(endPoint.Port)); llsdSimInfo.Add("Port", new LLSDInteger(endPoint.Port));
@ -68,6 +72,7 @@ namespace OpenSim.Region.Environment
return llsdMessage; return llsdMessage;
} }
public static LLSD CrossRegion(ulong Handle, Vector3 pos, Vector3 lookAt, public static LLSD CrossRegion(ulong Handle, Vector3 pos, Vector3 lookAt,
IPEndPoint newRegionExternalEndPoint, IPEndPoint newRegionExternalEndPoint,
string capsURL, UUID AgentID, UUID SessionID) string capsURL, UUID AgentID, UUID SessionID)
@ -97,21 +102,7 @@ namespace OpenSim.Region.Environment
AgentDataArr.Add(AgentDataMap); AgentDataArr.Add(AgentDataMap);
LLSDMap RegionDataMap = new LLSDMap(4); LLSDMap RegionDataMap = new LLSDMap(4);
byte[] regionhandle = new byte[8]; RegionDataMap.Add("RegionHandle", LLSD.FromBinary(regionHandleToByteArray(Handle)));
{
int i = 0;
regionhandle[i++] = (byte)((Handle >> 56) % 256);
regionhandle[i++] = (byte)((Handle >> 48) % 256);
regionhandle[i++] = (byte)((Handle >> 40) % 256);
regionhandle[i++] = (byte)((Handle >> 32) % 256);
regionhandle[i++] = (byte)((Handle >> 24) % 256);
regionhandle[i++] = (byte)((Handle >> 16) % 256);
regionhandle[i++] = (byte)((Handle >> 8) % 256);
regionhandle[i++] = (byte)(Handle % 256);
}
RegionDataMap.Add("RegionHandle", LLSD.FromBinary(regionhandle));
RegionDataMap.Add("SeedCapability", LLSD.FromString(capsURL)); RegionDataMap.Add("SeedCapability", LLSD.FromString(capsURL));
RegionDataMap.Add("SimIP", LLSD.FromBinary(newRegionExternalEndPoint.Address.GetAddressBytes())); RegionDataMap.Add("SimIP", LLSD.FromBinary(newRegionExternalEndPoint.Address.GetAddressBytes()));
RegionDataMap.Add("SimPort", LLSD.FromInteger(newRegionExternalEndPoint.Port)); RegionDataMap.Add("SimPort", LLSD.FromInteger(newRegionExternalEndPoint.Port));