diff options
author | Justin Clarke Casey | 2008-09-29 19:09:49 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-09-29 19:09:49 +0000 |
commit | 941e20c46341bbb16d9c718a47d960dcaced939d (patch) | |
tree | 6b2a0986a048c46f755caf80b67fb5d8f8ebbb86 /OpenSim/Region | |
parent | ApplyImpulse now forwards impulse in both local and global modes. (diff) | |
download | opensim-SC-941e20c46341bbb16d9c718a47d960dcaced939d.zip opensim-SC-941e20c46341bbb16d9c718a47d960dcaced939d.tar.gz opensim-SC-941e20c46341bbb16d9c718a47d960dcaced939d.tar.bz2 opensim-SC-941e20c46341bbb16d9c718a47d960dcaced939d.tar.xz |
* refactor: move asynchronous scene object deletion to inventory queueing out to a separate class
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/AsyncSceneObjectGroupDeleter.cs | 146 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Scenes/Scene.Inventory.cs | 101 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Scenes/Scene.cs | 1 |
3 files changed, 165 insertions, 83 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 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs index 5ff6dec..8557b1c 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs | |||
@@ -40,23 +40,15 @@ using OpenSim.Region.Environment.Interfaces; | |||
40 | 40 | ||
41 | namespace OpenSim.Region.Environment.Scenes | 41 | namespace OpenSim.Region.Environment.Scenes |
42 | { | 42 | { |
43 | class DeleteToInventoryHolder | ||
44 | { | ||
45 | public DeRezObjectPacket DeRezPacket; | ||
46 | public EntityBase selectedEnt; | ||
47 | public IClientAPI remoteClient; | ||
48 | public SceneObjectGroup objectGroup; | ||
49 | public UUID folderID; | ||
50 | public bool permissionToDelete; | ||
51 | } | ||
52 | |||
53 | public partial class Scene | 43 | public partial class Scene |
54 | { | 44 | { |
55 | private Timer m_inventoryTicker; | ||
56 | private readonly Queue<DeleteToInventoryHolder> m_inventoryDeletes = new Queue<DeleteToInventoryHolder>(); | ||
57 | |||
58 | private static readonly ILog m_log | 45 | private static readonly ILog m_log |
59 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 46 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
47 | |||
48 | /// <summary> | ||
49 | /// Allows asynchronous derezzing of objects from the scene into a client's inventory. | ||
50 | /// </summary> | ||
51 | private AsyncSceneObjectGroupDeleter m_asyncSceneObjectDeleter; | ||
60 | 52 | ||
61 | /// <summary> | 53 | /// <summary> |
62 | /// Start all the scripts in the scene which should be started. | 54 | /// Start all the scripts in the scene which should be started. |
@@ -1546,35 +1538,8 @@ namespace OpenSim.Region.Environment.Scenes | |||
1546 | 1538 | ||
1547 | if (permissionToTake) | 1539 | if (permissionToTake) |
1548 | { | 1540 | { |
1549 | if (m_inventoryTicker != null) | 1541 | m_asyncSceneObjectDeleter.DeleteToInventory( |
1550 | { | 1542 | DeRezPacket, folderID, objectGroup, remoteClient, selectedEnt, permissionToDelete); |
1551 | m_inventoryTicker.Stop(); | ||
1552 | } | ||
1553 | else | ||
1554 | { | ||
1555 | m_inventoryTicker = new Timer(2000); | ||
1556 | m_inventoryTicker.AutoReset = false; | ||
1557 | m_inventoryTicker.Elapsed += InventoryRunDeleteTimer; | ||
1558 | } | ||
1559 | |||
1560 | lock (m_inventoryDeletes) | ||
1561 | { | ||
1562 | DeleteToInventoryHolder dtis = new DeleteToInventoryHolder(); | ||
1563 | dtis.DeRezPacket = DeRezPacket; | ||
1564 | dtis.folderID = folderID; | ||
1565 | dtis.objectGroup = objectGroup; | ||
1566 | dtis.remoteClient = remoteClient; | ||
1567 | dtis.selectedEnt = selectedEnt; | ||
1568 | dtis.permissionToDelete = permissionToDelete; | ||
1569 | |||
1570 | m_inventoryDeletes.Enqueue(dtis); | ||
1571 | } | ||
1572 | |||
1573 | m_inventoryTicker.Start(); | ||
1574 | |||
1575 | // Visually remove it, even if it isnt really gone yet. | ||
1576 | if (permissionToDelete) | ||
1577 | objectGroup.FakeDeleteGroup(); | ||
1578 | } | 1543 | } |
1579 | else if (permissionToDelete) | 1544 | else if (permissionToDelete) |
1580 | { | 1545 | { |
@@ -1584,47 +1549,17 @@ namespace OpenSim.Region.Environment.Scenes | |||
1584 | } | 1549 | } |
1585 | } | 1550 | } |
1586 | 1551 | ||
1587 | void InventoryRunDeleteTimer(object sender, ElapsedEventArgs e) | 1552 | /// <summary> |
1588 | { | 1553 | /// Delete a scene object from a scene and place in the given avatar's inventory. |
1589 | m_log.Info("Starting inventory send loop"); | 1554 | /// </summary> |
1590 | while (InventoryDeQueueAndDelete() == true) | 1555 | /// <param name="DeRezPacket"></param> |
1591 | { | 1556 | /// <param name="selectedEnt"></param> |
1592 | m_log.Info("Returned item successfully, continuing..."); | 1557 | /// <param name="remoteClient"> </param> |
1593 | } | 1558 | /// <param name="objectGroup"></param> |
1594 | } | 1559 | /// <param name="folderID"></param> |
1595 | 1560 | /// <param name="permissionToDelete"></param> | |
1596 | private bool InventoryDeQueueAndDelete() | 1561 | public void DeleteToInventory(DeRezObjectPacket DeRezPacket, EntityBase selectedEnt, IClientAPI remoteClient, |
1597 | { | 1562 | SceneObjectGroup objectGroup, UUID folderID, bool permissionToDelete) |
1598 | DeleteToInventoryHolder x = null; | ||
1599 | |||
1600 | try | ||
1601 | { | ||
1602 | lock (m_inventoryDeletes) | ||
1603 | { | ||
1604 | int left = m_inventoryDeletes.Count; | ||
1605 | if (left > 0) | ||
1606 | { | ||
1607 | m_log.InfoFormat("Sending deleted object to user's inventory, {0} item(s) remaining.", left); | ||
1608 | x = m_inventoryDeletes.Dequeue(); | ||
1609 | DeleteToInventory(x.DeRezPacket, x.selectedEnt, x.remoteClient, x.objectGroup, x.folderID, x.permissionToDelete); | ||
1610 | return true; | ||
1611 | } | ||
1612 | } | ||
1613 | } | ||
1614 | catch(Exception e) | ||
1615 | { | ||
1616 | // We can't put the object group details in here since the root part may have disappeared (which is where these sit). | ||
1617 | // FIXME: This needs to be fixed. | ||
1618 | m_log.ErrorFormat( | ||
1619 | "[AGENT INVENTORY]: Queued deletion of scene object to agent {0} {1} failed: {2}", | ||
1620 | (x != null ? x.remoteClient.Name : "unavailable"), (x != null ? x.remoteClient.AgentId.ToString() : "unavailable"), e.ToString()); | ||
1621 | } | ||
1622 | |||
1623 | m_log.Info("No objects left in inventory delete queue."); | ||
1624 | return false; | ||
1625 | } | ||
1626 | |||
1627 | private void DeleteToInventory(DeRezObjectPacket DeRezPacket, EntityBase selectedEnt, IClientAPI remoteClient, SceneObjectGroup objectGroup, UUID folderID, bool permissionToDelete) | ||
1628 | { | 1563 | { |
1629 | string sceneObjectXml = objectGroup.ToXmlString(); | 1564 | string sceneObjectXml = objectGroup.ToXmlString(); |
1630 | 1565 | ||
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 42e9c02..88da9be 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs | |||
@@ -275,6 +275,7 @@ namespace OpenSim.Region.Environment.Scenes | |||
275 | 275 | ||
276 | m_eventManager = new EventManager(); | 276 | m_eventManager = new EventManager(); |
277 | m_externalChecks = new SceneExternalChecks(this); | 277 | m_externalChecks = new SceneExternalChecks(this); |
278 | m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); | ||
278 | 279 | ||
279 | // Load region settings | 280 | // Load region settings |
280 | m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID); | 281 | m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID); |