Finished HG Service Store. Not fully functional because of problems with asset.ID insisting on being a UUID string.

0.6.6-post-fixes
diva 2009-05-18 20:04:59 +00:00
parent 1cc9d1fd8d
commit 13da5a9fba
3 changed files with 47 additions and 39 deletions

View File

@ -178,8 +178,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
if (asset != null) if (asset != null)
return asset; return asset;
else
m_log.DebugFormat("[HG ASSSET CONNECTOR]: Requested asset is not in cache. This shouldn't happen.");
} }
if (IsHG(id)) if (IsHG(id))
@ -295,7 +293,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
public string Store(AssetBase asset) public string Store(AssetBase asset)
{ {
if (m_Cache != null) bool isHG = IsHG(asset.ID);
if ((m_Cache != null) && !isHG)
// Don't store it in the cache if the asset is to
// be sent to the other grid, because this is already
// a copy of the local asset.
m_Cache.Cache(asset); m_Cache.Cache(asset);
if (asset.Temporary || asset.Local) if (asset.Temporary || asset.Local)

View File

@ -120,25 +120,30 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid
return null; return null;
} }
private bool PostAsset(GridAssetClient asscli, UUID assetID, bool isTexture) private bool PostAsset(string url, AssetBase asset)
{ {
AssetBase asset1; if (asset != null)
//m_scene.CommsManager.AssetCache.TryGetCachedAsset(assetID, out asset1);
asset1 = m_scene.CommsManager.AssetCache.GetAsset(assetID, isTexture);
if (asset1 != null)
{ {
// See long comment in AssetCache.AddAsset // See long comment in AssetCache.AddAsset
if (!asset1.Temporary || asset1.Local) if (!asset.Temporary || asset.Local)
{ {
// The asset cache returns instances of subclasses of AssetBase: // We need to copy the asset into a new asset, because
// TextureImage or AssetInfo. So in passing them to the remote // we need to set its ID to be URL+UUID, so that the
// server we first need to convert this to instances of AssetBase, // HGAssetService dispatches it to the remote grid.
// which is the serializable class for assets. // It's not pretty, but the best that can be done while
AssetBase asset = new AssetBase(); // not having a global naming infrastructure
Copy(asset1, asset); AssetBase asset1 = new AssetBase();
Copy(asset, asset1);
try
{
asset1.ID = url + "/" + asset.ID;
}
catch
{
m_log.Warn("[HGScene]: This won't work until Melanie kills a few more dragons");
}
asscli.StoreAsset(asset); m_scene.AssetService.Store(asset1);
} }
return true; return true;
} }
@ -315,46 +320,35 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid
{ {
if (!IsLocalUser(ownerID)) if (!IsLocalUser(ownerID))
{ {
// Post the item from the local AssetCache ontp the remote asset server // Post the item from the local AssetCache onto the remote asset server
// and place an entry in m_assetMap // and place an entry in m_assetMap
GridAssetClient asscli = null;
string userAssetURL = UserAssetURL(ownerID); string userAssetURL = UserAssetURL(ownerID);
if (userAssetURL != null) if (userAssetURL != null)
{ {
m_assetServers.TryGetValue(userAssetURL, out asscli);
if (asscli == null)
{
m_log.Debug("[HGScene]: Starting new GridAssetClient for " + userAssetURL);
asscli = new GridAssetClient(userAssetURL);
asscli.SetReceiver(m_scene.CommsManager.AssetCache); // Straight to the asset cache!
m_assetServers.Add(userAssetURL, asscli);
}
m_log.Debug("[HGScene]: Posting object " + assetID + " to asset server " + userAssetURL); m_log.Debug("[HGScene]: Posting object " + assetID + " to asset server " + userAssetURL);
AssetBase ass1 = null; AssetBase ass1 = m_scene.AssetService.Get(assetID.ToString());
m_scene.CommsManager.AssetCache.TryGetCachedAsset(assetID, out ass1);
if (ass1 != null) if (ass1 != null)
{ {
bool success = PostAsset(asscli, assetID, (ass1.Type == (sbyte)AssetType.Texture)); bool success = PostAsset(userAssetURL, ass1);
// Now the inside // Now the inside
Dictionary<UUID, bool> ids = SniffUUIDs(assetID); Dictionary<UUID, bool> ids = SniffUUIDs(assetID);
Dump(ids); Dump(ids);
foreach (KeyValuePair<UUID, bool> kvp in ids) foreach (KeyValuePair<UUID, bool> kvp in ids)
PostAsset(asscli, kvp.Key, kvp.Value); {
ass1 = m_scene.AssetService.Get(kvp.Key.ToString());
PostAsset(userAssetURL, ass1);
}
if (success) if (success)
{ m_log.DebugFormat("[HGScene]: Successfully posted item {0} to remote asset server {1}", assetID, userAssetURL);
m_log.Debug("[HGScene]: Successfully posted item to remote asset server " + userAssetURL);
if (!m_assetMap.ContainsKey(assetID))
m_assetMap.Add(assetID, asscli);
}
else else
m_log.Warn("[HGScene]: Could not post asset to remote asset server " + userAssetURL); m_log.WarnFormat("[HGScene]: Could not post asset {0} to remote asset server {1}", assetID, userAssetURL);
} }
else else
m_log.Debug("[HGScene]: Something wrong with asset"); m_log.Debug("[HGScene]: Something wrong with asset, it could not be found");
} }
else else
m_log.Warn("[HGScene]: Unable to locate foreign user's asset server"); m_log.Warn("[HGScene]: Unable to locate foreign user's asset server");

View File

@ -94,7 +94,7 @@ namespace OpenSim.Services.AssetService
// We're instantiating this class explicitly, but this won't // We're instantiating this class explicitly, but this won't
// work in general, because the remote grid may be running // work in general, because the remote grid may be running
// an asset server that has a different protocol. // an asset server that has a different protocol.
// Eventually we will want a piece of meta-protocol asking // Eventually we will want a piece of protocol asking
// the remote server about its kind. Definitely cool thing to do! // the remote server about its kind. Definitely cool thing to do!
connector = new AssetServicesConnector(url); connector = new AssetServicesConnector(url);
m_connectors.Add(url, connector); m_connectors.Add(url, connector);
@ -152,6 +152,17 @@ namespace OpenSim.Services.AssetService
public string Store(AssetBase asset) public string Store(AssetBase asset)
{ {
string url = string.Empty;
string assetID = string.Empty;
if (StringToUrlAndAssetID(asset.ID, out url, out assetID))
{
IAssetService connector = GetConnector(url);
// Restore the assetID to a simple UUID
asset.ID = assetID;
return connector.Store(asset);
}
return String.Empty; return String.Empty;
} }