aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs163
1 files changed, 163 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs b/OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs
new file mode 100644
index 0000000..f1eb1ad
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs
@@ -0,0 +1,163 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Threading;
32using log4net;
33using Mono.Addins;
34using Nini.Config;
35using OpenMetaverse;
36using OpenSim.Framework;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Framework.Monitoring;
39using OpenSim.Region.Framework.Scenes;
40using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41
42namespace OpenSim.Region.CoreModules.Framework
43{
44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GridServiceThrottleModule")]
45 public class GridServiceThrottleModule : ISharedRegionModule
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
49
50 private readonly List<Scene> m_scenes = new List<Scene>();
51
52 private OpenSim.Framework.BlockingQueue<GridRegionRequest> m_RequestQueue = new OpenSim.Framework.BlockingQueue<GridRegionRequest>();
53
54 public void Initialise(IConfigSource config)
55 {
56 Watchdog.StartThread(
57 ProcessQueue,
58 "GridServiceRequestThread",
59 ThreadPriority.BelowNormal,
60 true,
61 false);
62 }
63
64 public void AddRegion(Scene scene)
65 {
66 lock (m_scenes)
67 {
68 m_scenes.Add(scene);
69 scene.EventManager.OnNewClient += OnNewClient;
70 }
71 }
72
73 public void RegionLoaded(Scene scene)
74 {
75 }
76
77 public void RemoveRegion(Scene scene)
78 {
79 lock (m_scenes)
80 {
81 m_scenes.Remove(scene);
82 scene.EventManager.OnNewClient -= OnNewClient;
83 }
84 }
85
86 void OnNewClient(IClientAPI client)
87 {
88 client.OnRegionHandleRequest += OnRegionHandleRequest;
89 }
90
91 public void PostInitialise()
92 {
93 }
94
95 public void Close()
96 {
97 }
98
99 public string Name
100 {
101 get { return "GridServiceThrottleModule"; }
102 }
103
104 public Type ReplaceableInterface
105 {
106 get { return null; }
107 }
108
109 public void OnRegionHandleRequest(IClientAPI client, UUID regionID)
110 {
111 //m_log.DebugFormat("[GRIDSERVICE THROTTLE]: RegionHandleRequest {0}", regionID);
112 ulong handle = 0;
113 if (IsLocalRegionHandle(regionID, out handle))
114 {
115 client.SendRegionHandle(regionID, handle);
116 return;
117 }
118
119 GridRegionRequest request = new GridRegionRequest(client, regionID);
120 m_RequestQueue.Enqueue(request);
121
122 }
123
124 private bool IsLocalRegionHandle(UUID regionID, out ulong regionHandle)
125 {
126 regionHandle = 0;
127 foreach (Scene s in m_scenes)
128 if (s.RegionInfo.RegionID == regionID)
129 {
130 regionHandle = s.RegionInfo.RegionHandle;
131 return true;
132 }
133 return false;
134 }
135
136 private void ProcessQueue()
137 {
138 while (true)
139 {
140 Watchdog.UpdateThread();
141
142 GridRegionRequest request = m_RequestQueue.Dequeue();
143 GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, request.regionID);
144
145 if (r != null && r.RegionHandle != 0)
146 request.client.SendRegionHandle(request.regionID, r.RegionHandle);
147
148 }
149 }
150 }
151
152 class GridRegionRequest
153 {
154 public IClientAPI client;
155 public UUID regionID;
156
157 public GridRegionRequest(IClientAPI c, UUID r)
158 {
159 client = c;
160 regionID = r;
161 }
162 }
163}