IAssetCache.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 OpenSimulator 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. using OpenMetaverse;
  28. using OpenMetaverse.Packets;
  29. namespace OpenSim.Framework
  30. {
  31. public delegate void AssetRequestCallback(UUID assetId, AssetBase asset);
  32. /// <summary>
  33. /// Interface to the local asset cache. This is the mechanism through which assets can be added and requested.
  34. /// </summary>
  35. public interface IAssetCache : IAssetReceiver, IPlugin
  36. {
  37. /// <value>
  38. /// The 'server' from which assets can be requested and to which assets are persisted.
  39. /// </value>
  40. IAssetServer AssetServer { get; }
  41. void Initialise(ConfigSettings cs, IAssetServer server);
  42. /// <summary>
  43. /// Report statistical data to the log.
  44. /// </summary>
  45. void ShowState();
  46. /// <summary>
  47. /// Clear the asset cache.
  48. /// </summary>
  49. void Clear();
  50. /// <summary>
  51. /// Get an asset only if it's already in the cache.
  52. /// </summary>
  53. /// <param name="assetId"></param>
  54. /// <param name="asset"></param>
  55. /// <returns>true if the asset was in the cache, false if it was not</returns>
  56. bool TryGetCachedAsset(UUID assetID, out AssetBase asset);
  57. /// <summary>
  58. /// Asynchronously retrieve an asset.
  59. /// </summary>
  60. /// <param name="assetId"></param>
  61. /// <param name="callback">
  62. /// <param name="isTexture"></param>
  63. /// A callback invoked when the asset has either been found or not found.
  64. /// If the asset was found this is called with the asset UUID and the asset data
  65. /// If the asset was not found this is still called with the asset UUID but with a null asset data reference</param>
  66. void GetAsset(UUID assetID, AssetRequestCallback callback, bool isTexture);
  67. /// <summary>
  68. /// Synchronously retreive an asset. If the asset isn't in the cache, a request will be made to the persistent store to
  69. /// load it into the cache.
  70. /// </summary>
  71. ///
  72. /// XXX We'll keep polling the cache until we get the asset or we exceed
  73. /// the allowed number of polls. This isn't a very good way of doing things since a single thread
  74. /// is processing inbound packets, so if the asset server is slow, we could block this for up to
  75. /// the timeout period. Whereever possible we want to use the asynchronous callback GetAsset()
  76. ///
  77. /// <param name="assetID"></param>
  78. /// <param name="isTexture"></param>
  79. /// <returns>null if the asset could not be retrieved</returns>
  80. AssetBase GetAsset(UUID assetID, bool isTexture);
  81. /// <summary>
  82. /// Add an asset to both the persistent store and the cache.
  83. /// </summary>
  84. /// <param name="asset"></param>
  85. void AddAsset(AssetBase asset);
  86. /// <summary>
  87. /// Expire an asset from the cache
  88. /// </summary>
  89. /// Allows you to clear a specific asset by uuid out
  90. /// of the asset cache. This is needed because the osdynamic
  91. /// texture code grows the asset cache without bounds. The
  92. /// real solution here is a much better cache archicture, but
  93. /// this is a stop gap measure until we have such a thing.
  94. void ExpireAsset(UUID assetID);
  95. /// <summary>
  96. /// Handle an asset request from the client. The result will be sent back asynchronously.
  97. /// </summary>
  98. /// <param name="userInfo"></param>
  99. /// <param name="transferRequest"></param>
  100. void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest);
  101. }
  102. public class AssetCachePluginInitialiser : PluginInitialiserBase
  103. {
  104. private ConfigSettings config;
  105. private IAssetServer server;
  106. public AssetCachePluginInitialiser (ConfigSettings p_sv, IAssetServer p_as)
  107. {
  108. config = p_sv;
  109. server = p_as;
  110. }
  111. public override void Initialise (IPlugin plugin)
  112. {
  113. IAssetCache p = plugin as IAssetCache;
  114. p.Initialise (config, server);
  115. }
  116. }
  117. }