public ChatSessionRequest(ViewerAgent agent, AgentCircuit circuit, string remoteIP, RwLockedDictionary <string, Func <ViewerAgent, AgentCircuit, HttpRequest, Map, Map> > handlers) { m_Agent = agent; m_Circuit = circuit; m_RemoteIP = remoteIP; ChatSessionRequestMethodHandlers = handlers; }
void IExperienceKeyValueInterface.Store(UEI experienceID, string key, string value) { RwLockedDictionary <string, string> exp = m_KeyValues[experienceID]; lock (m_UpdateLock) { exp[key] = value; } }
public MemorySceneListener( RwLockedDictionaryAutoAdd <UUID, RwLockedDictionary <UUID, Map> > objects, RwLockedDictionaryAutoAdd <UUID, RwLockedDictionary <UUID, Map> > primitives, RwLockedDictionaryAutoAdd <UUID, RwLockedDictionary <string, Map> > primitems, UUID regionID) : base(regionID) { m_Objects = objects[regionID]; m_Primitives = primitives[regionID]; m_PrimItems = primitems[regionID]; }
public RwLockedDictionary <string, Action <List <string>, TTY, UUID> > CheckAddCommandType(string cmd) { RwLockedDictionary <string, Action <List <string>, TTY, UUID> > dict; lock (m_RegisterCmdGroupLock) { if (!m_SubCommands.TryGetValue(cmd, out dict)) { dict = new RwLockedDictionary <string, Action <List <string>, TTY, UUID> >(); Commands.Add(cmd, new CommandType(cmd, dict).Command_Handler); m_SubCommands.Add(cmd, dict); } return(dict); } }
public void AddRemoveAllCommand(string cmd, Action <List <string>, TTY, UUID> handler) { RwLockedDictionary <string, Action <List <string>, TTY, UUID> > removecmds = CheckAddCommandType("remove"); RwLockedDictionary <string, Action <List <string>, TTY, UUID> > removeallcmds; lock (m_RegisterCmdGroupLock) { if (!m_SubCommands.TryGetValue("remove all", out removeallcmds)) { removeallcmds = new RwLockedDictionary <string, Action <List <string>, TTY, UUID> >(); removecmds.Add("all", new SubCommandType("remove all", removeallcmds).Command_Handler); m_SubCommands.Add("remove all", removeallcmds); } } removeallcmds.Add(cmd, handler); }
bool IExperienceKeyValueInterface.StoreOnlyIfEqualOrig(UEI experienceID, string key, string value, string orig_value) { bool changed; RwLockedDictionary <string, string> exp = m_KeyValues[experienceID]; lock (m_UpdateLock) { string ov; changed = exp.TryGetValue(key, out ov) && ov == orig_value; if (changed) { exp[key] = value; } } return(changed); }
/* * public IList<TerrainPatch> GetTerrainDistanceSorted(Vector3 v) * { * SortedList<int, TerrainPatch> sorted = new SortedList<int, TerrainPatch>(); * uint x; * uint y; * * if(v.X < 0) * { * x = 0; * } * else if(v.X >= SizeX) * { * x = SizeX - 1; * } * else * { * x = (uint)v.X / TERRAIN_PATCH_SIZE; * } * * if (v.Y < 0) * { * y = 0; * } * else if(v.Y >= SizeY) * { * y = SizeY - 1; * } * else * { * y = (uint)v.Y / TERRAIN_PATCH_SIZE; * } * * int distance; * * for(uint py = 0; py < SizeY / TERRAIN_PATCH_SIZE; ++py) * { * for(uint px = 0; px < SizeX / TERRAIN_PATCH_SIZE; ++px) * { * distance = ((int)px - (int)x) * ((int)px - (int)x) + ((int)py - (int)y) * ((int)py - (int)y); * sorted.Add(distance, new TerrainPatch(px, py, m_Map[py * m_PatchCountX + px])); * } * } * * return sorted.Values; * } */ private List <LayerData> CompileTerrainData(IAgent agent) => m_TerrainRwLock.AcquireReaderLock(() => { int y; int x; var mlist = new List <LayerData>(); var dirtyPatches = new List <LayerPatch>(); RwLockedDictionary <uint, uint> agentSceneSerials = agent.TransmittedTerrainSerials[m_Scene.ID]; for (y = 0; y < m_Scene.SizeY / LayerCompressor.LAYER_PATCH_NUM_XY_ENTRIES; ++y) { for (x = 0; x < m_Scene.SizeX / LayerCompressor.LAYER_PATCH_NUM_XY_ENTRIES; ++x) { LayerPatch patch = m_TerrainPatches[y, x]; uint serial; if (agentSceneSerials.TryGetValue(patch.ExtendedPatchID, out serial)) { if (serial != patch.Serial) { agentSceneSerials[patch.ExtendedPatchID] = serial; dirtyPatches.Add(m_TerrainPatches[y, x]); } } else { dirtyPatches.Add(m_TerrainPatches[y, x]); } } } var layerType = LayerData.LayerDataType.Land; if (BASE_REGION_SIZE < m_Scene.SizeX || BASE_REGION_SIZE < m_Scene.SizeY) { layerType = LayerData.LayerDataType.LandExtended; } int offset = 0; while (offset < dirtyPatches.Count) { int remaining = dirtyPatches.Count - offset; int actualused = 0; mlist.Add(LayerCompressor.ToLayerMessage(dirtyPatches, layerType, offset, remaining, out actualused)); offset += actualused; } return(mlist); });
public void FrameTimer(object o, ElapsedEventArgs args) { RwLockedDictionary <uint /* localids */, ScriptReportData> oldTopScripts = m_TopScripts; m_TopScripts = new RwLockedDictionary <uint, ScriptReportData>(); m_LastTopScripts = oldTopScripts; long tickCount = TimeSource.TickCount; if (m_FirstEventEps) { m_LastScriptEventTickCount = tickCount; m_LastScriptEventCounter = m_ScriptEventCounter; m_FirstEventEps = false; } else if (TimeSource.TicksElapsed(tickCount, m_LastScriptEventTickCount) >= TimeSource.Frequency) { long deltaticks = TimeSource.TicksElapsed(tickCount, m_LastScriptEventTickCount); int newEvents = m_ScriptEventCounter; ScriptEventsPerSec = TimeSource.NormalizedToEventsPerSeconds(newEvents - m_LastScriptEventCounter, deltaticks); m_LastScriptEventTickCount = tickCount; m_LastScriptEventCounter = newEvents; long newaccum = Interlocked.Read(ref m_ScriptRuntimeAccumulatingTickCount); long totalscriptexec = newaccum - m_LastScriptRuntimeAccumulatingTickCount; m_LastScriptRuntimeAccumulatingTickCount = newaccum; /* add execution times of actually running scripts */ foreach (ScriptThreadContext tc in m_Threads) { if (tc.IsExecuting) { long diff = Math.Min(TimeSource.TicksElapsed(tickCount, tc.ExecutionStartTickCount), deltaticks); totalscriptexec += diff; } } ScriptTimeMsPerSec = TimeSource.TicksToMsecs(totalscriptexec); } }
private void ProcessTopScripts(AgentCircuit circuit, SceneInterface scene, LandStatFilterFlags flags, string filter) { RwLockedDictionary <uint, ScriptReportData> execTimes = scene.ScriptThreadPool.GetExecutionTimes(); var reply = new LandStatReply { ReportType = LandStatReportEnum.TopScripts, RequestFlags = 0, TotalObjectCount = (uint)execTimes.Count }; int allocedlength = 0; /* make top objects go first */ foreach (KeyValuePair <uint, ScriptReportData> kvp in execTimes.OrderByDescending(x => x.Value.Score)) { if (reply.ReportData.Count == 100) { break; } ObjectPart p; try { if (!scene.Primitives.TryGetValue(kvp.Key, out p)) { continue; } UGUIWithName owner = scene.AvatarNameService.ResolveName(p.Owner); if ((flags & LandStatFilterFlags.FilterByObject) != 0 && !p.Name.Contains(filter)) { continue; } if ((flags & LandStatFilterFlags.FilterByOwner) != 0 && !owner.FullName.Contains(filter)) { continue; } ParcelInfo pinfo; if ((flags & LandStatFilterFlags.FilterByParcelName) != 0 && !scene.Parcels.TryGetValue(p.GlobalPosition, out pinfo) && !pinfo.Name.Equals(filter, System.StringComparison.InvariantCultureIgnoreCase)) { continue; } var entry = new LandStatReply.ReportDataEntry { Location = p.GlobalPosition, Score = kvp.Value.Score, TaskID = p.ID, TaskLocalID = kvp.Key, TaskName = p.Name, OwnerName = owner.FullName }; if (allocedlength + entry.MessageLength > 1400) { circuit.SendMessage(reply); reply = new LandStatReply { ReportType = 0, RequestFlags = 0, TotalObjectCount = (uint)execTimes.Count }; } reply.ReportData.Add(entry); allocedlength += entry.MessageLength; } catch { /* ignore the report */ } } circuit.SendMessage(reply); }
public SubCommandType(string command, RwLockedDictionary <string, Action <List <string>, TTY, UUID> > dict) { m_Command = command; m_Dict = dict; }
public override void Store(UUID muteListOwnerID, MuteListEntry mute) { RwLockedDictionary <string, MuteListEntry> list = m_MuteLists[muteListOwnerID]; list[GetKey(mute.MuteID, mute.MuteName)] = new MuteListEntry(mute); }
List <ObjectGroup> ISimulationDataObjectStorageInterface.LoadObjects(UUID regionID, bool skipErrors) { var objGroups = new Dictionary <UUID, ObjectGroup>(); var originalAssetIDs = new Dictionary <UUID, UUID>(); var nextOwnerAssetIDs = new Dictionary <UUID, UUID>(); var objGroupParts = new Dictionary <UUID, SortedDictionary <int, ObjectPart> >(); var objPartIDs = new List <UUID>(); var objParts = new Dictionary <UUID, ObjectPart>(); var orphanedPrims = new List <UUID>(); var orphanedPrimInventories = new List <KeyValuePair <UUID, UUID> >(); var objectList = new RwLockedDictionary <UUID, Map>(); var primitiveList = new RwLockedDictionary <UUID, Map>(); var primItemList = new RwLockedDictionary <string, Map>(); if (m_Objects.TryGetValue(regionID, out objectList)) { UUID objgroupID = UUID.Zero; m_Log.InfoFormat("Loading object groups for region ID {0}", regionID); foreach (KeyValuePair <UUID, Map> kvp in objectList) { try { objgroupID = kvp.Key; originalAssetIDs[objgroupID] = kvp.Value["OriginalAssetID"].AsUUID; nextOwnerAssetIDs[objgroupID] = kvp.Value["NextOwnerAssetID"].AsUUID; objGroups[objgroupID] = ObjectGroupFromMap(kvp.Value); } catch (Exception e) { m_Log.WarnFormat("Failed to load object {0}: {1}\n{2}", objgroupID, e.Message, e.StackTrace); objGroups.Remove(objgroupID); } } m_Log.InfoFormat("Loading prims for region ID {0}", regionID); int primcount = 0; if (m_Primitives.TryGetValue(regionID, out primitiveList)) { foreach (KeyValuePair <UUID, Map> kvp in primitiveList) { UUID rootPartID = kvp.Value["RootPartID"].AsUUID; if (objGroups.ContainsKey(rootPartID)) { if (!objGroupParts.ContainsKey(rootPartID)) { objGroupParts.Add(rootPartID, new SortedDictionary <int, ObjectPart>()); } var objpart = ObjectPartFromMap(kvp.Value); objGroupParts[rootPartID].Add(objpart.LoadedLinkNumber, objpart); objPartIDs.Add(objpart.ID); objParts[objpart.ID] = objpart; if ((++primcount) % 5000 == 0) { m_Log.InfoFormat("Loading prims for region ID {0} - {1} loaded", regionID, primcount); } } else { m_Log.WarnFormat("deleting orphan prim in region ID {0}: {1}", regionID, kvp.Key); orphanedPrims.Add(kvp.Key); } } } m_Log.InfoFormat("Loaded prims for region ID {0} - {1} loaded", regionID, primcount); int primitemcount = 0; m_Log.InfoFormat("Loading prim inventories for region ID {0}", regionID); if (m_PrimItems.TryGetValue(regionID, out primItemList)) { foreach (var map in primItemList.Values) { var partID = map["PrimID"].AsUUID; ObjectPart part; if (objParts.TryGetValue(partID, out part)) { var item = ObjectPartInventoryItemFromMap(map); if (skipErrors) { try { part.Inventory.Add(item.ID, item.Name, item); } catch { m_Log.WarnFormat("deleting duplicate prim in region ID {0}: {1}", regionID, map["ID"].AsUUID); orphanedPrimInventories.Add(new KeyValuePair <UUID, UUID>(map["PrimID"].AsUUID, map["ID"].AsUUID)); } } else { part.Inventory.Add(item.ID, item.Name, item); } if ((++primitemcount) % 5000 == 0) { m_Log.InfoFormat("Loading prim inventories for region ID {0} - {1} loaded", regionID, primitemcount); } } else { m_Log.WarnFormat("deleting orphan prim in region ID {0}: {1}", regionID, map["ID"].AsUUID); orphanedPrimInventories.Add(new KeyValuePair <UUID, UUID>(map["PrimID"].AsUUID, map["ID"].AsUUID)); } } } m_Log.InfoFormat("Loaded prim inventories for region ID {0} - {1} loaded", regionID, primitemcount); } var removeObjGroups = new List <UUID>(); foreach (var kvp in objGroups) { if (!objGroupParts.ContainsKey(kvp.Key)) { removeObjGroups.Add(kvp.Key); } else { foreach (var objpart in objGroupParts[kvp.Key].Values) { kvp.Value.Add(objpart.LoadedLinkNumber, objpart.ID, objpart); } try { kvp.Value.OriginalAssetID = originalAssetIDs[kvp.Value.ID]; kvp.Value.NextOwnerAssetID = nextOwnerAssetIDs[kvp.Value.ID]; kvp.Value.FinalizeObject(); } catch { m_Log.WarnFormat("deleting orphan object in region ID {0}: {1}", regionID, kvp.Key); removeObjGroups.Add(kvp.Key); } } } foreach (var objid in removeObjGroups) { objGroups.Remove(objid); objectList.Remove(objid); } foreach (var primid in orphanedPrims) { primitiveList.Remove(primid); } foreach (var kvp in orphanedPrimInventories) { primItemList.Remove(GenItemKey(kvp.Key, kvp.Value)); } return(new List <ObjectGroup>(objGroups.Values)); }
private void PurgeOrDelete(UUID principalID, UUID folderID, bool deleteFolder) { List <UUID> folders; InventoryFolder ownfolder; if (!Folder.TryGetValue(principalID, folderID, out ownfolder)) { throw new KeyNotFoundException(); } if (deleteFolder) { folders = new List <UUID> { folderID }; } else { folders = GetFolderIDs(principalID, folderID); } int index = 0; while (index < folders.Count) { foreach (UUID folder in GetFolderIDs(principalID, folders[index])) { if (!folders.Contains(folder)) { folders.Add(folder); } } ++index; } RwLockedDictionary <UUID, InventoryItem> itemSet = m_Items[principalID]; foreach (InventoryItem item in itemSet.Values) { if (folders.Contains(item.ParentFolderID)) { itemSet.Remove(item.ID); } } UUID[] folderArray = folders.ToArray(); Array.Reverse(folderArray); RwLockedDictionary <UUID, InventoryFolder> folderSet = m_Folders[principalID]; foreach (UUID folder in folderArray) { folderSet.Remove(folder); } if (deleteFolder) { IncrementVersionNoExcept(principalID, ownfolder.ParentFolderID); } else { IncrementVersionNoExcept(principalID, folderID); } }
public EnvironmentSettings(EnvironmentSettings env) { m_WaterSettings = env.WaterSettings; DayCycle = new RwLockedList <KeyValuePair <double, string> >(env.DayCycle); SkySettings = new RwLockedDictionary <string, SkyEntry>(env.SkySettings); }
private void ThreadMain(object obj) { var tc = (ScriptThreadContext)obj; var pool = tc.ThreadPool; ScriptInstance ev; while (!m_ShutdownThreads) { try { ev = pool.m_ScriptTriggerQueue.Dequeue(1000); } catch { lock (m_Threads) { if (m_Threads.Count > m_MinimumThreads) { break; } } continue; } long executionStart = TimeSource.TickCount; tc.ExecutionStartTickCount = executionStart; tc.IsExecuting = true; ObjectPartInventoryItem item = ev.Item; try { Interlocked.Increment(ref m_ExecutingScripts); lock (tc) { if (Interlocked.CompareExchange(ref ev.ThreadPool, this, null) != null) { continue; } tc.CurrentScriptInstance = ev; } ev.ProcessEvent(); } catch (ThreadAbortException) { /* no in script event should abort us */ Thread.ResetAbort(); try { item.ScriptInstance = null; } catch (ThreadAbortException) { Thread.ResetAbort(); } catch (Exception e) { m_Log.WarnFormat("Exception at script removal {0} ({1}): {2}\n{3}", item.Name, item.AssetID.ToString(), e.Message, e.StackTrace); } ScriptLoader.Remove(item.AssetID, ev); continue; } catch (ScriptAbortException) { ev.AbortBegin(); try { item.ScriptInstance = null; } catch (ThreadAbortException) { Thread.ResetAbort(); } catch (Exception e) { m_Log.WarnFormat("Exception at script removal {0} ({1}): {2}\n{3}", item.Name, item.AssetID.ToString(), e.Message, e.StackTrace); } ScriptLoader.Remove(item.AssetID, ev); continue; } catch (InvalidProgramException e) { /* stop the broken script */ m_Log.WarnFormat("Automatically stopped script {0} ({1}) of {2} ({3}) in {4} ({5}) due to program error: {6}\n{7}", item.Name, item.AssetID.ToString(), ev.Part?.Name ?? "?", ev.Part?.ID.ToString() ?? "?", ev.Part?.ObjectGroup?.Name ?? "?", ev.Part?.ObjectGroup?.ID.ToString() ?? "?", e.Message, e.StackTrace); ev.IsRunning = false; continue; } catch (Exception e) { m_Log.WarnFormat("Exception at script {0} ({1}) of {2} ({3}) in {4} ({5}) due to program error: {6}\n{7}", item.Name, item.AssetID.ToString(), ev.Part?.Name ?? "?", ev.Part?.ID.ToString() ?? "?", ev.Part?.ObjectGroup?.Name, ev.Part?.ObjectGroup?.ID.ToString() ?? "?", e.Message, e.StackTrace); } finally { Interlocked.Decrement(ref m_ExecutingScripts); tc.IsExecuting = false; uint localId; lock (tc) { try { localId = tc.CurrentScriptInstance.Part.LocalID[m_SceneID]; executionStart = TimeSource.TicksElapsed(TimeSource.TickCount, executionStart); if (executionStart > 0) { RwLockedDictionary <uint, ScriptReportData> execTime = m_TopScripts; ScriptReportData prevexectime; if (!execTime.TryGetValue(localId, out prevexectime)) { prevexectime = new ScriptReportData(); execTime.Add(localId, prevexectime); } prevexectime.AddScore(TimeSource.TicksToMsecs(executionStart)); Interlocked.Add(ref m_ScriptRuntimeAccumulatingTickCount, executionStart); } } catch { /* ignore it here */ } tc.CurrentScriptInstance = null; } } ev.ThreadPool = null; if (ev.HasEventsPending) { pool.m_ScriptTriggerQueue.Enqueue(ev); } } lock (m_Threads) { m_Threads.Remove(tc); if (m_ShutdownThreads && m_Threads.Count == 0) { m_WaitShutdownEvent.Set(); } } }