29 using System.Collections.Generic;
30 using System.Reflection;
31 using System.Threading;
33 using OpenSim.Framework;
35 using OpenSim.Services.Interfaces;
39 namespace OpenSim.Groups
56 private Dictionary<string, bool> m_ActiveRequests =
new Dictionary<string, bool>();
57 private const int GROUPS_CACHE_TIMEOUT = 1 * 60;
71 private ExpiringCache<string, object> m_Cache =
new ExpiringCache<string, object>();
93 m_Cache.Add(
"group-" + group.GroupID.ToString(), group, GROUPS_CACHE_TIMEOUT);
94 if (m_Cache.Contains(
"memberships-" + RequestingAgentID.ToString()))
95 m_Cache.Remove(
"memberships-" + RequestingAgentID.ToString());
107 if (group != null && group.
GroupID != UUID.Zero)
109 m_Cache.AddOrUpdate(
"group-" + group.GroupID.ToString(), group, GROUPS_CACHE_TIMEOUT);
119 bool firstCall =
false;
120 string cacheKey =
"group-";
121 if (GroupID != UUID.Zero)
122 cacheKey += GroupID.ToString();
124 cacheKey += GroupName;
132 if (m_Cache.TryGetValue(cacheKey, out group))
139 if (!m_ActiveRequests.ContainsKey(cacheKey))
141 m_ActiveRequests.Add(cacheKey,
true);
155 m_Cache.AddOrUpdate(cacheKey, group, GROUPS_CACHE_TIMEOUT);
161 m_ActiveRequests.Remove(cacheKey);
172 if (membership == null)
180 m_Cache.AddOrUpdate(
"active-" + AgentID.ToString(), membership, GROUPS_CACHE_TIMEOUT);
181 m_Cache.AddOrUpdate(
"membership-" + AgentID.ToString() +
"-" + GroupID.ToString(), membership, GROUPS_CACHE_TIMEOUT);
194 string cacheKey =
"active-" + AgentID.ToString();
195 if (m_Cache.Contains(cacheKey))
196 m_Cache.Remove(cacheKey);
198 cacheKey =
"memberships-" + AgentID.ToString();
199 if (m_Cache.Contains(cacheKey))
200 m_Cache.Remove(cacheKey);
202 cacheKey =
"membership-" + AgentID.ToString() +
"-" + GroupID.ToString();
203 if (m_Cache.Contains(cacheKey))
204 m_Cache.Remove(cacheKey);
206 cacheKey =
"members-" + RequestingAgentID.ToString() +
"-" + GroupID.ToString();
207 if (m_Cache.Contains(cacheKey))
208 m_Cache.Remove(cacheKey);
210 cacheKey =
"roles-" +
"-" + GroupID.ToString() +
"-" + AgentID.ToString();
211 if (m_Cache.Contains(cacheKey))
212 m_Cache.Remove(cacheKey);
219 string cacheKey =
"active-" + AgentID.ToString();
221 if (m_Cache.Contains(cacheKey))
222 m_Cache.AddOrUpdate(cacheKey, activeGroup, GROUPS_CACHE_TIMEOUT);
227 object membership = null;
228 bool firstCall =
false;
229 string cacheKey =
"active-" + AgentID.ToString();
237 if (m_Cache.TryGetValue(cacheKey, out membership))
244 if (!m_ActiveRequests.ContainsKey(cacheKey))
246 m_ActiveRequests.Add(cacheKey,
true);
259 m_Cache.AddOrUpdate(cacheKey, membership, GROUPS_CACHE_TIMEOUT);
265 m_ActiveRequests.Remove(cacheKey);
276 object membership = null;
277 bool firstCall =
false;
278 string cacheKey =
"membership-" + AgentID.ToString() +
"-" + GroupID.ToString();
286 if (m_Cache.TryGetValue(cacheKey, out membership))
293 if (!m_ActiveRequests.ContainsKey(cacheKey))
295 m_ActiveRequests.Add(cacheKey,
true);
307 m_Cache.AddOrUpdate(cacheKey, membership, GROUPS_CACHE_TIMEOUT);
313 m_ActiveRequests.Remove(cacheKey);
323 object memberships = null;
324 bool firstCall =
false;
325 string cacheKey =
"memberships-" + AgentID.ToString();
333 if (m_Cache.TryGetValue(cacheKey, out memberships))
336 return (List<GroupMembershipData>)memberships;
340 if (!m_ActiveRequests.ContainsKey(cacheKey))
342 m_ActiveRequests.Add(cacheKey,
true);
354 m_Cache.AddOrUpdate(cacheKey, memberships, GROUPS_CACHE_TIMEOUT);
355 return (List<GroupMembershipData>)memberships;
360 m_ActiveRequests.Remove(cacheKey);
370 object members = null;
371 bool firstCall =
false;
373 string cacheKey =
"members-" + RequestingAgentID.ToString() +
"-" + GroupID.ToString();
381 if (m_Cache.TryGetValue(cacheKey, out members))
383 List<ExtendedGroupMembersData> xx = (List<ExtendedGroupMembersData>)members;
384 return xx.ConvertAll<
GroupMembersData>(
new Converter<ExtendedGroupMembersData, GroupMembersData>(m_ForeignImporter.ConvertGroupMembersData));
388 if (!m_ActiveRequests.ContainsKey(cacheKey))
390 m_ActiveRequests.Add(cacheKey,
true);
399 List<ExtendedGroupMembersData> _members = d();
401 if (_members != null && _members.Count > 0)
402 members = _members.ConvertAll<
GroupMembersData>(
new Converter<ExtendedGroupMembersData, GroupMembersData>(m_ForeignImporter.ConvertGroupMembersData));
404 members =
new List<GroupMembersData>();
409 m_Cache.AddOrUpdate(cacheKey, _members, GROUPS_CACHE_TIMEOUT);
411 return (List<GroupMembersData>)members;
416 m_ActiveRequests.Remove(cacheKey);
429 role.Description = description;
432 role.Powers = powers;
433 role.RoleID = roleID;
438 m_Cache.AddOrUpdate(
"role-" + roleID.ToString(), role, GROUPS_CACHE_TIMEOUT);
441 if (m_Cache.Contains(
"roles-" + groupID.ToString()))
442 m_Cache.Remove(
"roles-" + groupID.ToString());
458 if (m_Cache.TryGetValue(
"role-" + roleID.ToString(), out role))
461 r.Description = description;
466 m_Cache.Update(
"role-" + roleID.ToString(), r, GROUPS_CACHE_TIMEOUT);
474 if (m_Cache.Contains(
"role-" + roleID.ToString()))
475 m_Cache.Remove(
"role-" + roleID.ToString());
478 if (m_Cache.Contains(
"roles-" + groupID.ToString()))
479 m_Cache.Remove(
"roles-" + groupID.ToString());
493 if (m_Cache.Contains(
"role-" + roleID.ToString()))
494 m_Cache.Remove(
"role-" + roleID.ToString());
497 if (m_Cache.Contains(
"roles-" + groupID.ToString()))
498 m_Cache.Remove(
"roles-" + groupID.ToString());
500 if (m_Cache.Contains(
"roles-" + groupID.ToString() +
"-" + RequestingAgentID.ToString()))
501 m_Cache.Remove(
"roles-" + groupID.ToString() +
"-" + RequestingAgentID.ToString());
503 if (m_Cache.Contains(
"rolemembers-" + RequestingAgentID.ToString() +
"-" + groupID.ToString()))
504 m_Cache.Remove(
"rolemembers-" + RequestingAgentID.ToString() +
"-" + groupID.ToString());
511 bool firstCall =
false;
512 string cacheKey =
"roles-" + GroupID.ToString();
518 if (m_Cache.TryGetValue(cacheKey, out roles))
519 return (List<GroupRolesData>)roles;
522 if (!m_ActiveRequests.ContainsKey(cacheKey))
524 m_ActiveRequests.Add(cacheKey,
true);
538 m_Cache.AddOrUpdate(cacheKey, roles, GROUPS_CACHE_TIMEOUT);
539 return (List<GroupRolesData>)roles;
545 m_ActiveRequests.Remove(cacheKey);
555 object rmembers = null;
556 bool firstCall =
false;
558 string cacheKey =
"rolemembers-" + RequestingAgentID.ToString() +
"-" + GroupID.ToString();
565 if (m_Cache.TryGetValue(cacheKey, out rmembers))
567 List<ExtendedGroupRoleMembersData> xx = (List<ExtendedGroupRoleMembersData>)rmembers;
572 if (!m_ActiveRequests.ContainsKey(cacheKey))
574 m_ActiveRequests.Add(cacheKey,
true);
583 List<ExtendedGroupRoleMembersData> _rmembers = d();
585 if (_rmembers != null && _rmembers.Count > 0)
586 rmembers = _rmembers.ConvertAll<
GroupRoleMembersData>(
new Converter<ExtendedGroupRoleMembersData, GroupRoleMembersData>(m_ForeignImporter.ConvertGroupRoleMembersData));
588 rmembers =
new List<GroupRoleMembersData>();
597 m_Cache.AddOrUpdate(cacheKey, _rmembers, GROUPS_CACHE_TIMEOUT);
598 return (List<GroupRoleMembersData>)rmembers;
603 m_ActiveRequests.Remove(cacheKey);
618 string cacheKey =
"role-" + RoleID.ToString();
620 if (m_Cache.TryGetValue(cacheKey, out obj))
627 cacheKey =
"rolemembers-" + RequestingAgentID.ToString() +
"-" + GroupID.ToString();
628 if (m_Cache.TryGetValue(cacheKey, out obj))
634 UUID
id =
new UUID(AgentID);
635 List<ExtendedGroupRoleMembersData> xx = (List<ExtendedGroupRoleMembersData>)obj;
636 List<GroupRoleMembersData> rmlist = xx.ConvertAll<
GroupRoleMembersData>(m_ForeignImporter.ConvertGroupRoleMembersData);
644 m_Cache.Remove(cacheKey);
650 cacheKey =
"roles-" + GroupID.ToString() +
"-" + AgentID.ToString();
651 if (m_Cache.Contains(cacheKey))
652 m_Cache.Remove(cacheKey);
665 string cacheKey =
"role-" + RoleID.ToString();
667 if (m_Cache.TryGetValue(cacheKey, out obj))
673 cacheKey =
"roles-" + GroupID.ToString() +
"-" + AgentID.ToString();
674 if (m_Cache.Contains(cacheKey))
675 m_Cache.Remove(cacheKey);
677 cacheKey =
"rolemembers-" + RequestingAgentID.ToString() +
"-" + GroupID.ToString();
678 if (m_Cache.Contains(cacheKey))
679 m_Cache.Remove(cacheKey);
687 bool firstCall =
false;
688 string cacheKey =
"roles-" + GroupID.ToString() +
"-" + AgentID.ToString();
696 if (m_Cache.TryGetValue(cacheKey, out roles))
699 return (List<GroupRolesData>)roles;
703 if (!m_ActiveRequests.ContainsKey(cacheKey))
705 m_ActiveRequests.Add(cacheKey,
true);
717 m_Cache.AddOrUpdate(cacheKey, roles, GROUPS_CACHE_TIMEOUT);
718 m_ActiveRequests.Remove(cacheKey);
719 return (List<GroupRolesData>)roles;
724 m_ActiveRequests.Remove(cacheKey);
739 string cacheKey =
"membership-" + AgentID.ToString() +
"-" + GroupID.ToString();
740 if (m_Cache.Contains(cacheKey))
741 m_Cache.Remove(cacheKey);
743 cacheKey =
"memberships-" + AgentID.ToString();
744 if (m_Cache.Contains(cacheKey))
745 m_Cache.Remove(cacheKey);
755 string cacheKey =
"membership-" + AgentID.ToString() +
"-" + GroupID.ToString();
756 if (m_Cache.Contains(cacheKey))
757 m_Cache.Remove(cacheKey);
759 cacheKey =
"memberships-" + AgentID.ToString();
760 if (m_Cache.Contains(cacheKey))
761 m_Cache.Remove(cacheKey);
763 cacheKey =
"active-" + AgentID.ToString();
765 if (m_Cache.TryGetValue(cacheKey, out m))
768 membership.ListInProfile = ListInProfile;
769 membership.AcceptNotices = AcceptNotices;
780 m_Cache.AddOrUpdate(
"notice-" + noticeID.ToString(), notice, GROUPS_CACHE_TIMEOUT);
781 string cacheKey =
"notices-" + groupID.ToString();
782 if (m_Cache.Contains(cacheKey))
783 m_Cache.Remove(cacheKey);
795 object notice = null;
796 bool firstCall =
false;
797 string cacheKey =
"notice-" + noticeID.ToString();
805 if (m_Cache.TryGetValue(cacheKey, out notice))
811 if (!m_ActiveRequests.ContainsKey(cacheKey))
813 m_ActiveRequests.Add(cacheKey,
true);
826 m_Cache.AddOrUpdate(cacheKey, _notice, GROUPS_CACHE_TIMEOUT);
832 m_ActiveRequests.Remove(cacheKey);
842 object notices = null;
843 bool firstCall =
false;
844 string cacheKey =
"notices-" + GroupID.ToString();
852 if (m_Cache.TryGetValue(cacheKey, out notices))
855 return (List<ExtendedGroupNoticeData>)notices;
859 if (!m_ActiveRequests.ContainsKey(cacheKey))
861 m_ActiveRequests.Add(cacheKey,
true);
874 m_Cache.AddOrUpdate(cacheKey, notices, GROUPS_CACHE_TIMEOUT);
875 return (List<ExtendedGroupNoticeData>)notices;
880 m_ActiveRequests.Remove(cacheKey);
bool UpdateGroupRole(UUID groupID, UUID roleID, string name, string description, string title, ulong powers, BooleanDelegate d)
bool AddGroupNotice(UUID groupID, UUID noticeID, GroupNoticeInfo notice, BooleanDelegate d)
delegate GroupMembershipData GroupMembershipDelegate()
void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, BooleanDelegate d)
delegate List< GroupRolesData > GroupRolesListDelegate()
List< GroupRolesData > GetGroupRoles(string RequestingAgentID, UUID GroupID, GroupRolesListDelegate d)
void SetAgentActiveGroupRole(string AgentID, UUID GroupID, VoidDelegate d)
List< GroupMembershipData > GetAgentGroupMemberships(string AgentID, GroupMembershipListDelegate d)
List< GroupRolesData > GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID, GroupRolesListDelegate d)
delegate ExtendedGroupRecord GroupRecordDelegate()
RemoteConnectorCacheWrapper(IUserManagement uman)
void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, BooleanDelegate d)
ExtendedGroupMembershipData GetAgentActiveMembership(string AgentID, GroupMembershipDelegate d)
delegate void VoidDelegate()
bool UpdateGroup(UUID groupID, GroupRecordDelegate d)
bool AddGroupRole(UUID groupID, UUID roleID, string description, string name, ulong powers, string title, BooleanDelegate d)
List< GroupMembersData > GetGroupMembers(string RequestingAgentID, UUID GroupID, GroupMembersListDelegate d)
delegate List< ExtendedGroupMembersData > GroupMembersListDelegate()
ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName, GroupRecordDelegate d)
void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID, VoidDelegate d)
UUID CreateGroup(UUID RequestingAgentID, GroupRecordDelegate d)
delegate List< ExtendedGroupNoticeData > NoticeListDelegate()
void SetAgentActiveGroup(string AgentID, GroupMembershipDelegate d)
List< GroupRoleMembersData > GetGroupRoleMembers(string RequestingAgentID, UUID GroupID, RoleMembersListDelegate d)
bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, GroupMembershipDelegate d)
void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, VoidDelegate d)
List< ExtendedGroupNoticeData > GetGroupNotices(UUID GroupID, NoticeListDelegate d)
delegate bool BooleanDelegate()
GroupNoticeInfo GetGroupNotice(UUID noticeID, NoticeDelegate d)
delegate List< ExtendedGroupRoleMembersData > RoleMembersListDelegate()
This maintains the relationship between a UUID and a user name.
delegate List< GroupMembershipData > GroupMembershipListDelegate()
delegate GroupNoticeInfo NoticeDelegate()
void UpdateMembership(string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile, VoidDelegate d)
ExtendedGroupMembershipData GetAgentGroupMembership(string AgentID, UUID GroupID, GroupMembershipDelegate d)