aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/AsyncSceneObjectGroupDeleter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/AsyncSceneObjectGroupDeleter.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/AsyncSceneObjectGroupDeleter.cs165
1 files changed, 0 insertions, 165 deletions
diff --git a/OpenSim/Region/Environment/Scenes/AsyncSceneObjectGroupDeleter.cs b/OpenSim/Region/Environment/Scenes/AsyncSceneObjectGroupDeleter.cs
deleted file mode 100644
index 1429452..0000000
--- a/OpenSim/Region/Environment/Scenes/AsyncSceneObjectGroupDeleter.cs
+++ /dev/null
@@ -1,165 +0,0 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Timers;
32using log4net;
33using OpenMetaverse;
34using OpenMetaverse.Packets;
35using OpenSim.Framework;
36
37namespace OpenSim.Region.Environment.Scenes
38{
39 class DeleteToInventoryHolder
40 {
41 public DeRezAction action;
42 public IClientAPI remoteClient;
43 public SceneObjectGroup objectGroup;
44 public UUID folderID;
45 public bool permissionToDelete;
46 }
47
48 /// <summary>
49 /// Asynchronously derez objects. This is used to derez large number of objects to inventory without holding
50 /// up the main client thread.
51 /// </summary>
52 public class AsyncSceneObjectGroupDeleter
53 {
54 private static readonly ILog m_log
55 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
56
57 /// <value>
58 /// Is the deleter currently enabled?
59 /// </value>
60 public bool Enabled;
61
62 private Timer m_inventoryTicker = new Timer(2000);
63 private readonly Queue<DeleteToInventoryHolder> m_inventoryDeletes = new Queue<DeleteToInventoryHolder>();
64 private Scene m_scene;
65
66 public AsyncSceneObjectGroupDeleter(Scene scene)
67 {
68 m_scene = scene;
69
70 m_inventoryTicker.AutoReset = false;
71 m_inventoryTicker.Elapsed += InventoryRunDeleteTimer;
72 }
73
74 /// <summary>
75 /// Delete the given object from the scene
76 /// </summary>
77 public void DeleteToInventory(DeRezAction action, UUID folderID,
78 SceneObjectGroup objectGroup, IClientAPI remoteClient,
79 bool permissionToDelete)
80 {
81 if (Enabled)
82 m_inventoryTicker.Stop();
83
84 lock (m_inventoryDeletes)
85 {
86 DeleteToInventoryHolder dtis = new DeleteToInventoryHolder();
87 dtis.action = action;
88 dtis.folderID = folderID;
89 dtis.objectGroup = objectGroup;
90 dtis.remoteClient = remoteClient;
91 dtis.permissionToDelete = permissionToDelete;
92
93 m_inventoryDeletes.Enqueue(dtis);
94 }
95
96 if (Enabled)
97 m_inventoryTicker.Start();
98
99 // Visually remove it, even if it isnt really gone yet. This means that if we crash before the object
100 // has gone to inventory, it will reappear in the region again on restart instead of being lost.
101 // This is not ideal since the object will still be available for manipulation when it should be, but it's
102 // better than losing the object for now.
103 if (permissionToDelete)
104 objectGroup.DeleteGroup(false);
105 }
106
107 private void InventoryRunDeleteTimer(object sender, ElapsedEventArgs e)
108 {
109 m_log.Debug("[SCENE]: Starting send to inventory loop");
110
111 while (InventoryDeQueueAndDelete())
112 {
113 m_log.Debug("[SCENE]: Sent item successfully to inventory, continuing...");
114 }
115 }
116
117 /// <summary>
118 /// Move the next object in the queue to inventory. Then delete it properly from the scene.
119 /// </summary>
120 /// <returns></returns>
121 public bool InventoryDeQueueAndDelete()
122 {
123 DeleteToInventoryHolder x = null;
124
125 try
126 {
127 lock (m_inventoryDeletes)
128 {
129 int left = m_inventoryDeletes.Count;
130 if (left > 0)
131 {
132 m_log.DebugFormat(
133 "[SCENE]: Sending object to user's inventory, {0} item(s) remaining.", left);
134
135 x = m_inventoryDeletes.Dequeue();
136
137 try
138 {
139 m_scene.DeleteToInventory(x.action, x.folderID, x.objectGroup, x.remoteClient);
140 if (x.permissionToDelete)
141 m_scene.DeleteSceneObject(x.objectGroup, false);
142 }
143 catch (Exception e)
144 {
145 m_log.DebugFormat("Exception background sending object: " + e);
146 }
147
148 return true;
149 }
150 }
151 }
152 catch (Exception e)
153 {
154 // We can't put the object group details in here since the root part may have disappeared (which is where these sit).
155 // FIXME: This needs to be fixed.
156 m_log.ErrorFormat(
157 "[SCENE]: Queued sending of scene object to agent {0} {1} failed: {2}",
158 (x != null ? x.remoteClient.Name : "unavailable"), (x != null ? x.remoteClient.AgentId.ToString() : "unavailable"), e.ToString());
159 }
160
161 m_log.Debug("[SCENE]: No objects left in inventory send queue.");
162 return false;
163 }
164 }
165}