diff options
author | Justin Clarke Casey | 2008-06-16 15:36:01 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-06-16 15:36:01 +0000 |
commit | ba69cc31e5bfb3386880d4bc142df236531ab055 (patch) | |
tree | a1a6013b72f01b336aef115ac34d1cde6a4c29da /OpenSim/Region/Environment/Modules/World/Archiver/AssetsRequest.cs | |
parent | the beginning of the great id format migration. This makes (diff) | |
download | opensim-SC-ba69cc31e5bfb3386880d4bc142df236531ab055.zip opensim-SC-ba69cc31e5bfb3386880d4bc142df236531ab055.tar.gz opensim-SC-ba69cc31e5bfb3386880d4bc142df236531ab055.tar.bz2 opensim-SC-ba69cc31e5bfb3386880d4bc142df236531ab055.tar.xz |
* Refactor: Break out AssetsRequest to a separate file in the Archiver module
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Archiver/AssetsRequest.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Archiver/AssetsRequest.cs | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/AssetsRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/AssetsRequest.cs new file mode 100644 index 0000000..2021b70 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Archiver/AssetsRequest.cs | |||
@@ -0,0 +1,105 @@ | |||
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 OpenSim.Framework; | ||
29 | using OpenSim.Framework.Communications.Cache; | ||
30 | using OpenSim.Region.Environment.Interfaces; | ||
31 | using OpenSim.Region.Environment.Scenes; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Threading; | ||
34 | using libsecondlife; | ||
35 | |||
36 | namespace OpenSim.Region.Environment.Modules.World.Archiver | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// Encapsulate the asynchronous requests for the assets required for an archive operation | ||
40 | /// </summary> | ||
41 | class AssetsRequest | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// Callback used when all the assets requested have been received. | ||
45 | /// </summary> | ||
46 | protected AssetsRequestCallback m_assetsRequestCallback; | ||
47 | |||
48 | /// <summary> | ||
49 | /// Assets retrieved in this request | ||
50 | /// </summary> | ||
51 | protected Dictionary<LLUUID, AssetBase> m_assets = new Dictionary<LLUUID, AssetBase>(); | ||
52 | |||
53 | /// <summary> | ||
54 | /// Record the number of asset replies required so we know when we've finished | ||
55 | /// </summary> | ||
56 | private int m_repliesRequired; | ||
57 | |||
58 | /// <summary> | ||
59 | /// Asset cache used to request the assets | ||
60 | /// </summary> | ||
61 | protected AssetCache m_assetCache; | ||
62 | |||
63 | protected internal AssetsRequest(AssetsRequestCallback assetsRequestCallback, AssetCache assetCache, ICollection<LLUUID> uuids) | ||
64 | { | ||
65 | m_assetsRequestCallback = assetsRequestCallback; | ||
66 | m_assetCache = assetCache; | ||
67 | m_repliesRequired = uuids.Count; | ||
68 | |||
69 | // We can stop here if there are no assets to fetch | ||
70 | if (m_repliesRequired == 0) | ||
71 | m_assetsRequestCallback(m_assets); | ||
72 | |||
73 | foreach (LLUUID uuid in uuids) | ||
74 | { | ||
75 | m_assetCache.GetAsset(uuid, AssetRequestCallback, true); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | /// <summary> | ||
80 | /// Called back by the asset cache when it has the asset | ||
81 | /// </summary> | ||
82 | /// <param name="assetID"></param> | ||
83 | /// <param name="asset"></param> | ||
84 | public void AssetRequestCallback(LLUUID assetID, AssetBase asset) | ||
85 | { | ||
86 | m_assets[assetID] = asset; | ||
87 | |||
88 | if (m_assets.Count == m_repliesRequired) | ||
89 | { | ||
90 | // We want to stop using the asset cache thread asap as we now need to do the actual work of producing the archive | ||
91 | Thread newThread = new Thread(PerformAssetsRequestCallback); | ||
92 | newThread.Name = "OpenSimulator archiving thread post assets receipt"; | ||
93 | newThread.Start(); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | /// <summary> | ||
98 | /// Perform the callback on the original requester of the assets | ||
99 | /// </summary> | ||
100 | protected void PerformAssetsRequestCallback() | ||
101 | { | ||
102 | m_assetsRequestCallback(m_assets); | ||
103 | } | ||
104 | } | ||
105 | } | ||