123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814 |
- /*
- * 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.
- * * Neither the name of the OpenSimulator Project nor the
- * 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 System;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Threading;
- using OpenSim.Framework;
- //using OpenSim.Region.Framework.Interfaces;
- using OpenSim.Services.Interfaces;
- using OpenMetaverse;
- namespace OpenSim.Groups
- {
- public delegate ExtendedGroupRecord GroupRecordDelegate();
- public delegate GroupMembershipData GroupMembershipDelegate();
- public delegate List<GroupMembershipData> GroupMembershipListDelegate();
- public delegate List<ExtendedGroupMembersData> GroupMembersListDelegate();
- public delegate List<GroupRolesData> GroupRolesListDelegate();
- public delegate List<ExtendedGroupRoleMembersData> RoleMembersListDelegate();
- public delegate GroupNoticeInfo NoticeDelegate();
- public delegate List<ExtendedGroupNoticeData> NoticeListDelegate();
- public delegate void VoidDelegate();
- public delegate bool BooleanDelegate();
- public class RemoteConnectorCacheWrapper
- {
- private const int GROUPS_CACHE_TIMEOUT = 1 * 60; // 1 minutes
- private ForeignImporter m_ForeignImporter;
- private HashSet<string> m_ActiveRequests = new HashSet<string>();
- // This all important cache caches objects of different types:
- // group-<GroupID> or group-<Name> => ExtendedGroupRecord
- // active-<AgentID> => GroupMembershipData
- // membership-<AgentID>-<GroupID> => GroupMembershipData
- // memberships-<AgentID> => List<GroupMembershipData>
- // members-<RequestingAgentID>-<GroupID> => List<ExtendedGroupMembersData>
- // role-<RoleID> => GroupRolesData
- // roles-<GroupID> => List<GroupRolesData> ; all roles in the group
- // roles-<GroupID>-<AgentID> => List<GroupRolesData> ; roles that the agent has
- // rolemembers-<RequestingAgentID>-<GroupID> => List<ExtendedGroupRoleMembersData>
- // notice-<noticeID> => GroupNoticeInfo
- // notices-<GroupID> => List<ExtendedGroupNoticeData>
- private ExpiringCacheOS<string, object> m_Cache = new ExpiringCacheOS<string, object>(30000);
- public RemoteConnectorCacheWrapper(IUserManagement uman)
- {
- m_ForeignImporter = new ForeignImporter(uman);
- }
- public UUID CreateGroup(UUID RequestingAgentID, GroupRecordDelegate d)
- {
- //m_log.DebugFormat("[Groups.RemoteConnector]: Creating group {0}", name);
- //reason = string.Empty;
- //ExtendedGroupRecord group = m_GroupsService.CreateGroup(RequestingAgentID.ToString(), name, charter, showInList, insigniaID,
- // membershipFee, openEnrollment, allowPublish, maturePublish, founderID, out reason);
- ExtendedGroupRecord group = d();
- if (group == null)
- return UUID.Zero;
- if (!group.GroupID.IsZero())
- {
- m_Cache.AddOrUpdate("group-" + group.GroupID.ToString(), group, GROUPS_CACHE_TIMEOUT);
- m_Cache.Remove("memberships-" + RequestingAgentID.ToString());
- }
- return group.GroupID;
- }
- public bool UpdateGroup(UUID groupID, GroupRecordDelegate d)
- {
- //reason = string.Empty;
- //ExtendedGroupRecord group = m_GroupsService.UpdateGroup(RequestingAgentID, groupID, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish);
- ExtendedGroupRecord group = d();
- if (!group.GroupID.IsZero())
- m_Cache.AddOrUpdate("group-" + group.GroupID.ToString(), group, GROUPS_CACHE_TIMEOUT);
- return true;
- }
- public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName, GroupRecordDelegate d)
- {
- //if (GroupID.IsZero() && string.IsNullOrEmpty(GroupName))
- // return null;
- object group = null;
- bool firstCall = false;
- string cacheKey = "group-";
- if (GroupID.IsZero())
- cacheKey += GroupName;
- else
- cacheKey += GroupID.ToString();
- //m_log.DebugFormat("[XXX]: GetGroupRecord {0}", cacheKey);
- while (true)
- {
- lock (m_Cache)
- {
- if (m_Cache.TryGetValue(cacheKey, out group))
- {
- //m_log.DebugFormat("[XXX]: GetGroupRecord {0} cached!", cacheKey);
- return (ExtendedGroupRecord)group;
- }
- // not cached
- if (!m_ActiveRequests.Contains(cacheKey))
- {
- m_ActiveRequests.Add(cacheKey);
- firstCall = true;
- }
- }
- if (firstCall)
- {
- try
- {
- //group = m_GroupsService.GetGroupRecord(RequestingAgentID, GroupID, GroupName);
- group = d();
- lock (m_Cache)
- {
- m_Cache.AddOrUpdate(cacheKey, group, GROUPS_CACHE_TIMEOUT);
- return (ExtendedGroupRecord)group;
- }
- }
- finally
- {
- m_ActiveRequests.Remove(cacheKey);
- }
- }
- else
- Thread.Sleep(50);
- }
- }
- public bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, GroupMembershipDelegate d)
- {
- GroupMembershipData membership = d();
- if (membership == null)
- return false;
- lock (m_Cache)
- {
- // first, remove everything! add a user is a heavy-duty op
- m_Cache.Clear();
- m_Cache.AddOrUpdate("active-" + AgentID.ToString(), membership, GROUPS_CACHE_TIMEOUT);
- m_Cache.AddOrUpdate("membership-" + AgentID.ToString() + "-" + GroupID.ToString(), membership, GROUPS_CACHE_TIMEOUT);
- }
- return true;
- }
- public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID, VoidDelegate d)
- {
- d();
- string AgentIDToString = AgentID.ToString();
- string cacheKey = "active-" + AgentIDToString;
- m_Cache.Remove(cacheKey);
- cacheKey = "memberships-" + AgentIDToString;
- m_Cache.Remove(cacheKey);
- string GroupIDToString = GroupID.ToString();
- cacheKey = "membership-" + AgentIDToString + "-" + GroupIDToString;
- m_Cache.Remove(cacheKey);
- cacheKey = "members-" + RequestingAgentID.ToString() + "-" + GroupIDToString;
- m_Cache.Remove(cacheKey);
- cacheKey = "roles-" + "-" + GroupIDToString + "-" + AgentIDToString;
- m_Cache.Remove(cacheKey);
- }
- public void SetAgentActiveGroup(string AgentID, GroupMembershipDelegate d)
- {
- GroupMembershipData activeGroup = d();
- string cacheKey = "active-" + AgentID.ToString();
- m_Cache.AddOrUpdate(cacheKey, activeGroup, GROUPS_CACHE_TIMEOUT);
- }
- public ExtendedGroupMembershipData GetAgentActiveMembership(string AgentID, GroupMembershipDelegate d)
- {
- object membership = null;
- bool firstCall = false;
- string cacheKey = "active-" + AgentID.ToString();
- //m_log.DebugFormat("[XXX]: GetAgentActiveMembership {0}", cacheKey);
- while (true)
- {
- lock (m_Cache)
- {
- if (m_Cache.TryGetValue(cacheKey, out membership))
- {
- //m_log.DebugFormat("[XXX]: GetAgentActiveMembership {0} cached!", cacheKey);
- return (ExtendedGroupMembershipData)membership;
- }
- // not cached
- if (!m_ActiveRequests.Contains(cacheKey))
- {
- m_ActiveRequests.Add(cacheKey);
- firstCall = true;
- }
- }
- if (firstCall)
- {
- try
- {
- membership = d();
- m_Cache.AddOrUpdate(cacheKey, membership, GROUPS_CACHE_TIMEOUT);
- return (ExtendedGroupMembershipData)membership;
- }
- finally
- {
- m_ActiveRequests.Remove(cacheKey);
- }
- }
- else
- Thread.Sleep(50);
- }
- }
- public ExtendedGroupMembershipData GetAgentGroupMembership(string AgentID, UUID GroupID, GroupMembershipDelegate d)
- {
- object membership = null;
- bool firstCall = false;
- string cacheKey = "membership-" + AgentID.ToString() + "-" + GroupID.ToString();
- //m_log.DebugFormat("[XXX]: GetAgentGroupMembership {0}", cacheKey);
- while (true)
- {
- lock (m_Cache)
- {
- if (m_Cache.TryGetValue(cacheKey, out membership))
- {
- //m_log.DebugFormat("[XXX]: GetAgentGroupMembership {0}", cacheKey);
- return (ExtendedGroupMembershipData)membership;
- }
- // not cached
- if (!m_ActiveRequests.Contains(cacheKey))
- {
- m_ActiveRequests.Add(cacheKey);
- firstCall = true;
- }
- }
- if (firstCall)
- {
- try
- {
- membership = d();
- m_Cache.AddOrUpdate(cacheKey, membership, GROUPS_CACHE_TIMEOUT);
- return (ExtendedGroupMembershipData)membership;
- }
- finally
- {
- m_ActiveRequests.Remove(cacheKey);
- }
- }
- else
- Thread.Sleep(50);
- }
- }
- public List<GroupMembershipData> GetAgentGroupMemberships(string AgentID, GroupMembershipListDelegate d)
- {
- object memberships = null;
- bool firstCall = false;
- string cacheKey = "memberships-" + AgentID.ToString();
- //m_log.DebugFormat("[XXX]: GetAgentGroupMemberships {0}", cacheKey);
- while (true)
- {
- lock (m_Cache)
- {
- if (m_Cache.TryGetValue(cacheKey, out memberships))
- {
- //m_log.DebugFormat("[XXX]: GetAgentGroupMemberships {0} cached!", cacheKey);
- return (List<GroupMembershipData>)memberships;
- }
- // not cached
- if (!m_ActiveRequests.Contains(cacheKey))
- {
- m_ActiveRequests.Add(cacheKey);
- firstCall = true;
- }
- }
- if (firstCall)
- {
- try
- {
- memberships = d();
- m_Cache.AddOrUpdate(cacheKey, memberships, GROUPS_CACHE_TIMEOUT);
- return (List<GroupMembershipData>)memberships;
- }
- finally
- {
- m_ActiveRequests.Remove(cacheKey);
- }
- }
- else
- Thread.Sleep(50);
- }
- }
- public List<GroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID, GroupMembersListDelegate d)
- {
- object members = null;
- bool firstCall = false;
- // we need to key in also on the requester, because different ppl have different view privileges
- string cacheKey = "members-" + RequestingAgentID.ToString() + "-" + GroupID.ToString();
- //m_log.DebugFormat("[XXX]: GetGroupMembers {0}", cacheKey);
- while (true)
- {
- lock (m_Cache)
- {
- if (m_Cache.TryGetValue(cacheKey, out members))
- {
- List<ExtendedGroupMembersData> xx = (List<ExtendedGroupMembersData>)members;
- return xx.ConvertAll<GroupMembersData>(new Converter<ExtendedGroupMembersData, GroupMembersData>(m_ForeignImporter.ConvertGroupMembersData));
- }
- // not cached
- if (!m_ActiveRequests.Contains(cacheKey))
- {
- m_ActiveRequests.Add(cacheKey);
- firstCall = true;
- }
- }
- if (firstCall)
- {
- try
- {
- List<ExtendedGroupMembersData> _members = d();
- if (_members != null && _members.Count > 0)
- members = _members.ConvertAll<GroupMembersData>(new Converter<ExtendedGroupMembersData, GroupMembersData>(m_ForeignImporter.ConvertGroupMembersData));
- else
- members = new List<GroupMembersData>();
- m_Cache.AddOrUpdate(cacheKey, _members, GROUPS_CACHE_TIMEOUT);
- return (List<GroupMembersData>)members;
- }
- finally
- {
- m_ActiveRequests.Remove(cacheKey);
- }
- }
- else
- Thread.Sleep(50);
- }
- }
- public bool AddGroupRole(UUID groupID, UUID roleID, string description, string name, ulong powers, string title, BooleanDelegate d)
- {
- if (d())
- {
- GroupRolesData role = new GroupRolesData();
- role.Description = description;
- role.Members = 0;
- role.Name = name;
- role.Powers = powers;
- role.RoleID = roleID;
- role.Title = title;
- m_Cache.AddOrUpdate("role-" + roleID.ToString(), role, GROUPS_CACHE_TIMEOUT);
- // also remove this list
- m_Cache.Remove("roles-" + groupID.ToString());
- return true;
- }
- return false;
- }
- public bool UpdateGroupRole(UUID groupID, UUID roleID, string name, string description, string title, ulong powers, BooleanDelegate d)
- {
- if (d())
- {
- object role;
- lock (m_Cache)
- if (m_Cache.TryGetValue("role-" + roleID.ToString(), out role))
- {
- GroupRolesData r = (GroupRolesData)role;
- r.Description = description;
- r.Name = name;
- r.Powers = powers;
- r.Title = title;
- m_Cache.AddOrUpdate("role-" + roleID.ToString(), r, GROUPS_CACHE_TIMEOUT);
- }
- return true;
- }
- else
- {
- m_Cache.Remove("role-" + roleID.ToString());
- // also remove these lists, because they will have an outdated role
- m_Cache.Remove("roles-" + groupID.ToString());
- return false;
- }
- }
- public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, VoidDelegate d)
- {
- d();
- lock (m_Cache)
- {
- m_Cache.Remove("role-" + roleID.ToString());
- // also remove the list, because it will have an removed role
- m_Cache.Remove("roles-" + groupID.ToString());
- m_Cache.Remove("roles-" + groupID.ToString() + "-" + RequestingAgentID.ToString());
- m_Cache.Remove("rolemembers-" + RequestingAgentID.ToString() + "-" + groupID.ToString());
- }
- }
- public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID GroupID, GroupRolesListDelegate d)
- {
- object roles = null;
- bool firstCall = false;
- string cacheKey = "roles-" + GroupID.ToString();
- while (true)
- {
- lock (m_Cache)
- {
- if (m_Cache.TryGetValue(cacheKey, out roles))
- return (List<GroupRolesData>)roles;
- // not cached
- if (!m_ActiveRequests.Contains(cacheKey))
- {
- m_ActiveRequests.Add(cacheKey);
- firstCall = true;
- }
- }
- if (firstCall)
- {
- try
- {
- roles = d();
- if (roles != null)
- {
- m_Cache.AddOrUpdate(cacheKey, roles, GROUPS_CACHE_TIMEOUT);
- return (List<GroupRolesData>)roles;
- }
- }
- finally
- {
- m_ActiveRequests.Remove(cacheKey);
- }
- }
- else
- Thread.Sleep(50);
- }
- }
- public List<GroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID GroupID, RoleMembersListDelegate d)
- {
- object rmembers = null;
- bool firstCall = false;
- // we need to key in also on the requester, because different ppl have different view privileges
- string cacheKey = "rolemembers-" + RequestingAgentID.ToString() + "-" + GroupID.ToString();
- //m_log.DebugFormat("[XXX]: GetGroupRoleMembers {0}", cacheKey);
- while (true)
- {
- lock (m_Cache)
- {
- if (m_Cache.TryGetValue(cacheKey, out rmembers))
- {
- List<ExtendedGroupRoleMembersData> xx = (List<ExtendedGroupRoleMembersData>)rmembers;
- return xx.ConvertAll<GroupRoleMembersData>(m_ForeignImporter.ConvertGroupRoleMembersData);
- }
- // not cached
- if (!m_ActiveRequests.Contains(cacheKey))
- {
- m_ActiveRequests.Add(cacheKey);
- firstCall = true;
- }
- }
- if (firstCall)
- {
- try
- {
- List<ExtendedGroupRoleMembersData> _rmembers = d();
- if (_rmembers != null && _rmembers.Count > 0)
- rmembers = _rmembers.ConvertAll<GroupRoleMembersData>(new Converter<ExtendedGroupRoleMembersData, GroupRoleMembersData>(m_ForeignImporter.ConvertGroupRoleMembersData));
- else
- rmembers = new List<GroupRoleMembersData>();
- // For some strange reason, when I cache the list of GroupRoleMembersData,
- // it gets emptied out. The TryGet gets an empty list...
- //m_Cache.AddOrUpdate(cacheKey, rmembers, GROUPS_CACHE_TIMEOUT);
- // Caching the list of ExtendedGroupRoleMembersData doesn't show that issue
- // I don't get it.
- m_Cache.AddOrUpdate(cacheKey, _rmembers, GROUPS_CACHE_TIMEOUT);
- return (List<GroupRoleMembersData>)rmembers;
- }
- finally
- {
- m_ActiveRequests.Remove(cacheKey);
- }
- }
- else
- Thread.Sleep(50);
- }
- }
- public void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, BooleanDelegate d)
- {
- if (d())
- {
- lock (m_Cache)
- {
- // update the cached role
- string cacheKey = "role-" + RoleID.ToString();
- object obj;
- if (m_Cache.TryGetValue(cacheKey, out obj))
- {
- GroupRolesData r = (GroupRolesData)obj;
- r.Members++;
- }
- // add this agent to the list of role members
- cacheKey = "rolemembers-" + RequestingAgentID.ToString() + "-" + GroupID.ToString();
- if (m_Cache.TryGetValue(cacheKey, out obj))
- {
- try
- {
- // This may throw an exception, in which case the agentID is not a UUID but a full ID
- // In that case, let's just remove the whoe things from the cache
- UUID id = new UUID(AgentID);
- List<ExtendedGroupRoleMembersData> xx = (List<ExtendedGroupRoleMembersData>)obj;
- List<GroupRoleMembersData> rmlist = xx.ConvertAll<GroupRoleMembersData>(m_ForeignImporter.ConvertGroupRoleMembersData);
- GroupRoleMembersData rm = new GroupRoleMembersData();
- rm.MemberID = id;
- rm.RoleID = RoleID;
- rmlist.Add(rm);
- }
- catch
- {
- m_Cache.Remove(cacheKey);
- }
- }
- // Remove the cached info about this agent's roles
- // because we don't have enough local info about the new role
- cacheKey = "roles-" + GroupID.ToString() + "-" + AgentID.ToString();
- if (m_Cache.Contains(cacheKey))
- m_Cache.Remove(cacheKey);
- }
- }
- }
- public void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, BooleanDelegate d)
- {
- if (d())
- {
- lock (m_Cache)
- {
- // update the cached role
- string cacheKey = "role-" + RoleID.ToString();
- object obj;
- if (m_Cache.TryGetValue(cacheKey, out obj))
- {
- GroupRolesData r = (GroupRolesData)obj;
- r.Members--;
- }
- cacheKey = "roles-" + GroupID.ToString() + "-" + AgentID.ToString();
- m_Cache.Remove(cacheKey);
- cacheKey = "rolemembers-" + RequestingAgentID.ToString() + "-" + GroupID.ToString();
- m_Cache.Remove(cacheKey);
- }
- }
- }
- public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID, GroupRolesListDelegate d)
- {
- object roles = null;
- bool firstCall = false;
- string cacheKey = "roles-" + GroupID.ToString() + "-" + AgentID.ToString();
- //m_log.DebugFormat("[XXX]: GetAgentGroupRoles {0}", cacheKey);
- while (true)
- {
- lock (m_Cache)
- {
- if (m_Cache.TryGetValue(cacheKey, out roles))
- {
- //m_log.DebugFormat("[XXX]: GetAgentGroupRoles {0} cached!", cacheKey);
- return (List<GroupRolesData>)roles;
- }
- // not cached
- if (!m_ActiveRequests.Contains(cacheKey))
- {
- m_ActiveRequests.Add(cacheKey);
- firstCall = true;
- }
- }
- if (firstCall)
- {
- try
- {
- roles = d();
- m_Cache.AddOrUpdate(cacheKey, roles, GROUPS_CACHE_TIMEOUT);
- return (List<GroupRolesData>)roles;
- }
- finally
- {
- m_ActiveRequests.Remove(cacheKey);
- }
- }
- else
- Thread.Sleep(50);
- }
- }
- public void SetAgentActiveGroupRole(string AgentID, UUID GroupID, VoidDelegate d)
- {
- d();
- lock (m_Cache)
- {
- // Invalidate cached info, because it has ActiveRoleID and Powers
- string cacheKey = "membership-" + AgentID.ToString() + "-" + GroupID.ToString();
- m_Cache.Remove(cacheKey);
- cacheKey = "memberships-" + AgentID.ToString();
- m_Cache.Remove(cacheKey);
- }
- }
- public void UpdateMembership(string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile, VoidDelegate d)
- {
- d();
- lock (m_Cache)
- {
- string cacheKey = "membership-" + AgentID.ToString() + "-" + GroupID.ToString();
- if (m_Cache.Contains(cacheKey))
- m_Cache.Remove(cacheKey);
- cacheKey = "memberships-" + AgentID.ToString();
- m_Cache.Remove(cacheKey);
- cacheKey = "active-" + AgentID.ToString();
- object m = null;
- if (m_Cache.TryGetValue(cacheKey, out m))
- {
- GroupMembershipData membership = (GroupMembershipData)m;
- membership.ListInProfile = ListInProfile;
- membership.AcceptNotices = AcceptNotices;
- }
- }
- }
- public bool AddGroupNotice(UUID groupID, UUID noticeID, GroupNoticeInfo notice, BooleanDelegate d)
- {
- if (d())
- {
- m_Cache.AddOrUpdate("notice-" + noticeID.ToString(), notice, GROUPS_CACHE_TIMEOUT);
- string cacheKey = "notices-" + groupID.ToString();
- m_Cache.Remove(cacheKey);
- return true;
- }
- return false;
- }
- public GroupNoticeInfo GetGroupNotice(UUID noticeID, NoticeDelegate d)
- {
- object notice = null;
- bool firstCall = false;
- string cacheKey = "notice-" + noticeID.ToString();
- //m_log.DebugFormat("[XXX]: GetAgentGroupRoles {0}", cacheKey);
- while (true)
- {
- lock (m_Cache)
- {
- if (m_Cache.TryGetValue(cacheKey, out notice))
- {
- return (GroupNoticeInfo)notice;
- }
- // not cached
- if (!m_ActiveRequests.Contains(cacheKey))
- {
- m_ActiveRequests.Add(cacheKey);
- firstCall = true;
- }
- }
- if (firstCall)
- {
- try
- {
- GroupNoticeInfo _notice = d();
- m_Cache.AddOrUpdate(cacheKey, _notice, GROUPS_CACHE_TIMEOUT);
- return _notice;
- }
- finally
- {
- m_ActiveRequests.Remove(cacheKey);
- }
- }
- else
- Thread.Sleep(50);
- }
- }
- public List<ExtendedGroupNoticeData> GetGroupNotices(UUID GroupID, NoticeListDelegate d)
- {
- object notices = null;
- bool firstCall = false;
- string cacheKey = "notices-" + GroupID.ToString();
- //m_log.DebugFormat("[XXX]: GetGroupNotices {0}", cacheKey);
- while (true)
- {
- lock (m_Cache)
- {
- if (m_Cache.TryGetValue(cacheKey, out notices))
- {
- //m_log.DebugFormat("[XXX]: GetGroupNotices {0} cached!", cacheKey);
- return (List<ExtendedGroupNoticeData>)notices;
- }
- // not cached
- if (!m_ActiveRequests.Contains(cacheKey))
- {
- m_ActiveRequests.Add(cacheKey);
- firstCall = true;
- }
- }
- if (firstCall)
- {
- try
- {
- notices = d();
- m_Cache.AddOrUpdate(cacheKey, notices, GROUPS_CACHE_TIMEOUT);
- return (List<ExtendedGroupNoticeData>)notices;
- }
- finally
- {
- m_ActiveRequests.Remove(cacheKey);
- }
- }
- else
- Thread.Sleep(50);
- }
- }
- }
- }
|