diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/AsyncSceneObjectGroupDeleter.cs | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/AsyncSceneObjectGroupDeleter.cs b/OpenSim/Region/Environment/Scenes/AsyncSceneObjectGroupDeleter.cs new file mode 100644 index 0000000..8c43bcb --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/AsyncSceneObjectGroupDeleter.cs | |||
@@ -0,0 +1,146 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Timers; | ||
32 | using log4net; | ||
33 | using OpenMetaverse; | ||
34 | using OpenMetaverse.Packets; | ||
35 | using OpenSim.Framework; | ||
36 | |||
37 | namespace OpenSim.Region.Environment.Scenes | ||
38 | { | ||
39 | class DeleteToInventoryHolder | ||
40 | { | ||
41 | public DeRezObjectPacket DeRezPacket; | ||
42 | public EntityBase selectedEnt; | ||
43 | public IClientAPI remoteClient; | ||
44 | public SceneObjectGroup objectGroup; | ||
45 | public UUID folderID; | ||
46 | public bool permissionToDelete; | ||
47 | } | ||
48 | |||
49 | /// <summary> | ||
50 | /// Asynchronously derez objects. This is used to derez large number of objects to inventory without holding | ||
51 | /// up the main client thread. | ||
52 | /// </summary> | ||
53 | public class AsyncSceneObjectGroupDeleter | ||
54 | { | ||
55 | private static readonly ILog m_log | ||
56 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
57 | |||
58 | private Timer m_inventoryTicker; | ||
59 | private readonly Queue<DeleteToInventoryHolder> m_inventoryDeletes = new Queue<DeleteToInventoryHolder>(); | ||
60 | private Scene m_scene; | ||
61 | |||
62 | public AsyncSceneObjectGroupDeleter(Scene scene) | ||
63 | { | ||
64 | m_scene = scene; | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// Delete the given object from the scene | ||
69 | /// </summary> | ||
70 | public void DeleteToInventory( | ||
71 | DeRezObjectPacket DeRezPacket, UUID folderID, SceneObjectGroup objectGroup, IClientAPI remoteClient, | ||
72 | EntityBase selectedEnt, bool permissionToDelete) | ||
73 | { | ||
74 | if (m_inventoryTicker != null) | ||
75 | { | ||
76 | m_inventoryTicker.Stop(); | ||
77 | } | ||
78 | else | ||
79 | { | ||
80 | m_inventoryTicker = new Timer(2000); | ||
81 | m_inventoryTicker.AutoReset = false; | ||
82 | m_inventoryTicker.Elapsed += InventoryRunDeleteTimer; | ||
83 | } | ||
84 | |||
85 | lock (m_inventoryDeletes) | ||
86 | { | ||
87 | DeleteToInventoryHolder dtis = new DeleteToInventoryHolder(); | ||
88 | dtis.DeRezPacket = DeRezPacket; | ||
89 | dtis.folderID = folderID; | ||
90 | dtis.objectGroup = objectGroup; | ||
91 | dtis.remoteClient = remoteClient; | ||
92 | dtis.selectedEnt = selectedEnt; | ||
93 | dtis.permissionToDelete = permissionToDelete; | ||
94 | |||
95 | m_inventoryDeletes.Enqueue(dtis); | ||
96 | } | ||
97 | |||
98 | m_inventoryTicker.Start(); | ||
99 | |||
100 | // Visually remove it, even if it isnt really gone yet. | ||
101 | if (permissionToDelete) | ||
102 | objectGroup.FakeDeleteGroup(); | ||
103 | } | ||
104 | |||
105 | private void InventoryRunDeleteTimer(object sender, ElapsedEventArgs e) | ||
106 | { | ||
107 | m_log.Info("Starting inventory send loop"); | ||
108 | while (InventoryDeQueueAndDelete() == true) | ||
109 | { | ||
110 | m_log.Info("Returned item successfully, continuing..."); | ||
111 | } | ||
112 | } | ||
113 | |||
114 | private bool InventoryDeQueueAndDelete() | ||
115 | { | ||
116 | DeleteToInventoryHolder x = null; | ||
117 | |||
118 | try | ||
119 | { | ||
120 | lock (m_inventoryDeletes) | ||
121 | { | ||
122 | int left = m_inventoryDeletes.Count; | ||
123 | if (left > 0) | ||
124 | { | ||
125 | m_log.InfoFormat("Sending deleted object to user's inventory, {0} item(s) remaining.", left); | ||
126 | x = m_inventoryDeletes.Dequeue(); | ||
127 | m_scene.DeleteToInventory( | ||
128 | x.DeRezPacket, x.selectedEnt, x.remoteClient, x.objectGroup, x.folderID, x.permissionToDelete); | ||
129 | return true; | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | catch(Exception e) | ||
134 | { | ||
135 | // We can't put the object group details in here since the root part may have disappeared (which is where these sit). | ||
136 | // FIXME: This needs to be fixed. | ||
137 | m_log.ErrorFormat( | ||
138 | "[AGENT INVENTORY]: Queued deletion of scene object to agent {0} {1} failed: {2}", | ||
139 | (x != null ? x.remoteClient.Name : "unavailable"), (x != null ? x.remoteClient.AgentId.ToString() : "unavailable"), e.ToString()); | ||
140 | } | ||
141 | |||
142 | m_log.Info("No objects left in inventory delete queue."); | ||
143 | return false; | ||
144 | } | ||
145 | } | ||
146 | } | ||