public UserAccount GetUserAccount(UUID scopeID, UUID userID)
        {
            // Cache check
            UserAccount account;

            if (m_accountCache.TryGetValue(userID, out account))
            {
                return(account);
            }

            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "GetUser" },
                { "UserID", userID.ToString() }
            };

            account = GetUser(requestArgs);

            if (account == null)
            {
                // Store null responses too, to avoid repeated lookups for missing accounts
                m_accountCache.AddOrUpdate(userID, null, CACHE_EXPIRATION_SECONDS);
            }

            return(account);
        }
        private void SaveFileCacheForAsset(UUID AssetId, OpenJPEG.J2KLayerInfo[] Layers)
        {
            m_decodedCache.AddOrUpdate(AssetId, Layers, TimeSpan.FromMinutes(10));

            if (Cache != null)
            {
                string assetID = "j2kCache_" + AssetId.ToString();

                AssetBase layerDecodeAsset = new AssetBase(assetID, assetID, (sbyte)AssetType.Notecard, m_CreatorID.ToString());
                layerDecodeAsset.Local     = true;
                layerDecodeAsset.Temporary = true;

                #region Serialize Layer Data

                StringBuilder stringResult = new StringBuilder();
                string        strEnd       = "\n";
                for (int i = 0; i < Layers.Length; i++)
                {
                    if (i == Layers.Length - 1)
                    {
                        strEnd = String.Empty;
                    }

                    stringResult.AppendFormat("{0}|{1}|{2}{3}", Layers[i].Start, Layers[i].End, Layers[i].End - Layers[i].Start, strEnd);
                }

                layerDecodeAsset.Data = Util.UTF8.GetBytes(stringResult.ToString());

                #endregion Serialize Layer Data

                Cache.Cache(layerDecodeAsset);
            }
        }
        public void Cache(UUID userID, UserAccount account)
        {
            // Cache even null accounts
            m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);

            //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
        }
        public void Cache(UUID userID, UserAccount account)
        {
            // Cache even null accounts
            m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);
            if (account != null)
            {
                m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS);
            }

            //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
        }
        private AvatarAppearance GetAppearance(UUID principalID)
        {
            AvatarAppearance a = null;

            if (m_Appearances.TryGetValue(principalID, out a))
            {
                return(a);
            }

            a = m_AvatarService.GetAppearance(principalID);
            m_Appearances.AddOrUpdate(principalID, a, 5 * 60); // 5minutes
            return(a);
        }
        private List <XInventoryFolder> GetFolderTree(UUID principalID, UUID folder)
        {
            List <XInventoryFolder> t = null;

            if (m_SuitcaseTrees.TryGetValue(principalID, out t))
            {
                return(t);
            }

            // Get the tree of the suitcase folder
            t = GetFolderTreeRecursive(folder);
            m_SuitcaseTrees.AddOrUpdate(principalID, t, 5 * 60); // 5minutes
            return(t);
        }
Example #7
0
        public GridUserInfo GetGridUserInfo(string userID)
        {
            GridUserInfo info = null;

            if (m_Infos.TryGetValue(userID, out info))
            {
                return(info);
            }

            info = m_RemoteConnector.GetGridUserInfo(userID);

            m_Infos.AddOrUpdate(userID, info, KEEPTIME);

            return(info);
        }
        bool SendIMToRegion(PresenceInfo upd, GridInstantMessage im, UUID toAgentID, bool foreigner)
        {
            bool       imresult = false;
            GridRegion reginfo  = null;

            if (!m_RegionCache.TryGetValue(upd.RegionID, out reginfo))
            {
                reginfo = m_GridService.GetRegionByUUID(UUID.Zero /*!!!*/, upd.RegionID);
                if (reginfo != null)
                {
                    m_RegionCache.AddOrUpdate(upd.RegionID, reginfo, CACHE_EXPIRATION_SECONDS);
                }
            }

            if (reginfo != null)
            {
                imresult = InstantMessageServiceConnector.SendInstantMessage(reginfo.ServerURI, im);
            }
            else
            {
                m_log.DebugFormat("[HG IM SERVICE]: Failed to deliver message to {0}", reginfo.ServerURI);
                return(false);
            }

            if (imresult)
            {
                // IM delivery successful, so store the Agent's location in our local cache.
                m_UserLocationMap[toAgentID] = upd;
                return(true);
            }
            else
            {
                // try again, but lookup user this time.
                // Warning, this must call the Async version
                // of this method or we'll be making thousands of threads
                // The version within the spawned thread is SendGridInstantMessageViaXMLRPCAsync
                // The version that spawns the thread is SendGridInstantMessageViaXMLRPC

                // This is recursive!!!!!
                return(TrySendInstantMessage(im, upd, false, foreigner));
            }
        }
Example #9
0
        public void Cache(UUID scopeID, UUID regionID, GridRegion rinfo)
        {
            // for now, do not cache negative results; this is because
            // we need to figure out how to handle regions coming online
            // in a timely way
            if (rinfo == null)
            {
                return;
            }

            ScopedRegionUUID id = new ScopedRegionUUID(scopeID, regionID);

            // Cache even null accounts
            m_UUIDCache.AddOrUpdate(id, rinfo, CACHE_EXPIRATION_SECONDS);
            if (rinfo != null)
            {
                ScopedRegionName name = new ScopedRegionName(scopeID, rinfo.RegionName);
                m_NameCache.AddOrUpdate(name, id, CACHE_EXPIRATION_SECONDS);

                ScopedRegionPosition pos = new ScopedRegionPosition(scopeID, rinfo.RegionHandle);
                m_PositionCache.AddOrUpdate(pos, rinfo, CACHE_EXPIRATION_SECONDS);
            }
        }
Example #10
0
 public void Cache(UUID userID, InventoryCollection inv)
 {
     m_Inventories.AddOrUpdate(userID, inv, 120);
 }
Example #11
0
 public void Cache(UUID userID, InventoryFolderBase root)
 {
     m_RootFolders.AddOrUpdate(userID, root, CACHE_EXPIRATION_SECONDS);
 }
        /// <summary>
        /// Encapsulate the XmlRpc call to standardize security and error handling.
        /// </summary>
        private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param)
        {
            XmlRpcResponse resp     = null;
            string         CacheKey = null;

            // Only bother with the cache if it isn't disabled.
            if (m_cacheTimeout > 0)
            {
                if (!function.StartsWith("groups.get"))
                {
                    // Any and all updates cause the cache to clear
                    m_memoryCache.Clear();
                }
                else
                {
                    StringBuilder sb = new StringBuilder(requestingAgentID + function);
                    foreach (object key in param.Keys)
                    {
                        if (param[key] != null)
                        {
                            sb.AppendFormat(",{0}:{1}", key.ToString(), param[key].ToString());
                        }
                    }

                    CacheKey = sb.ToString();
                    m_memoryCache.TryGetValue(CacheKey, out resp);
                }
            }

            if (resp == null)
            {
                if (m_debugEnabled)
                {
                    m_log.DebugFormat("[XMLRPC-GROUPS-CONNECTOR]: Cache miss for key {0}", CacheKey);
                }

                string UserService;
                UUID   SessionID;
                GetClientGroupRequestID(requestingAgentID, out UserService, out SessionID);

                param.Add("RequestingAgentID", requestingAgentID.ToString());
                param.Add("RequestingAgentUserService", UserService);
                param.Add("RequestingSessionID", SessionID.ToString());
                param.Add("ReadKey", m_groupReadKey);
                param.Add("WriteKey", m_groupWriteKey);

                IList parameters = new ArrayList();
                parameters.Add(param);

                ConfigurableKeepAliveXmlRpcRequest req;
                req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive);

                try
                {
                    resp = req.Send(m_groupsServerURI, 10000);

                    if ((m_cacheTimeout > 0) && (CacheKey != null))
                    {
                        m_memoryCache.AddOrUpdate(CacheKey, resp, TimeSpan.FromSeconds(m_cacheTimeout));
                    }
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat(
                        "[XMLRPC-GROUPS-CONNECTOR]: An error has occured while attempting to access the XmlRpcGroups server method {0} at {1}",
                        function, m_groupsServerURI);

                    m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0}{1}", e.Message, e.StackTrace);

                    foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
                    {
                        m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} ", ResponseLine);
                    }

                    foreach (string key in param.Keys)
                    {
                        m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", key, param[key].ToString());
                    }

                    Hashtable respData = new Hashtable();
                    respData.Add("error", e.ToString());
                    return(respData);
                }
            }

            if (resp.Value is Hashtable)
            {
                Hashtable respData = (Hashtable)resp.Value;
                if (respData.Contains("error") && !respData.Contains("succeed"))
                {
                    LogRespDataToConsoleError(requestingAgentID, function, param, respData);
                }

                return(respData);
            }

            m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: The XmlRpc server returned a {1} instead of a hashtable for {0}", function, resp.Value.GetType().ToString());

            if (resp.Value is ArrayList)
            {
                ArrayList al = (ArrayList)resp.Value;
                m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Contains {0} elements", al.Count);

                foreach (object o in al)
                {
                    m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", o.GetType().ToString(), o.ToString());
                }
            }
            else
            {
                m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Function returned: {0}", resp.Value.ToString());
            }

            Hashtable error = new Hashtable();

            error.Add("error", "invalid return value");
            return(error);
        }
Example #13
0
        ////////////////////////////////////////////////////////////
        // IImprovedAssetCache
        //

        private void UpdateMemoryCache(string key, AssetBase asset)
        {
            m_MemoryCache.AddOrUpdate(GetAssetID(key), asset, m_MemoryExpiration);
        }
Example #14
0
        /// <summary>
        /// Send updated position information about an agent in this region to a neighbor
        /// This operation may be called very frequently if an avatar is moving about in
        /// the region.
        /// </summary>
        public bool UpdateAgent(GridRegion destination, AgentPosition data)
        {
            bool v = true;

            if (_failedSims.TryGetValue(destination.ServerURI, out v))
            {
                return(false);
            }

            // The basic idea of this code is that the first thread that needs to
            // send an update for a specific avatar becomes the worker for any subsequent
            // requests until there are no more outstanding requests. Further, only send the most
            // recent update; this *should* never be needed but some requests get
            // slowed down and once that happens the problem with service end point
            // limits kicks in and nothing proceeds
            string uri = destination.ServerURI + AgentPath() + data.AgentID + "/";

            lock (m_updateAgentQueue)
            {
                if (m_updateAgentQueue.ContainsKey(uri))
                {
                    // Another thread is already handling
                    // updates for this simulator, just update
                    // the position and return, overwrites are
                    // not a problem since we only care about the
                    // last update anyway
                    m_updateAgentQueue[uri] = data;
                    return(true);
                }

                // Otherwise update the reference and start processing
                m_updateAgentQueue[uri] = data;
            }

            AgentPosition pos     = null;
            bool          success = true;

            while (success)
            {
                lock (m_updateAgentQueue)
                {
                    // save the position
                    AgentPosition lastpos = pos;

                    pos = m_updateAgentQueue[uri];

                    // this is true if no one put a new
                    // update in the map since the last
                    // one we processed, if thats the
                    // case then we are done
                    if (pos == lastpos)
                    {
                        m_updateAgentQueue.Remove(uri);
                        return(true);
                    }
                }

                success = UpdateAgent(destination, (IAgentData)pos, 10000);
            }
            // we get here iff success == false
            // blacklist sim for 2 minutes
            lock (m_updateAgentQueue)
            {
                _failedSims.AddOrUpdate(destination.ServerURI, true, 120);
                m_updateAgentQueue.Remove(uri);
            }
            return(false);
        }