diff options
author | John Hurliman | 2009-10-13 14:50:03 -0700 |
---|---|---|
committer | John Hurliman | 2009-10-13 14:50:03 -0700 |
commit | 23a334b9f54a1ef5df3b503c165e7b76b746a2b1 (patch) | |
tree | 93003db47fcd77af4085c0c49cbc1f2f0293b5eb /OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs | |
parent | * Unregister event handlers in LLUDPServer when a client logs out and disconn... (diff) | |
download | opensim-SC-23a334b9f54a1ef5df3b503c165e7b76b746a2b1.zip opensim-SC-23a334b9f54a1ef5df3b503c165e7b76b746a2b1.tar.gz opensim-SC-23a334b9f54a1ef5df3b503c165e7b76b746a2b1.tar.bz2 opensim-SC-23a334b9f54a1ef5df3b503c165e7b76b746a2b1.tar.xz |
* Rewrote ClientManager to remove Lindenisms from OpenSim core, improve performance by removing locks, and replace LLUDPClientCollection
* Removed the confusing (and LL-specific) shutdowncircuit parameter from IClientAPI.Close()
* Updated the LLUDP code to only use ClientManager instead of trying to synchronize ClientManager and m_clients
* Remove clients asynchronously since it is a very slow operation (including a 2000ms sleep)
Diffstat (limited to 'OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs deleted file mode 100644 index 4f375e4..0000000 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs +++ /dev/null | |||
@@ -1,137 +0,0 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenMetaverse; | ||
33 | using BclExtras.Collections; | ||
34 | |||
35 | using ReaderWriterLockImpl = OpenMetaverse.ReaderWriterLockSlim; | ||
36 | |||
37 | namespace OpenSim.Region.ClientStack.LindenUDP | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// A thread safe mapping from endpoints to client references | ||
41 | /// </summary> | ||
42 | public sealed class UDPClientCollection | ||
43 | { | ||
44 | #region IComparers | ||
45 | |||
46 | private sealed class IPEndPointComparer : IComparer<IPEndPoint> | ||
47 | { | ||
48 | public int Compare(IPEndPoint x, IPEndPoint y) | ||
49 | { | ||
50 | int result = x.Address.Address.CompareTo(y.Address.Address); | ||
51 | if (result == 0) result = x.Port.CompareTo(y.Port); | ||
52 | return result; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | #endregion IComparers | ||
57 | |||
58 | /// <summary>An immutable dictionary mapping from <seealso cref="IPEndPoint"/> | ||
59 | /// to <seealso cref="LLUDPClient"/> references</summary> | ||
60 | private ImmutableMap<IPEndPoint, LLUDPClient> m_dict; | ||
61 | /// <summary>Immutability grants thread safety for concurrent reads and | ||
62 | /// read-writes, but not concurrent writes</summary> | ||
63 | private object m_writeLock = new object(); | ||
64 | |||
65 | /// <summary>Number of clients in the collection</summary> | ||
66 | public int Count { get { return m_dict.Count; } } | ||
67 | |||
68 | /// <summary> | ||
69 | /// Default constructor | ||
70 | /// </summary> | ||
71 | public UDPClientCollection() | ||
72 | { | ||
73 | m_dict = new ImmutableMap<IPEndPoint, LLUDPClient>(new IPEndPointComparer()); | ||
74 | } | ||
75 | |||
76 | /// <summary> | ||
77 | /// Add a client reference to the collection | ||
78 | /// </summary> | ||
79 | /// <param name="key">Remote endpoint of the client</param> | ||
80 | /// <param name="value">Reference to the client object</param> | ||
81 | public void Add(IPEndPoint key, LLUDPClient value) | ||
82 | { | ||
83 | lock (m_writeLock) | ||
84 | m_dict = m_dict.Add(key, value); | ||
85 | } | ||
86 | |||
87 | /// <summary> | ||
88 | /// Remove a client from the collection | ||
89 | /// </summary> | ||
90 | /// <param name="key">Remote endpoint of the client</param> | ||
91 | public void Remove(IPEndPoint key) | ||
92 | { | ||
93 | lock (m_writeLock) | ||
94 | m_dict = m_dict.Delete(key); | ||
95 | } | ||
96 | |||
97 | /// <summary> | ||
98 | /// Resets the client collection | ||
99 | /// </summary> | ||
100 | public void Clear() | ||
101 | { | ||
102 | lock (m_writeLock) | ||
103 | m_dict = new ImmutableMap<IPEndPoint, LLUDPClient>(new IPEndPointComparer()); | ||
104 | } | ||
105 | |||
106 | /// <summary> | ||
107 | /// Checks if an endpoint is in the collection | ||
108 | /// </summary> | ||
109 | /// <param name="key">Endpoint to check for</param> | ||
110 | /// <returns>True if the endpoint was found in the collection, otherwise false</returns> | ||
111 | public bool ContainsKey(IPEndPoint key) | ||
112 | { | ||
113 | return m_dict.ContainsKey(key); | ||
114 | } | ||
115 | |||
116 | /// <summary> | ||
117 | /// Attempts to fetch a value out of the collection | ||
118 | /// </summary> | ||
119 | /// <param name="key">Endpoint of the client to retrieve</param> | ||
120 | /// <param name="value">Retrieved client, or null on lookup failure</param> | ||
121 | /// <returns>True if the lookup succeeded, otherwise false</returns> | ||
122 | public bool TryGetValue(IPEndPoint key, out LLUDPClient value) | ||
123 | { | ||
124 | return m_dict.TryGetValue(key, out value); | ||
125 | } | ||
126 | |||
127 | /// <summary> | ||
128 | /// Performs a given task in parallel for each of the elements in the | ||
129 | /// collection | ||
130 | /// </summary> | ||
131 | /// <param name="action">Action to perform on each element</param> | ||
132 | public void ForEach(Action<LLUDPClient> action) | ||
133 | { | ||
134 | Parallel.ForEach<LLUDPClient>(m_dict.Values, action); | ||
135 | } | ||
136 | } | ||
137 | } | ||