private void ProcessPrimDeletions(MySqlConnection conn) { var removedItems = new List <UUID>(); foreach (UUID k in m_PrimDeletions.Keys.ToArray()) { removedItems.Add(k); if (removedItems.Count == 255) { string c1 = string.Format("DELETE FROM prims WHERE RegionID = \"{0}\" AND (ID=\"{1}\")", m_RegionID, string.Join("\" OR ID=\"", removedItems)); string c2 = string.Format("DELETE FROM primitems WHERE RegionID = \"{0}\" AND (PrimID=\"{1}\")", m_RegionID, string.Join("\" OR PrimID=\"", removedItems)); using (var cmd = new MySqlCommand(c1, conn)) { cmd.ExecuteNonQuery(); } using (var cmd = new MySqlCommand(c2, conn)) { cmd.ExecuteNonQuery(); } foreach (UUID r in removedItems) { m_PrimDeletions.Remove(r); Interlocked.Increment(ref m_ProcessedPrims); } removedItems.Clear(); } } if (removedItems.Count != 0) { string c1 = string.Format("DELETE FROM prims WHERE RegionID = \"{0}\" AND (ID=\"{1}\")", m_RegionID, string.Join("\" OR ID=\"", removedItems)); string c2 = string.Format("DELETE FROM primitems WHERE RegionID = \"{0}\" AND (PrimID=\"{1}\")", m_RegionID, string.Join("\" OR PrimID=\"", removedItems)); using (var cmd = new MySqlCommand(c1, conn)) { cmd.ExecuteNonQuery(); } using (var cmd = new MySqlCommand(c2, conn)) { cmd.ExecuteNonQuery(); } foreach (UUID r in removedItems) { m_PrimDeletions.Remove(r); Interlocked.Increment(ref m_ProcessedPrims); } } }
public bool cancelOrder(IOrder order) { IList <IOrder_Mutable> val; bool result = false; _logger.DebugLog(SOURCE, "Orderbook cancelOrder " + order); if (order.isBid()) { if (!_bidsDict.TryGetValue(order.getPrice(), out val)) { return(false); } else { ((IOrder_Mutable)order).setCancel(); result = val.Remove((IOrder_Mutable)order); _numBids--; } } else { if (!_asksDict.TryGetValue(order.getPrice(), out val)) { return(false); } else { ((IOrder_Mutable)order).setCancel(); result = val.Remove((IOrder_Mutable)order); _numAsks--; } } if (val.Count == 0) { if (order.isBid()) { _bidsDict.Remove(order.getPrice()); _bids.Remove(order.getPrice()); } else { _asksDict.Remove(order.getPrice()); _asks.Remove(order.getPrice()); } } foreach (IOrderbookObserver obs in _obsList) { this.Send(obs, new NotifyObserverEvent(this, new OrderbookEvent_CancelOrder((IOrder_Mutable)order)), 0.0); } return(result); }
protected override void OnUpdate(ObjectInventoryUpdateInfo info) { if (info.IsRemoved) { m_PrimItemUpdates.Remove(new PrimKey(info)); m_PrimItemDeletions[new PrimKey(info)] = true; } else { m_PrimItemUpdates[new PrimKey(info)] = info; } }
private void ProcessPrimItemDeletions(NpgsqlConnection conn) { StringBuilder sb = new StringBuilder(); List <PrimKey> removedItems = new List <PrimKey>(); foreach (PrimKey k in m_PrimItemDeletions.Keys.ToArray()) { if (sb.Length != 0) { sb.Append(" OR "); } else { sb.Append("DELETE FROM primitems WHERE "); } sb.AppendFormat("(\"RegionID\" = '{0}' AND \"PrimID\" = '{1}' AND \"InventoryID\" = '{2}')", m_RegionID, k.PartID, k.ItemID); removedItems.Add(k); if (removedItems.Count == 255) { using (var cmd = new NpgsqlCommand(sb.ToString(), conn)) { cmd.ExecuteNonQuery(); } foreach (PrimKey r in removedItems) { m_PrimItemDeletions.Remove(r); } sb.Clear(); removedItems.Clear(); } } if (removedItems.Count != 0) { using (var cmd = new NpgsqlCommand(sb.ToString(), conn)) { cmd.ExecuteNonQuery(); } foreach (PrimKey r in removedItems) { m_PrimItemDeletions.Remove(r); } } }
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); } } }
private void ProcessGroupDeletions(NpgsqlConnection conn) { var removedItems = new List <UUID>(); foreach (UUID k in m_GroupDeletions.Keys.ToArray()) { removedItems.Add(k); if (removedItems.Count == 255) { string c = string.Format("DELETE FROM objects WHERE \"RegionID\"='{0}' AND (\"ID\"='{1}')", m_RegionID, string.Join("' OR \"ID\"='", removedItems)); using (var cmd = new NpgsqlCommand(c, conn)) { cmd.ExecuteNonQuery(); } foreach (UUID r in removedItems) { m_GroupDeletions.Remove(r); } removedItems.Clear(); } } if (removedItems.Count != 0) { string c = string.Format("DELETE FROM objects WHERE \"RegionID\"='{0}' AND (\"ID\"='{1}')", m_RegionID, string.Join("' OR \"ID\"='", removedItems)); using (var cmd = new NpgsqlCommand(c, conn)) { cmd.ExecuteNonQuery(); } foreach (UUID r in removedItems) { m_GroupDeletions.Remove(r); } } }
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 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); } } } }
/// <summary> /// Remove an item with the specified key from the collection /// </summary> /// <param name="rangeKey"> /// The item key to remove /// </param> /// <returns> /// <see langword="true"/> if the item was removed /// <see langword="false"/> if the item was not in the collection /// </returns> public bool RemoveByKey(K rangeKey) { return(_dictionary.Remove(rangeKey)); }