IAssetCache.cs 5.2 KB

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