aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-05-27 14:21:32 +0000
committerJustin Clarke Casey2008-05-27 14:21:32 +0000
commit64821ac0a12f838211bd8150663914d6682bb7e1 (patch)
tree1bf1087e56b328c35b3f2a223a50ab01738387d3 /OpenSim
parentThank you very much, Xantor for a patch that: (diff)
downloadopensim-SC_OLD-64821ac0a12f838211bd8150663914d6682bb7e1.zip
opensim-SC_OLD-64821ac0a12f838211bd8150663914d6682bb7e1.tar.gz
opensim-SC_OLD-64821ac0a12f838211bd8150663914d6682bb7e1.tar.bz2
opensim-SC_OLD-64821ac0a12f838211bd8150663914d6682bb7e1.tar.xz
* Implement asynchronous assets request for archiving
* No user functionality yet
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs303
1 files changed, 187 insertions, 116 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs
index 1ebf3e0..867aa3a 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveRequest.cs
@@ -1,116 +1,187 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using OpenSim.Framework.Communications.Cache; 28using OpenSim.Framework;
29using OpenSim.Region.Environment.Interfaces; 29using OpenSim.Framework.Communications.Cache;
30using OpenSim.Region.Environment.Modules.World.Serialiser; 30using OpenSim.Region.Environment.Interfaces;
31using OpenSim.Region.Environment.Scenes; 31using OpenSim.Region.Environment.Modules.World.Serialiser;
32using System.Collections.Generic; 32using OpenSim.Region.Environment.Scenes;
33using System.Reflection; 33using System.Collections.Generic;
34using libsecondlife; 34using System.Reflection;
35using log4net; 35using libsecondlife;
36using Nini.Config; 36using log4net;
37 37using Nini.Config;
38namespace OpenSim.Region.Environment 38
39{ 39namespace OpenSim.Region.Environment
40 /// <summary> 40{
41 /// Handles an individual archive request 41 /// <summary>
42 /// </summary> 42 /// Method called when all the necessary assets for an archive request have been received.
43 public class ArchiveRequest 43 /// </summary>
44 { 44 public delegate void AssetsRequestCallback(IDictionary<LLUUID, AssetBase> assets);
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45
46 46 /// <summary>
47 private Scene m_scene; 47 /// Handles an individual archive request
48 private string m_savePath; 48 /// </summary>
49 49 public class ArchiveRequest
50 public ArchiveRequest(Scene scene, string savePath) 50 {
51 { 51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 m_scene = scene; 52
53 m_savePath = savePath; 53 private Scene m_scene;
54 54 private string m_savePath;
55 ArchiveRegion(); 55
56 } 56 public ArchiveRequest(Scene scene, string savePath)
57 57 {
58 protected void ArchiveRegion() 58 m_scene = scene;
59 { 59 m_savePath = savePath;
60 m_log.Warn("[ARCHIVER]: Archive region not yet implemented"); 60
61 61 ArchiveRegion();
62 Dictionary<LLUUID, int> textureUuids = new Dictionary<LLUUID, int>(); 62 }
63 63
64 List<EntityBase> entities = m_scene.GetEntities(); 64 protected void ArchiveRegion()
65 65 {
66 foreach (EntityBase entity in entities) 66 m_log.Warn("[ARCHIVER]: Archive region not yet implemented");
67 { 67
68 if (entity is SceneObjectGroup) 68 Dictionary<LLUUID, int> textureUuids = new Dictionary<LLUUID, int>();
69 { 69
70 SceneObjectGroup sceneObject = (SceneObjectGroup)entity; 70 List<EntityBase> entities = m_scene.GetEntities();
71 71
72 foreach (SceneObjectPart part in sceneObject.GetParts()) 72 foreach (EntityBase entity in entities)
73 { 73 {
74 LLUUID texture = new LLUUID(part.Shape.TextureEntry, 0); 74 if (entity is SceneObjectGroup)
75 textureUuids[texture] = 1; 75 {
76 } 76 SceneObjectGroup sceneObject = (SceneObjectGroup)entity;
77 } 77
78 } 78 foreach (SceneObjectPart part in sceneObject.GetParts())
79 79 {
80 string serEntities = SerializeObjects(entities); 80 LLUUID texture = new LLUUID(part.Shape.TextureEntry, 0);
81 81 textureUuids[texture] = 1;
82 if (serEntities != null && serEntities.Length > 0) 82 }
83 { 83 }
84 m_log.DebugFormat("[ARCHIVER]: Successfully got serialization for {0} entities", entities.Count); 84 }
85 m_log.DebugFormat("[ARCHIVER]: Requiring save of {0} textures", textureUuids.Count); 85
86 } 86 string serEntities = SerializeObjects(entities);
87 } 87
88 88 if (serEntities != null && serEntities.Length > 0)
89 /// <summary> 89 {
90 /// Get an xml representation of the given scene objects. 90 m_log.DebugFormat("[ARCHIVER]: Successfully got serialization for {0} entities", entities.Count);
91 /// </summary> 91 m_log.DebugFormat("[ARCHIVER]: Requiring save of {0} textures", textureUuids.Count);
92 /// <param name="scene"></param> 92
93 /// <returns></returns> 93 // Asynchronously request all the assets required to perform this archive operation
94 protected static string SerializeObjects(List<EntityBase> entities) 94 new AssetsRequest(ReceivedAllAssets, m_scene.AssetCache, textureUuids.Keys);
95 { 95 }
96 string serialization = "<scene>"; 96 }
97 97
98 List<string> serObjects = new List<string>(); 98 protected internal void ReceivedAllAssets(IDictionary<LLUUID, AssetBase> assets)
99 99 {
100 foreach (EntityBase ent in entities) 100 m_log.DebugFormat("[ARCHIVER]: Received all {0} textures required", assets.Count);
101 { 101 }
102 if (ent is SceneObjectGroup) 102
103 { 103 /// <summary>
104 serObjects.Add(((SceneObjectGroup) ent).ToXmlString2()); 104 /// Get an xml representation of the given scene objects.
105 } 105 /// </summary>
106 } 106 /// <param name="scene"></param>
107 107 /// <returns></returns>
108 foreach (string serObject in serObjects) 108 protected static string SerializeObjects(List<EntityBase> entities)
109 serialization += serObject; 109 {
110 110 string serialization = "<scene>";
111 serialization += "</scene>"; 111
112 112 List<string> serObjects = new List<string>();
113 return serialization; 113
114 } 114 foreach (EntityBase ent in entities)
115 } 115 {
116} 116 if (ent is SceneObjectGroup)
117 {
118 serObjects.Add(((SceneObjectGroup) ent).ToXmlString2());
119 }
120 }
121
122 foreach (string serObject in serObjects)
123 serialization += serObject;
124
125 serialization += "</scene>";
126
127 return serialization;
128 }
129 }
130
131 /// <summary>
132 /// Encapsulate the asynchronous requests for the assets required for an archive operation
133 /// </summary>
134 class AssetsRequest
135 {
136 /// <summary>
137 /// Callback used when all the assets requested have been received.
138 /// </summary>
139 protected AssetsRequestCallback m_assetsRequestCallback;
140
141 /// <summary>
142 /// Assets retrieved in this request
143 /// </summary>
144 protected Dictionary<LLUUID, AssetBase> m_assets = new Dictionary<LLUUID, AssetBase>();
145
146 /// <summary>
147 /// Record the number of asset replies required so we know when we've finished
148 /// </summary>
149 private int m_repliesRequired;
150
151 /// <summary>
152 /// Asset cache used to request the assets
153 /// </summary>
154 protected AssetCache m_assetCache;
155
156 protected internal AssetsRequest(AssetsRequestCallback assetsRequestCallback, AssetCache assetCache, ICollection<LLUUID> uuids)
157 {
158 m_assetsRequestCallback = assetsRequestCallback;
159 m_assetCache = assetCache;
160 m_repliesRequired = uuids.Count;
161
162 // We can stop here if there are no assets to fetch
163 if (m_repliesRequired == 0)
164 m_assetsRequestCallback(m_assets);
165
166 foreach (LLUUID uuid in uuids)
167 {
168 m_assetCache.GetAsset(uuid, AssetRequestCallback, true);
169 }
170 }
171
172 /// <summary>
173 /// Called back by the asset cache when it has the asset
174 /// </summary>
175 /// <param name="assetID"></param>
176 /// <param name="asset"></param>
177 public void AssetRequestCallback(LLUUID assetID, AssetBase asset)
178 {
179 m_assets[assetID] = asset;
180
181 if (m_assets.Count == m_repliesRequired)
182 {
183 m_assetsRequestCallback(m_assets);
184 }
185 }
186 }
187}