UpdateQueue.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Runtime.Serialization;
  30. using System.Security.Permissions;
  31. using OpenMetaverse;
  32. using OpenSim.Region.Environment.Scenes;
  33. namespace OpenSim.Region.Environment.Types
  34. {
  35. [Serializable]
  36. public class UpdateQueue : ISerializable
  37. {
  38. private Queue<SceneObjectPart> m_queue;
  39. private List<UUID> m_ids;
  40. private object m_syncObject = new object();
  41. public int Count
  42. {
  43. get { return m_queue.Count; }
  44. }
  45. public UpdateQueue()
  46. {
  47. m_queue = new Queue<SceneObjectPart>();
  48. m_ids = new List<UUID>();
  49. }
  50. public void Clear()
  51. {
  52. lock (m_syncObject)
  53. {
  54. m_ids.Clear();
  55. m_queue.Clear();
  56. }
  57. }
  58. public void Enqueue(SceneObjectPart part)
  59. {
  60. lock (m_syncObject)
  61. {
  62. if (!m_ids.Contains(part.UUID))
  63. {
  64. m_ids.Add(part.UUID);
  65. m_queue.Enqueue(part);
  66. }
  67. }
  68. }
  69. public SceneObjectPart Dequeue()
  70. {
  71. SceneObjectPart part = null;
  72. lock (m_syncObject)
  73. {
  74. if (m_queue.Count > 0)
  75. {
  76. part = m_queue.Dequeue();
  77. m_ids.Remove(part.UUID);
  78. }
  79. }
  80. return part;
  81. }
  82. protected UpdateQueue(SerializationInfo info, StreamingContext context)
  83. {
  84. //System.Console.WriteLine("UpdateQueue Deserialize BGN");
  85. if (info == null)
  86. {
  87. throw new ArgumentNullException("info");
  88. }
  89. m_queue = (Queue<SceneObjectPart>)info.GetValue("m_queue", typeof(Queue<SceneObjectPart>));
  90. List<Guid> ids_work = (List<Guid>)info.GetValue("m_ids", typeof(List<Guid>));
  91. foreach (Guid guid in ids_work)
  92. {
  93. m_ids.Add(new UUID(guid));
  94. }
  95. //System.Console.WriteLine("UpdateQueue Deserialize END");
  96. }
  97. [SecurityPermission(SecurityAction.LinkDemand,
  98. Flags = SecurityPermissionFlag.SerializationFormatter)]
  99. public virtual void GetObjectData(
  100. SerializationInfo info, StreamingContext context)
  101. {
  102. if (info == null)
  103. {
  104. throw new ArgumentNullException("info");
  105. }
  106. List<Guid> ids_work = new List<Guid>();
  107. foreach (UUID uuid in m_ids)
  108. {
  109. ids_work.Add(uuid.Guid);
  110. }
  111. info.AddValue("m_queue", m_queue);
  112. info.AddValue("m_ids", ids_work);
  113. }
  114. }
  115. }