2009-05-09 02:49:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) Contributors, http://opensimulator.org/
|
|
|
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2009-06-01 06:37:14 +00:00
|
|
|
* * Neither the name of the OpenSimulator Project nor the
|
2009-05-09 02:49:55 +00:00
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using log4net;
|
2012-11-13 16:49:52 +00:00
|
|
|
using Mono.Addins;
|
2009-05-09 02:49:55 +00:00
|
|
|
using Nini.Config;
|
|
|
|
using System;
|
2009-05-10 12:27:05 +00:00
|
|
|
using System.Collections.Generic;
|
2009-05-09 02:49:55 +00:00
|
|
|
using System.Reflection;
|
2009-05-10 14:03:06 +00:00
|
|
|
using OpenSim.Framework;
|
2009-05-18 12:36:59 +00:00
|
|
|
using OpenSim.Server.Base;
|
2009-05-09 02:49:55 +00:00
|
|
|
using OpenSim.Region.Framework.Interfaces;
|
|
|
|
using OpenSim.Region.Framework.Scenes;
|
|
|
|
using OpenSim.Services.Interfaces;
|
|
|
|
|
2009-06-14 19:44:56 +00:00
|
|
|
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
|
2009-05-09 02:49:55 +00:00
|
|
|
{
|
2012-11-13 16:49:52 +00:00
|
|
|
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalAssetServicesConnector")]
|
2010-02-12 21:32:03 +00:00
|
|
|
public class LocalAssetServicesConnector : ISharedRegionModule, IAssetService
|
2009-05-09 02:49:55 +00:00
|
|
|
{
|
2010-02-12 21:32:03 +00:00
|
|
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
2009-05-09 02:49:55 +00:00
|
|
|
|
2009-05-10 14:03:06 +00:00
|
|
|
private IImprovedAssetCache m_Cache = null;
|
2009-05-10 12:27:05 +00:00
|
|
|
|
2009-05-09 02:49:55 +00:00
|
|
|
private IAssetService m_AssetService;
|
|
|
|
|
|
|
|
private bool m_Enabled = false;
|
|
|
|
|
2009-08-10 22:08:22 +00:00
|
|
|
public Type ReplaceableInterface
|
2009-07-10 20:17:13 +00:00
|
|
|
{
|
|
|
|
get { return null; }
|
|
|
|
}
|
|
|
|
|
2009-05-09 02:49:55 +00:00
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get { return "LocalAssetServicesConnector"; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Initialise(IConfigSource source)
|
|
|
|
{
|
2009-05-17 15:37:50 +00:00
|
|
|
IConfig moduleConfig = source.Configs["Modules"];
|
2009-05-09 02:49:55 +00:00
|
|
|
if (moduleConfig != null)
|
|
|
|
{
|
|
|
|
string name = moduleConfig.GetString("AssetServices", "");
|
|
|
|
if (name == Name)
|
|
|
|
{
|
|
|
|
IConfig assetConfig = source.Configs["AssetService"];
|
|
|
|
if (assetConfig == null)
|
|
|
|
{
|
2010-02-12 21:32:03 +00:00
|
|
|
m_log.Error("[LOCAL ASSET SERVICES CONNECTOR]: AssetService missing from OpenSim.ini");
|
2009-05-09 02:49:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-02 02:23:35 +00:00
|
|
|
string serviceDll = assetConfig.GetString("LocalServiceModule", String.Empty);
|
2009-05-09 02:49:55 +00:00
|
|
|
|
|
|
|
if (serviceDll == String.Empty)
|
|
|
|
{
|
2010-02-12 21:32:03 +00:00
|
|
|
m_log.Error("[LOCAL ASSET SERVICES CONNECTOR]: No LocalServiceModule named in section AssetService");
|
2009-05-09 02:49:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-02 02:23:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Loading asset service at {0}", serviceDll);
|
|
|
|
}
|
2009-05-09 02:49:55 +00:00
|
|
|
|
|
|
|
Object[] args = new Object[] { source };
|
2010-02-12 21:32:03 +00:00
|
|
|
m_AssetService = ServerUtils.LoadPlugin<IAssetService>(serviceDll, args);
|
2009-05-09 02:49:55 +00:00
|
|
|
|
|
|
|
if (m_AssetService == null)
|
|
|
|
{
|
2010-02-12 21:32:03 +00:00
|
|
|
m_log.Error("[LOCAL ASSET SERVICES CONNECTOR]: Can't load asset service");
|
2009-05-09 02:49:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_Enabled = true;
|
2010-02-12 21:32:03 +00:00
|
|
|
m_log.Info("[LOCAL ASSET SERVICES CONNECTOR]: Local asset connector enabled");
|
2009-05-09 02:49:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void PostInitialise()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddRegion(Scene scene)
|
|
|
|
{
|
|
|
|
if (!m_Enabled)
|
|
|
|
return;
|
|
|
|
|
2009-05-10 14:03:06 +00:00
|
|
|
scene.RegisterModuleInterface<IAssetService>(this);
|
2009-05-09 02:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveRegion(Scene scene)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RegionLoaded(Scene scene)
|
|
|
|
{
|
2009-05-10 12:27:05 +00:00
|
|
|
if (!m_Enabled)
|
|
|
|
return;
|
|
|
|
|
2009-05-10 14:03:06 +00:00
|
|
|
if (m_Cache == null)
|
|
|
|
{
|
|
|
|
m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>();
|
|
|
|
|
|
|
|
if (!(m_Cache is ISharedRegionModule))
|
|
|
|
m_Cache = null;
|
|
|
|
}
|
2009-05-10 12:27:05 +00:00
|
|
|
|
2011-08-30 00:58:32 +00:00
|
|
|
m_log.DebugFormat(
|
|
|
|
"[LOCAL ASSET SERVICES CONNECTOR]: Enabled connector for region {0}", scene.RegionInfo.RegionName);
|
2009-05-10 12:27:05 +00:00
|
|
|
|
2009-05-10 14:03:06 +00:00
|
|
|
if (m_Cache != null)
|
2009-05-10 12:27:05 +00:00
|
|
|
{
|
2011-08-30 00:58:32 +00:00
|
|
|
m_log.DebugFormat(
|
|
|
|
"[LOCAL ASSET SERVICES CONNECTOR]: Enabled asset caching for region {0}",
|
|
|
|
scene.RegionInfo.RegionName);
|
2009-05-10 12:27:05 +00:00
|
|
|
}
|
2009-05-10 14:03:06 +00:00
|
|
|
else
|
|
|
|
{
|
2011-08-30 00:58:32 +00:00
|
|
|
// Short-circuit directly to storage layer. This ends up storing temporary and local assets.
|
2009-05-10 14:03:06 +00:00
|
|
|
//
|
|
|
|
scene.UnregisterModuleInterface<IAssetService>(this);
|
|
|
|
scene.RegisterModuleInterface<IAssetService>(m_AssetService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public AssetBase Get(string id)
|
|
|
|
{
|
2010-02-12 21:32:03 +00:00
|
|
|
// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Synchronously requesting asset {0}", id);
|
|
|
|
|
2009-05-22 04:23:59 +00:00
|
|
|
AssetBase asset = null;
|
|
|
|
if (m_Cache != null)
|
|
|
|
asset = m_Cache.Get(id);
|
2009-05-10 14:03:06 +00:00
|
|
|
|
|
|
|
if (asset == null)
|
2009-06-08 19:35:36 +00:00
|
|
|
{
|
|
|
|
asset = m_AssetService.Get(id);
|
|
|
|
if ((m_Cache != null) && (asset != null))
|
|
|
|
m_Cache.Cache(asset);
|
2010-02-12 21:32:03 +00:00
|
|
|
|
|
|
|
// if (null == asset)
|
|
|
|
// m_log.WarnFormat("[LOCAL ASSET SERVICES CONNECTOR]: Could not synchronously find asset with id {0}", id);
|
2009-06-08 19:35:36 +00:00
|
|
|
}
|
2010-02-12 21:32:03 +00:00
|
|
|
|
2009-05-10 14:03:06 +00:00
|
|
|
return asset;
|
|
|
|
}
|
|
|
|
|
2010-04-08 19:31:44 +00:00
|
|
|
public AssetBase GetCached(string id)
|
|
|
|
{
|
2012-01-02 19:46:30 +00:00
|
|
|
// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Cache request for {0}", id);
|
|
|
|
|
2010-04-08 19:31:44 +00:00
|
|
|
if (m_Cache != null)
|
|
|
|
return m_Cache.Get(id);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2009-05-10 14:03:06 +00:00
|
|
|
public AssetMetadata GetMetadata(string id)
|
|
|
|
{
|
2009-05-22 04:23:59 +00:00
|
|
|
AssetBase asset = null;
|
|
|
|
if (m_Cache != null)
|
|
|
|
asset = m_Cache.Get(id);
|
2009-05-10 14:03:06 +00:00
|
|
|
|
|
|
|
if (asset != null)
|
|
|
|
return asset.Metadata;
|
|
|
|
|
|
|
|
asset = m_AssetService.Get(id);
|
2009-05-22 04:23:59 +00:00
|
|
|
if (asset != null)
|
2009-05-10 14:03:06 +00:00
|
|
|
{
|
2009-05-22 04:23:59 +00:00
|
|
|
if (m_Cache != null)
|
|
|
|
m_Cache.Cache(asset);
|
2009-05-10 14:03:06 +00:00
|
|
|
return asset.Metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public byte[] GetData(string id)
|
|
|
|
{
|
2011-04-14 23:42:06 +00:00
|
|
|
// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Requesting data for asset {0}", id);
|
2012-09-15 01:12:26 +00:00
|
|
|
|
|
|
|
AssetBase asset = null;
|
|
|
|
|
|
|
|
if (m_Cache != null)
|
|
|
|
asset = m_Cache.Get(id);
|
2009-05-10 14:03:06 +00:00
|
|
|
|
|
|
|
if (asset != null)
|
|
|
|
return asset.Data;
|
|
|
|
|
|
|
|
asset = m_AssetService.Get(id);
|
|
|
|
if (asset != null)
|
|
|
|
{
|
2009-05-22 04:23:59 +00:00
|
|
|
if (m_Cache != null)
|
|
|
|
m_Cache.Cache(asset);
|
2009-05-10 14:03:06 +00:00
|
|
|
return asset.Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Get(string id, Object sender, AssetRetrieved handler)
|
|
|
|
{
|
2010-02-12 21:32:03 +00:00
|
|
|
// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Asynchronously requesting asset {0}", id);
|
|
|
|
|
2009-05-22 04:23:59 +00:00
|
|
|
if (m_Cache != null)
|
2009-05-10 14:03:06 +00:00
|
|
|
{
|
2010-02-12 21:32:03 +00:00
|
|
|
AssetBase asset = m_Cache.Get(id);
|
|
|
|
|
|
|
|
if (asset != null)
|
|
|
|
{
|
2014-11-04 00:55:48 +00:00
|
|
|
Util.FireAndForget(
|
|
|
|
o => handler(id, sender, asset), null, "LocalAssetServiceConnector.GotFromCacheCallback");
|
2010-02-12 21:32:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-10 14:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_AssetService.Get(id, sender, delegate (string assetID, Object s, AssetBase a)
|
|
|
|
{
|
2009-05-22 04:23:59 +00:00
|
|
|
if ((a != null) && (m_Cache != null))
|
2009-05-10 14:03:06 +00:00
|
|
|
m_Cache.Cache(a);
|
2009-09-01 19:07:48 +00:00
|
|
|
|
2010-02-12 21:32:03 +00:00
|
|
|
// if (null == a)
|
2010-02-15 10:15:03 +00:00
|
|
|
// m_log.WarnFormat("[LOCAL ASSET SERVICES CONNECTOR]: Could not asynchronously find asset with id {0}", id);
|
2010-02-12 21:32:03 +00:00
|
|
|
|
2014-11-04 00:55:48 +00:00
|
|
|
Util.FireAndForget(
|
|
|
|
o => handler(assetID, s, a), null, "LocalAssetServiceConnector.GotFromServiceCallback");
|
2009-05-10 14:03:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-31 08:53:12 +00:00
|
|
|
public bool[] AssetsExist(string[] ids)
|
|
|
|
{
|
|
|
|
return m_AssetService.AssetsExist(ids);
|
|
|
|
}
|
|
|
|
|
2009-05-10 14:03:06 +00:00
|
|
|
public string Store(AssetBase asset)
|
|
|
|
{
|
2009-05-22 04:23:59 +00:00
|
|
|
if (m_Cache != null)
|
|
|
|
m_Cache.Cache(asset);
|
2009-06-01 16:00:46 +00:00
|
|
|
|
2013-06-10 20:26:19 +00:00
|
|
|
if (asset.Local)
|
2011-08-30 00:58:32 +00:00
|
|
|
{
|
|
|
|
// m_log.DebugFormat(
|
|
|
|
// "[LOCAL ASSET SERVICE CONNECTOR]: Returning asset {0} {1} without querying database since status Temporary = {2}, Local = {3}",
|
|
|
|
// asset.Name, asset.ID, asset.Temporary, asset.Local);
|
|
|
|
|
2009-05-14 03:07:00 +00:00
|
|
|
return asset.ID;
|
2011-08-30 00:58:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// m_log.DebugFormat(
|
|
|
|
// "[LOCAL ASSET SERVICE CONNECTOR]: Passing {0} {1} on to asset service for storage, status Temporary = {2}, Local = {3}",
|
|
|
|
// asset.Name, asset.ID, asset.Temporary, asset.Local);
|
|
|
|
|
|
|
|
return m_AssetService.Store(asset);
|
|
|
|
}
|
2009-05-10 14:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool UpdateContent(string id, byte[] data)
|
|
|
|
{
|
2009-05-22 04:23:59 +00:00
|
|
|
AssetBase asset = null;
|
|
|
|
if (m_Cache != null)
|
|
|
|
m_Cache.Get(id);
|
2009-05-10 14:03:06 +00:00
|
|
|
if (asset != null)
|
|
|
|
{
|
|
|
|
asset.Data = data;
|
2009-05-22 04:23:59 +00:00
|
|
|
if (m_Cache != null)
|
|
|
|
m_Cache.Cache(asset);
|
2009-05-10 14:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_AssetService.UpdateContent(id, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Delete(string id)
|
|
|
|
{
|
2009-05-22 04:23:59 +00:00
|
|
|
if (m_Cache != null)
|
|
|
|
m_Cache.Expire(id);
|
2009-05-10 14:03:06 +00:00
|
|
|
|
|
|
|
return m_AssetService.Delete(id);
|
2009-05-09 02:49:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|