From aac8ca041170f6d1d648c6c5244dc3dfad428587 Mon Sep 17 00:00:00 2001 From: diva Date: Sun, 17 May 2009 01:38:43 +0000 Subject: HG asset transfers starting to work -- GETs only for now. --- OpenSim/Services/AssetService/AssetService.cs | 1 + OpenSim/Services/AssetService/HGAssetService.cs | 80 +++++++++++++++++++++---- 2 files changed, 68 insertions(+), 13 deletions(-) (limited to 'OpenSim/Services/AssetService') diff --git a/OpenSim/Services/AssetService/AssetService.cs b/OpenSim/Services/AssetService/AssetService.cs index af3a746..968cf5c 100644 --- a/OpenSim/Services/AssetService/AssetService.cs +++ b/OpenSim/Services/AssetService/AssetService.cs @@ -66,6 +66,7 @@ namespace OpenSim.Services.AssetService public AssetBase Get(string id) { + m_log.DebugFormat("[ASSET SERVICE]: Get asset {0}", id); UUID assetID; if (!UUID.TryParse(id, out assetID)) diff --git a/OpenSim/Services/AssetService/HGAssetService.cs b/OpenSim/Services/AssetService/HGAssetService.cs index 87e42fe..0b6389f 100644 --- a/OpenSim/Services/AssetService/HGAssetService.cs +++ b/OpenSim/Services/AssetService/HGAssetService.cs @@ -28,11 +28,13 @@ using log4net; using Nini.Config; using System; +using System.Collections.Generic; using System.Reflection; using OpenSim.Framework; +using OpenSim.Servers.Connectors; using OpenSim.Services.Interfaces; -namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset +namespace OpenSim.Services.AssetService { public class HGAssetService : IAssetService { @@ -40,6 +42,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType); + private Dictionary m_connectors = new Dictionary(); + public HGAssetService(IConfigSource source) { IConfig moduleConfig = source.Configs["ServiceConnectors"]; @@ -50,27 +54,68 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset IConfig assetConfig = source.Configs["AssetService"]; if (assetConfig == null) { - m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpanSim.ini"); + m_log.Error("[HG ASSET SERVICE]: AssetService missing from OpanSim.ini"); return; } - m_log.Info("[ASSET CONNECTOR]: HG asset service enabled"); + m_log.Info("[HG ASSET SERVICE]: HG asset service enabled"); } } - // - // Note to Diva: - // - // This is not the broker! - // This module is not supposed to route anything anywhere. This is where - // the code to access remote assets (by URL) goes. It can be assumed - // that the ID is a URL. The broker makes sure of that. - // - // This is a disposable comment :) Feel free to remove it - // + private bool StringToUrlAndAssetID(string id, out string url, out string assetID) + { + url = String.Empty; + assetID = String.Empty; + + Uri assetUri; + + if (Uri.TryCreate(id, UriKind.Absolute, out assetUri) && + assetUri.Scheme == Uri.UriSchemeHttp) + { + url = "http://" + assetUri.Authority; + assetID = assetUri.LocalPath; + return true; + } + + return false; + } + + private IAssetService GetConnector(string url) + { + AssetServicesConnector connector = null; + lock (m_connectors) + { + if (m_connectors.ContainsKey(url)) + { + connector = m_connectors[url]; + } + else + { + // We're instantiating this class explicitly, but this won't + // work in general, because the remote grid may be running + // an asset server that has a different protocol. + // Eventually we will want a piece of meta-protocol asking + // the remote server about its kind, and even asking it + // to send its own connector, which we would instantiate + // dynamically. Definitely coo, thing to do! + connector = new AssetServicesConnector(url); + m_connectors.Add(url, connector); + } + } + return connector; + } public AssetBase Get(string id) { + string url = string.Empty; + string assetID = string.Empty; + + if (StringToUrlAndAssetID(id, out url, out assetID)) + { + IAssetService connector = GetConnector(url); + return connector.Get(assetID); + } + return null; } @@ -86,6 +131,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset public bool Get(string id, Object sender, AssetRetrieved handler) { + string url = string.Empty; + string assetID = string.Empty; + + if (StringToUrlAndAssetID(id, out url, out assetID)) + { + IAssetService connector = GetConnector(url); + return connector.Get(assetID, sender, handler); + } + return false; } -- cgit v1.1