use 'in' on PollService event args

This commit is contained in:
UbitUmarov
2022-10-16 17:36:17 +01:00
parent 8895577c80
commit 0df9802aa3
10 changed files with 91 additions and 106 deletions

View File

@@ -610,7 +610,7 @@ namespace OpenSim.Framework.Console
// Check if there is anything to send. Return true if this client has
// lines pending.
protected bool HasEvents(UUID RequestID, UUID sessionID)
protected bool HasEvents(in UUID RequestID, in UUID sessionID)
{
ConsoleConnection c = null;
@@ -627,7 +627,7 @@ namespace OpenSim.Framework.Console
}
// Send all pending output to the client.
protected Hashtable GetEvents(UUID RequestID, UUID sessionID)
protected Hashtable GetEvents(in UUID RequestID, in UUID sessionID)
{
// Find the connection that goes with this client.
ConsoleConnection c = null;
@@ -716,17 +716,15 @@ namespace OpenSim.Framework.Console
// This is really just a no-op. It generates what is sent
// to the client if the poll times out without any events.
protected Hashtable NoEvents(UUID RequestID, UUID id)
protected Hashtable NoEvents(in UUID RequestID, in UUID id)
{
Hashtable result = new Hashtable();
XmlDocument xmldoc = new XmlDocument();
XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
"", "");
XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
xmldoc.AppendChild(xmlnode);
XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession",
"");
XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession", "");
xmldoc.AppendChild(rootElement);

View File

@@ -31,13 +31,13 @@ using OpenMetaverse;
namespace OpenSim.Framework.Servers.HttpServer
{
public delegate OSHttpResponse RequestMethod(UUID ID, OSHttpRequest request);
public delegate bool HasEventsMethod(UUID requestID, UUID pId);
public delegate OSHttpResponse RequestMethod(in UUID ID, OSHttpRequest request);
public delegate bool HasEventsMethod(in UUID requestID, in UUID pId);
public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId);
public delegate Hashtable GetEventsMethod(in UUID requestID, in UUID pId);
public delegate Hashtable NoEventsMethod(UUID requestID, UUID pId);
public delegate void DropMethod(UUID requestID, UUID pId);
public delegate Hashtable NoEventsMethod(in UUID requestID, in UUID pId);
public delegate void DropMethod(in UUID requestID, in UUID pId);
public class PollServiceEventArgs : EventArgs
{

View File

@@ -41,16 +41,14 @@ namespace OpenSim.Framework.Servers.HttpServer
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private ConcurrentQueue<PollServiceHttpRequest> m_retryRequests = new ConcurrentQueue<PollServiceHttpRequest>();
private int m_WorkerThreadCount = 0;
private readonly ConcurrentQueue<PollServiceHttpRequest> m_retryRequests = new();
private readonly int m_WorkerThreadCount = 0;
private ObjectJobEngine m_workerPool;
private Thread m_retrysThread;
private bool m_running = false;
public PollServiceRequestManager(
bool performResponsesAsync, uint pWorkerThreadCount, int pTimeout)
public PollServiceRequestManager(bool performResponsesAsync, uint pWorkerThreadCount, int pTimeout)
{
m_WorkerThreadCount = (int)pWorkerThreadCount;
}
@@ -59,6 +57,7 @@ namespace OpenSim.Framework.Servers.HttpServer
{
if(m_running)
return;
m_running = true;
m_workerPool = new ObjectJobEngine(PoolWorkerJob, "PollServiceWorker", 4000, m_WorkerThreadCount);
@@ -86,12 +85,11 @@ namespace OpenSim.Framework.Servers.HttpServer
private void CheckRetries()
{
PollServiceHttpRequest preq;
while (m_running)
{
Thread.Sleep(100);
Watchdog.UpdateThread();
while (m_running && m_retryRequests.TryDequeue(out preq))
while (m_running && m_retryRequests.TryDequeue(out PollServiceHttpRequest preq))
m_workerPool.Enqueue(preq);
}
}
@@ -126,8 +124,7 @@ namespace OpenSim.Framework.Servers.HttpServer
private void PoolWorkerJob(object o)
{
PollServiceHttpRequest req = o as PollServiceHttpRequest;
if(req == null)
if (o is not PollServiceHttpRequest req)
return;
try
{
@@ -176,7 +173,7 @@ namespace OpenSim.Framework.Servers.HttpServer
}
catch (Exception e)
{
m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
m_log.Error($"Exception in poll service thread: {e}");
}
}
}

View File

@@ -55,7 +55,7 @@ namespace OpenSim.Region.ClientStack.Linden
public partial class EventQueueGetModule : IEventQueue, INonSharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static string LogHeader = "[EVENT QUEUE GET MODULE]";
private static readonly string LogHeader = "[EVENT QUEUE GET MODULE]";
private const int KEEPALIVE = 60; // this could be larger now, but viewers expect it on opensim
// we need to go back to close before viwers, or we may lose data
@@ -68,10 +68,10 @@ namespace OpenSim.Region.ClientStack.Linden
protected Scene m_scene;
private Dictionary<UUID, int> m_ids = new Dictionary<UUID, int>();
private readonly Dictionary<UUID, int> m_ids = new();
private Dictionary<UUID, Queue<byte[]>> queues = new Dictionary<UUID, Queue<byte[]>>();
private Dictionary<UUID, UUID> m_AvatarQueueUUIDMapping = new Dictionary<UUID, UUID>();
private readonly Dictionary<UUID, Queue<byte[]>> queues = new();
private readonly Dictionary<UUID, UUID> m_AvatarQueueUUIDMapping = new();
#region INonSharedRegionModule methods
public virtual void Initialise(IConfigSource config)
@@ -339,9 +339,9 @@ namespace OpenSim.Region.ClientStack.Linden
/// Generate an Event Queue Get handler path for the given eqg uuid.
/// </summary>
/// <param name='eqgUuid'></param>
private string GenerateEqgCapPath(UUID eqgUuid)
private static string GenerateEqgCapPath(UUID eqgUuid)
{
return string.Format("/CE/{0}", eqgUuid);
return $"/CE/{eqgUuid}";
}
public void OnRegisterCaps(UUID agentID, Caps caps)
@@ -349,16 +349,13 @@ namespace OpenSim.Region.ClientStack.Linden
// Register an event queue for the client
if (DebugLevel > 0)
m_log.DebugFormat(
"[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}",
agentID, caps, m_scene.RegionInfo.RegionName);
m_log.Debug(
$"[EVENTQUEUE]: OnRegisterCaps: agentID {agentID} caps {caps} region {m_scene.Name}");
UUID eventQueueGetUUID;
Queue<Byte[]> queue = null;
lock (queues)
{
queues.TryGetValue(agentID, out queue);
queues.TryGetValue(agentID, out Queue<byte[]> queue);
if (queue == null)
{
@@ -388,17 +385,16 @@ namespace OpenSim.Region.ClientStack.Linden
lock (m_AvatarQueueUUIDMapping)
{
// Its reuse caps path not queues those are been reused already
if (m_AvatarQueueUUIDMapping.ContainsKey(agentID))
if (m_AvatarQueueUUIDMapping.TryGetValue(agentID, out eventQueueGetUUID))
{
m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!");
eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID];
lock (m_ids)
{
// change to negative numbers so they are changed at end of sending first marker
// old data on a queue may be sent on a response for a new caps
// but at least will be sent with coerent IDs
if (m_ids.ContainsKey(agentID))
m_ids[agentID] = -m_ids[agentID];
if (m_ids.TryGetValue(agentID, out int previd))
m_ids[agentID] = -previd;
else
{
m_ids[agentID] = -Random.Shared.Next(30000000);
@@ -411,8 +407,8 @@ namespace OpenSim.Region.ClientStack.Linden
m_AvatarQueueUUIDMapping[agentID] = eventQueueGetUUID;
lock (m_ids)
{
if (m_ids.ContainsKey(agentID))
m_ids[agentID]++;
if (m_ids.TryGetValue(agentID, out int previd))
m_ids[agentID] = ++previd;
else
{
m_ids.Add(agentID, Random.Shared.Next(30000000));
@@ -428,7 +424,7 @@ namespace OpenSim.Region.ClientStack.Linden
new PollServiceEventArgs(null, GenerateEqgCapPath(eventQueueGetUUID), HasEvents, GetEvents, NoEvents, Drop, agentID, VIEWERKEEPALIVE));
}
public bool HasEvents(UUID requestID, UUID agentID)
public bool HasEvents(in UUID _, in UUID agentID)
{
Queue<byte[]> queue = GetQueue(agentID);
if (queue != null)
@@ -449,28 +445,27 @@ namespace OpenSim.Region.ClientStack.Linden
/// <param name='element'>Element containing message</param>
private void LogOutboundDebugMessage(OSD element, UUID agentId)
{
if (element is OSDMap)
if (element is OSDMap ev)
{
OSDMap ev = (OSDMap)element;
m_log.Debug($"Eq OUT {ev["message"],-30} to {m_scene.GetScenePresence(agentId).Name,-20} {m_scene.Name,-20}");
}
}
public void Drop(UUID requestID, UUID pAgentId)
public void Drop(in UUID requestID, in UUID pAgentId)
{
// do nothing, in last case http server will do it
}
private readonly byte[] EventHeader = osUTF8.GetASCIIBytes("<llsd><map><key>events</key><array>");
private static readonly byte[] EventHeader = osUTF8.GetASCIIBytes("<llsd><map><key>events</key><array>");
public Hashtable GetEvents(UUID requestID, UUID pAgentId)
public Hashtable GetEvents(in UUID requestID, in UUID pAgentId)
{
if (DebugLevel >= 2)
m_log.Warn($"POLLED FOR EQ MESSAGES BY {pAgentId} in {m_scene.Name}");
Queue<byte[]> queue = GetQueue(pAgentId);
if (queue == null)
return NoAgent(requestID, pAgentId);
if (queue is null)
return NoAgent();
byte[] element = null;
List<byte[]> elements;
@@ -500,7 +495,7 @@ namespace OpenSim.Region.ClientStack.Linden
element = queue.Dequeue();
// add elements until a marker is found
// so they get into a response
if (element == null)
if (element is null)
break;
if (DebugLevel > 0)
@@ -513,7 +508,7 @@ namespace OpenSim.Region.ClientStack.Linden
lock (m_ids)
{
if (element == null && negativeID)
if (element is null && negativeID)
{
m_ids[pAgentId] = Random.Shared.Next(30000000);
}
@@ -534,7 +529,7 @@ namespace OpenSim.Region.ClientStack.Linden
elements.Add(element);
totalSize += element.Length;
Hashtable responsedata = new Hashtable
Hashtable responsedata = new()
{
["int_response_code"] = 200,
["content_type"] = "application/xml"
@@ -556,26 +551,20 @@ namespace OpenSim.Region.ClientStack.Linden
return responsedata;
}
public Hashtable NoEvents(UUID requestID, UUID agentID)
public Hashtable NoEvents(in UUID _, in UUID agentID)
{
Hashtable responsedata = new Hashtable();
Queue<byte[]> queue = GetQueue(agentID);
if (queue == null)
return new Hashtable()
{
responsedata["int_response_code"] = (int)HttpStatusCode.NotFound;
return responsedata;
}
responsedata["int_response_code"] = (int)HttpStatusCode.BadGateway;
return responsedata;
["int_response_code"] = GetQueue(agentID) == null ? (int)HttpStatusCode.NotFound : (int)HttpStatusCode.BadGateway
};
}
public Hashtable NoAgent(UUID requestID, UUID agentID)
public static Hashtable NoAgent()
{
Hashtable responsedata = new Hashtable
return new Hashtable()
{
["int_response_code"] = (int)HttpStatusCode.NotFound
};
return responsedata;
}
}
}

View File

@@ -190,13 +190,13 @@ namespace OpenSim.Region.ClientStack.Linden
{
m_module = module;
HasEvents = (requestID, y) =>
HasEvents = delegate (in UUID requestID, in UUID _)
{
lock (responses)
return responses.ContainsKey(requestID);
};
Drop = (requestID, y) =>
Drop = delegate (in UUID requestID, in UUID _)
{
lock (responses)
{
@@ -206,7 +206,7 @@ namespace OpenSim.Region.ClientStack.Linden
}
};
GetEvents = (requestID, y) =>
GetEvents = delegate (in UUID requestID, in UUID _)
{
lock (responses)
{
@@ -221,7 +221,7 @@ namespace OpenSim.Region.ClientStack.Linden
}
};
Request = (requestID, request) =>
Request = delegate(in UUID requestID, OSHttpRequest request)
{
APollRequest reqinfo = new APollRequest();
reqinfo.thepoll = this;
@@ -231,7 +231,7 @@ namespace OpenSim.Region.ClientStack.Linden
return null;
};
NoEvents = (x, y) =>
NoEvents = delegate (in UUID _, in UUID _)
{
Hashtable response = new Hashtable();
response["int_response_code"] = 500;

View File

@@ -199,7 +199,7 @@ namespace OpenSim.Region.ClientStack.Linden
m_scene = scene;
m_hgassets = HGAssetSVC;
HasEvents = (requestID, agentID) =>
HasEvents = delegate(in UUID requestID, in UUID _)
{
lock (responses)
{
@@ -207,7 +207,7 @@ namespace OpenSim.Region.ClientStack.Linden
}
};
Drop = (requestID, y) =>
Drop = delegate(in UUID requestID, in UUID _)
{
lock (responses)
{
@@ -217,47 +217,48 @@ namespace OpenSim.Region.ClientStack.Linden
}
};
GetEvents = (requestID, y) =>
GetEvents = delegate(in UUID requestID, in UUID _)
{
lock (responses)
{
try
if(responses.Remove(requestID, out APollResponse apr))
{
OSHttpResponse response = responses[requestID].osresponse;
OSHttpResponse response = apr.osresponse;
if (response.Priority < 0)
response.Priority = 0;
Hashtable lixo = new Hashtable(1);
lixo["h"] = response;
Hashtable lixo = new()
{
["h"] = response
};
return lixo;
}
finally
{
responses.Remove(requestID);
}
}
return new Hashtable();
};
// x is request id, y is request data hashtable
Request = (requestID, request) =>
Request = delegate (in UUID requestID, OSHttpRequest request)
{
APollRequest reqinfo = new APollRequest();
reqinfo.thepoll = this;
reqinfo.reqID = requestID;
reqinfo.request = request;
APollRequest reqinfo = new()
{
thepoll = this,
reqID = requestID,
request = request
};
m_workerpool.Enqueue(reqinfo);
return null;
};
// this should never happen except possible on shutdown
NoEvents = (x, y) =>
NoEvents = delegate (in UUID _, in UUID _)
{
/*
lock (requests)
{
Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString());
requests.Remove(request);
}
lock (requests)
{
Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString());
requests.Remove(request);
}
*/
Hashtable response = new Hashtable();

View File

@@ -229,7 +229,7 @@ namespace OpenSim.Region.ClientStack.Linden
private class PollServiceInventoryEventArgs : PollServiceEventArgs
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private Dictionary<UUID, Hashtable> responses = new Dictionary<UUID, Hashtable>();
private HashSet<UUID> dropedResponses = new HashSet<UUID>();
@@ -241,13 +241,13 @@ namespace OpenSim.Region.ClientStack.Linden
{
m_module = module;
HasEvents = (requestID, y) =>
HasEvents = delegate (in UUID requestID, in UUID _)
{
lock (responses)
return responses.ContainsKey(requestID);
};
Drop = (requestID, y) =>
Drop = delegate (in UUID requestID, in UUID _)
{
lock (responses)
{
@@ -257,7 +257,7 @@ namespace OpenSim.Region.ClientStack.Linden
}
};
GetEvents = (requestID, y) =>
GetEvents = delegate (in UUID requestID, in UUID _)
{
lock (responses)
{
@@ -272,7 +272,7 @@ namespace OpenSim.Region.ClientStack.Linden
}
};
Request = (requestID, request) =>
Request = delegate (in UUID requestID, OSHttpRequest request)
{
APollRequest reqinfo = new APollRequest();
reqinfo.thepoll = this;
@@ -282,7 +282,7 @@ namespace OpenSim.Region.ClientStack.Linden
return null;
};
NoEvents = (x, y) =>
NoEvents = delegate (in UUID _, in UUID _)
{
Hashtable response = new Hashtable();
response["int_response_code"] = 500;

View File

@@ -537,7 +537,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
}
}
protected Hashtable NoEvents(UUID requestID, UUID sessionID)
protected Hashtable NoEvents(in UUID requestID, in UUID sessionID)
{
Hashtable response = new Hashtable();
UrlData url;
@@ -569,7 +569,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
return response;
}
protected bool HasEvents(UUID requestID, UUID sessionID)
protected bool HasEvents(in UUID requestID, in UUID sessionID)
{
UrlData url=null;
@@ -591,7 +591,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
}
}
protected void Drop(UUID requestID, UUID sessionID)
protected void Drop(in UUID requestID, in UUID _)
{
UrlData url = null;
lock (m_RequestMap)
@@ -608,7 +608,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
}
}
protected Hashtable GetEvents(UUID requestID, UUID sessionID)
protected Hashtable GetEvents(in UUID requestID, in UUID sessionID)
{
UrlData url = null;
@@ -689,7 +689,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
return resp;
}
public OSHttpResponse HttpRequestHandler(UUID requestID, OSHttpRequest request)
public OSHttpResponse HttpRequestHandler(in UUID requestID, OSHttpRequest request)
{
lock (request)
{
@@ -707,7 +707,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
string uri_tmp;
string pathInfo;
int pos = uri.IndexOf("/", 45); // /lslhttp/uuid/ <-
int pos = uri.IndexOf('/', 45); // /lslhttp/uuid/ <-
if (pos >= 45)
{
uri_tmp = uri.Substring(0, pos);

View File

@@ -6162,7 +6162,7 @@ namespace OpenSim.Region.Framework.Scenes
goto case "sequence";
do
{
index = Util.RandomClass.Next(spawnPoints.Length - 1);
index = Random.Shared.Next(spawnPoints.Length - 1);
spawnPosition = spawnPoints[index].GetLocation(teleHubPosition, teleHubRotation);
land = m_scene.LandChannel.GetLandObject(spawnPosition.X,spawnPosition.Y);

View File

@@ -163,7 +163,7 @@ namespace OpenSim.Services.GridService
return null;
}
private static IPEndPoint dummyIP = new IPEndPoint(0,0);
private static readonly IPEndPoint dummyIP = new IPEndPoint(0,0);
private bool TryCreateLinkImpl(UUID scopeID, int xloc, int yloc, RegionURI rurl, UUID ownerID, out GridRegion regInfo)
{
m_log.InfoFormat("[HYPERGRID LINKER]: Link to {0} {1}, in <{2},{3}>",
@@ -293,7 +293,7 @@ namespace OpenSim.Services.GridService
private bool TryCreateLinkImpl(UUID scopeID, int xloc, int yloc, string remoteRegionName, uint externalPort, string externalHostName, string serverURI, UUID ownerID, out GridRegion regInfo, out string reason)
{
m_log.InfoFormat("[HYPERGRID LINKER]: Link to {0} {1}, in <{2},{3}>",
((serverURI == null) ? (externalHostName + ":" + externalPort) : serverURI),
(serverURI ?? externalHostName + ":" + externalPort),
remoteRegionName, Util.WorldToRegionLoc((uint)xloc), Util.WorldToRegionLoc((uint)yloc));
reason = string.Empty;