protected override void StorageTerrainThread() { Thread.CurrentThread.Name = "Storage Terrain Thread: " + m_RegionID.ToString(); var knownSerialNumbers = new C5.TreeDictionary <uint, uint>(); while (!m_StopStorageThread || m_StorageTerrainRequestQueue.Count != 0) { LayerPatch req; try { req = m_StorageTerrainRequestQueue.Dequeue(1000); } catch { continue; } var serialNumber = req.Serial; if (!knownSerialNumbers.Contains(req.ExtendedPatchID) || knownSerialNumbers[req.ExtendedPatchID] != req.Serial) { m_Data[m_RegionID][req.ExtendedPatchID] = req.Serialization; knownSerialNumbers[req.ExtendedPatchID] = serialNumber; } } }
public static bool TryGetValue <K, V>(this C5.TreeDictionary <K, V> dictionary, K key, out V value) { value = default(V); if (dictionary.Contains(key)) { value = dictionary[key]; return(true); } return(false); }
protected override void OnUpdate(ObjectUpdateInfo info) { if (info.IsKilled) { if (info.Part.ObjectGroup.RootPart == info.Part) { m_GroupUpdates.Remove(info.ID); m_GroupDeletions[info.ID] = true; } m_PrimUpdates.Remove(info.ID); m_PrimDeletions[info.ID] = true; } else { bool havePrimSerial = m_PrimSerials.Contains(info.ID); if (havePrimSerial && m_PrimSerials[info.ID] == info.Part.SerialNumber) { /* ignore update */ } else { if (!havePrimSerial) { foreach (ObjectPartInventoryItem item in info.Part.Inventory.Values) { ObjectInventoryUpdateInfo invinfo = item.UpdateInfo; m_PrimItemUpdates[new PrimKey(invinfo)] = invinfo; } } if (info.Part.ObjectGroup.RootPart != info.Part) { m_GroupDeletions[info.ID] = true; } Dictionary <string, object> data = GenerateUpdateObjectPart(info.Part); data["RegionID"] = m_RegionID; m_PrimDeletions.Remove(info.ID); m_PrimUpdates[info.ID] = data; ObjectGroup grp = info.Part.ObjectGroup; m_GroupDeletions.Remove(grp.ID); m_GroupUpdates[grp.ID] = GenerateUpdateObjectGroup(grp); } } }
public void add(double time, double val) { if ((this.BurninTime > 0.0) && (time < this.BurninTime * 3600.0)) { return; } SingletonLogger.Instance().DebugLog(typeof(Trajectory), "Trajectory " + this.Name + " attempts add " + time + "->" + val); double historicallyAdjustedValue = ComputeHistoricallyAdjustedValue(time, val); // throttle data explosion if (!AboveTemporalGranularityThreshold(time)) { return; } // maintain function property if (_values.Contains(time)) { _values.Remove(time); } _values.Add(time, historicallyAdjustedValue); SingletonLogger.Instance().DebugLog(typeof(Trajectory), "Trajectory " + this.Name + " adds " + time + "->" + val); _lastTimestampOutput = time; // adjust min and max times if (time < _mint) { _mint = time; } if (time > _maxt) { _maxt = time; } }
public static bool ContainsKey <K, V>(this C5.TreeDictionary <K, V> dictionary, K key) => dictionary.Contains(key);
public bool ContainsKey(K key) { return(KToTMap.Contains(key)); }
protected override void StorageTerrainThread() { try { m_TerrainListenerThreads.Add(this); Thread.CurrentThread.Name = "Storage Terrain Thread: " + RegionID.ToString(); var knownSerialNumbers = new C5.TreeDictionary <uint, uint>(); string replaceIntoTerrain = string.Empty; var updateRequests = new List <string>(); while (!m_StopStorageThread || m_StorageTerrainRequestQueue.Count != 0) { LayerPatch req; try { req = m_StorageTerrainRequestQueue.Dequeue(1000); } catch { continue; } uint serialNumber = req.Serial; if (!knownSerialNumbers.Contains(req.ExtendedPatchID) || knownSerialNumbers[req.ExtendedPatchID] != req.Serial) { var data = new Dictionary <string, object> { ["RegionID"] = RegionID, ["PatchID"] = req.ExtendedPatchID, ["TerrainData"] = req.Serialization }; if (replaceIntoTerrain.Length == 0) { replaceIntoTerrain = "REPLACE INTO terrains (" + MySQLUtilities.GenerateFieldNames(data) + ") VALUES "; } updateRequests.Add("(" + MySQLUtilities.GenerateValues(data) + ")"); knownSerialNumbers[req.ExtendedPatchID] = serialNumber; } if ((m_StorageTerrainRequestQueue.Count == 0 && updateRequests.Count > 0) || updateRequests.Count >= 256) { string elems = string.Join(",", updateRequests); try { using (var conn = new MySqlConnection(m_ConnectionString)) { conn.Open(); using (var cmd = new MySqlCommand(replaceIntoTerrain + elems, conn)) { cmd.ExecuteNonQuery(); } } updateRequests.Clear(); Interlocked.Increment(ref m_ProcessedPatches); } catch (Exception e) { m_Log.Error("Terrain store failed", e); } } } } finally { m_TerrainListenerThreads.Remove(this); } }
public void PacketReceived(EndPoint ep, UDPPacket pck, List <UInt32> acknumbers) { /* no need for returning packets here since we are obliqued never to pass them around. * We just decode them here to actual messages */ MessageType mType = pck.ReadMessageType(); m_LastReceivedPacketAtTime = Environment.TickCount; Interlocked.Increment(ref m_PacketsReceived); /* do we have some acks from the packet's end? */ if (acknumbers != null) { int unackedReleasedCount = 0; bool ackedObjects = false; bool ackedSomethingElse = false; foreach (UInt32 ackno in acknumbers) { UDPPacket p_acked = null; lock (m_UnackedPacketsHash) { if (m_UnackedPacketsHash.Contains(ackno)) { p_acked = m_UnackedPacketsHash[ackno]; m_UnackedPacketsHash.Remove(ackno); } } if (p_acked != null) { unackedReleasedCount += p_acked.DataLength; Interlocked.Decrement(ref m_AckThrottlingCount[(int)p_acked.OutQueue]); if (p_acked.OutQueue == Message.QueueOutType.Object) { m_TxObjectPool.Enqueue(p_acked); ackedObjects = true; } else { ackedSomethingElse = true; } if (p_acked.AckMessage != null) { try { p_acked.AckMessage.OnSendComplete(true); } catch (Exception e) { m_Log.WarnFormat("OnSendCompletion: Exception {0} at {1}", e.ToString(), e.StackTrace); } } } if (ackedSomethingElse) { m_TxQueue.Enqueue(new AcksReceived()); } if (ackedObjects) { CheckForNewDataToSend(); } lock (m_LogoutReplyLock) { if (ackno == m_LogoutReplySeqNo && m_LogoutReplySent) { LogMsgOnLogoutCompletion(); TerminateCircuit(); return; } } } lock (m_UnackedBytesLock) { m_UnackedBytes -= unackedReleasedCount; } } if (pck.IsReliable) { /* we have to ack */ switch (mType) { case MessageType.CompleteAgentMovement: /* Immediate ack */ SendCircuitPacket(UDPPacket.PacketAckImmediate(pck.SequenceNumber)); break; default: m_AckList.Enqueue(pck.SequenceNumber); break; } } /* we know the message type now, so we have to decode it when possible */ switch (mType) { case MessageType.PacketAck: /* we decode it here, no need to pass it anywhere else */ int unackedReleasedCount = 0; bool ackedObjects = false; bool ackedSomethingElse = false; uint cnt = pck.ReadUInt8(); for (uint i = 0; i < cnt; ++i) { uint ackno = pck.ReadUInt32(); UDPPacket p_acked = null; lock (m_UnackedPacketsHash) { if (m_UnackedPacketsHash.Contains(ackno)) { p_acked = m_UnackedPacketsHash[ackno]; m_UnackedPacketsHash.Remove(ackno); } } if (p_acked != null) { unackedReleasedCount += p_acked.DataLength; Interlocked.Decrement(ref m_AckThrottlingCount[(int)p_acked.OutQueue]); if (p_acked.OutQueue == Message.QueueOutType.Object) { m_TxObjectPool.Enqueue(p_acked); ackedObjects = true; } else { ackedSomethingElse = true; } if (p_acked.AckMessage != null) { try { p_acked.AckMessage.OnSendComplete(true); } catch (Exception e) { m_Log.WarnFormat("OnSendCompletion: Exception {0} at {1}", e.ToString(), e.StackTrace); } } } lock (m_LogoutReplyLock) { if (ackno == m_LogoutReplySeqNo && m_LogoutReplySent) { LogMsgOnLogoutCompletion(); TerminateCircuit(); return; } } } if (ackedSomethingElse) { m_TxQueue.Enqueue(new AcksReceived()); } if (ackedObjects) { CheckForNewDataToSend(); } lock (m_UnackedBytesLock) { m_UnackedBytes -= unackedReleasedCount; } break; case MessageType.StartPingCheck: byte pingID = pck.ReadUInt8(); pck.ReadUInt32(); var newpck = new UDPPacket(); newpck.WriteMessageNumber(MessageType.CompletePingCheck); newpck.WriteUInt8(pingID); SendCircuitPacket(newpck); /* check for unacks */ try { foreach (uint keyval in m_UnackedPacketsHash.Keys) { UDPPacket Value; lock (m_UnackedPacketsHash) { if (!m_UnackedPacketsHash.Contains(keyval)) { continue; } Value = m_UnackedPacketsHash[keyval]; } if (Environment.TickCount - Value.TransferredAtTime > 1000) { if (Value.ResentCount < 5) { Value.TransferredAtTime = Environment.TickCount; Value.IsResent = true; Server.SendPacketTo(Value, RemoteEndPoint); } ++Value.ResentCount; } } } catch { /* no action required */ } break; case MessageType.CompletePingCheck: byte ackPingID = pck.ReadUInt8(); long timesent; if (m_PingSendTicks.Remove(ackPingID, out timesent)) { LastMeasuredLatencyMsecs = (int)PingTimeSource.TicksToMsecs(PingTimeSource.TicksElapsed(PingTimeSource.TickCount, timesent)) / 2; } break; default: bool isnewpacket = true; if (pck.IsReliable) { lock (m_ResentAge) { uint seqNo = pck.SequenceNumber; isnewpacket = !m_ResentDetectSet.Contains(seqNo) || !pck.IsResent; if (isnewpacket) { m_ResentAge.Add(new ResendAge { SeqNo = seqNo, TickCount = Environment.TickCount }); m_ResentDetectSet.Add(seqNo); } } } if (isnewpacket) { OnCircuitSpecificPacketReceived(mType, pck); } break; } lock (m_ResentAge) { if (m_ResentAge.Count > 0) { ResendAge age = m_ResentAge[0]; int actAge = Environment.TickCount - age.TickCount; if (actAge > 30000) { m_ResentDetectSet.Remove(age.SeqNo); m_ResentAge.RemoveAt(0); } } } }
protected override void StorageTerrainThread() { try { m_TerrainListenerThreads.Add(this); Thread.CurrentThread.Name = "Storage Terrain Thread: " + RegionID.ToString(); var knownSerialNumbers = new C5.TreeDictionary <uint, uint>(); Dictionary <string, object> updateRequestData = new Dictionary <string, object>(); int updateRequestCount = 0; while (!m_StopStorageThread || m_StorageTerrainRequestQueue.Count != 0) { LayerPatch req; try { req = m_StorageTerrainRequestQueue.Dequeue(1000); } catch { continue; } if (req == null) { using (var connection = new NpgsqlConnection(m_ConnectionString)) { connection.Open(); connection.InsideTransaction((transaction) => { using (var cmd = new NpgsqlCommand("DELETE FROM defaultterrains WHERE RegionID=@regionid", connection) { Transaction = transaction }) { cmd.Parameters.AddParameter("@RegionID", RegionID); cmd.ExecuteNonQuery(); } using (var cmd = new NpgsqlCommand("INSERT INTO defaultterrains (RegionID, PatchID, TerrainData) SELECT RegionID, PatchID, TerrainData FROM terrains WHERE RegionID=@regionid", connection) { Transaction = transaction }) { cmd.Parameters.AddParameter("@RegionID", RegionID); cmd.ExecuteNonQuery(); } }); } } else { uint serialNumber = req.Serial; if (!knownSerialNumbers.Contains(req.ExtendedPatchID) || knownSerialNumbers[req.ExtendedPatchID] != req.Serial) { updateRequestData.Add("PatchID" + updateRequestCount, req.ExtendedPatchID); updateRequestData.Add("TerrainData" + updateRequestCount, req.Serialization); ++updateRequestCount; knownSerialNumbers[req.ExtendedPatchID] = serialNumber; } if ((m_StorageTerrainRequestQueue.Count == 0 && updateRequestCount > 0) || updateRequestCount >= 256) { StringBuilder updateCmd = new StringBuilder(); try { using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) { conn.Open(); if (conn.HasOnConflict() && m_EnableOnConflict) { for (int i = 0; i < updateRequestCount; ++i) { updateCmd.AppendFormat("INSERT INTO terrains (\"RegionID\", \"PatchID\", \"TerrainData\") VALUES (@regionid, @patchid{0}, @terraindata{0}) ON CONFLICT(\"RegionID\", \"PatchID\") DO UPDATE SET \"TerrainData\"= @terraindata{0};", i); } } else { for (int i = 0; i < updateRequestCount; ++i) { updateCmd.AppendFormat("UPDATE terrains SET \"TerrainData\"=@terraindata{0} WHERE \"RegionID\" = @regionid AND \"PatchID\" = @patchid{0};", i); updateCmd.AppendFormat("INSERT INTO terrains (\"RegionID\", \"PatchID\", \"TerrainData\") SELECT @regionid, @patchid{0}, @terraindata{0} WHERE NOT EXISTS " + "(SELECT 1 FROM terrains WHERE \"RegionID\" = @regionid AND \"PatchID\" = @patchid{0});", i); } } using (NpgsqlCommand cmd = new NpgsqlCommand(updateCmd.ToString(), conn)) { cmd.Parameters.AddParameter("@regionid", RegionID); foreach (KeyValuePair <string, object> kvp in updateRequestData) { cmd.Parameters.AddParameter(kvp.Key, kvp.Value); } cmd.ExecuteNonQuery(); } } updateRequestData.Clear(); updateRequestCount = 0; Interlocked.Increment(ref m_ProcessedPatches); } catch (Exception e) { m_Log.Error("Terrain store failed", e); } } } } } finally { m_TerrainListenerThreads.Remove(this); } }
/// <summary> /// Get boolean value indicationg whether an item with the specified key exists in the collection /// </summary> /// <param name="rangeKey"> /// The item key (which is the start of the associated range) /// </param> /// <returns> /// <see langword="true"/> if does contain, <see langword="false"/> otherwise /// </returns> public bool ContainsKey(K rangeKey) { return(_dictionary.Contains(rangeKey)); }