diff options
Merge branch 'master' into diva-textures
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs new file mode 100644 index 0000000..72c00fc --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs | |||
@@ -0,0 +1,194 @@ | |||
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 log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using Nini.Config; | ||
33 | using OpenMetaverse; | ||
34 | |||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Services.Connectors; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | ||
43 | { | ||
44 | public class RemoteGridServicesConnector : | ||
45 | GridServicesConnector, ISharedRegionModule, IGridService | ||
46 | { | ||
47 | private static readonly ILog m_log = | ||
48 | LogManager.GetLogger( | ||
49 | MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private bool m_Enabled = false; | ||
52 | |||
53 | private IGridService m_LocalGridService; | ||
54 | |||
55 | public RemoteGridServicesConnector() | ||
56 | { | ||
57 | } | ||
58 | |||
59 | public RemoteGridServicesConnector(IConfigSource source) | ||
60 | { | ||
61 | InitialiseServices(source); | ||
62 | } | ||
63 | |||
64 | #region ISharedRegionmodule | ||
65 | |||
66 | public Type ReplaceableInterface | ||
67 | { | ||
68 | get { return null; } | ||
69 | } | ||
70 | |||
71 | public string Name | ||
72 | { | ||
73 | get { return "RemoteGridServicesConnector"; } | ||
74 | } | ||
75 | |||
76 | public override void Initialise(IConfigSource source) | ||
77 | { | ||
78 | IConfig moduleConfig = source.Configs["Modules"]; | ||
79 | if (moduleConfig != null) | ||
80 | { | ||
81 | string name = moduleConfig.GetString("GridServices", ""); | ||
82 | if (name == Name) | ||
83 | { | ||
84 | InitialiseServices(source); | ||
85 | m_Enabled = true; | ||
86 | m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled"); | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | private void InitialiseServices(IConfigSource source) | ||
92 | { | ||
93 | IConfig gridConfig = source.Configs["GridService"]; | ||
94 | if (gridConfig == null) | ||
95 | { | ||
96 | m_log.Error("[REMOTE GRID CONNECTOR]: GridService missing from OpenSim.ini"); | ||
97 | return; | ||
98 | } | ||
99 | |||
100 | base.Initialise(source); | ||
101 | |||
102 | m_LocalGridService = new LocalGridServicesConnector(source); | ||
103 | } | ||
104 | |||
105 | public void PostInitialise() | ||
106 | { | ||
107 | if (m_LocalGridService != null) | ||
108 | ((ISharedRegionModule)m_LocalGridService).PostInitialise(); | ||
109 | } | ||
110 | |||
111 | public void Close() | ||
112 | { | ||
113 | } | ||
114 | |||
115 | public void AddRegion(Scene scene) | ||
116 | { | ||
117 | if (m_Enabled) | ||
118 | scene.RegisterModuleInterface<IGridService>(this); | ||
119 | |||
120 | if (m_LocalGridService != null) | ||
121 | ((ISharedRegionModule)m_LocalGridService).AddRegion(scene); | ||
122 | } | ||
123 | |||
124 | public void RemoveRegion(Scene scene) | ||
125 | { | ||
126 | if (m_LocalGridService != null) | ||
127 | ((ISharedRegionModule)m_LocalGridService).RemoveRegion(scene); | ||
128 | } | ||
129 | |||
130 | public void RegionLoaded(Scene scene) | ||
131 | { | ||
132 | } | ||
133 | |||
134 | #endregion | ||
135 | |||
136 | #region IGridService | ||
137 | |||
138 | public override bool RegisterRegion(UUID scopeID, GridRegion regionInfo) | ||
139 | { | ||
140 | if (m_LocalGridService.RegisterRegion(scopeID, regionInfo)) | ||
141 | return base.RegisterRegion(scopeID, regionInfo); | ||
142 | |||
143 | return false; | ||
144 | } | ||
145 | |||
146 | public override bool DeregisterRegion(UUID regionID) | ||
147 | { | ||
148 | if (m_LocalGridService.DeregisterRegion(regionID)) | ||
149 | return base.DeregisterRegion(regionID); | ||
150 | |||
151 | return false; | ||
152 | } | ||
153 | |||
154 | // Let's override GetNeighbours completely -- never go to the grid server | ||
155 | // Neighbours are/should be cached locally | ||
156 | // For retrieval from the DB, caller should call GetRegionByPosition | ||
157 | public override List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) | ||
158 | { | ||
159 | return m_LocalGridService.GetNeighbours(scopeID, regionID); | ||
160 | } | ||
161 | |||
162 | public override GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) | ||
163 | { | ||
164 | GridRegion rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID); | ||
165 | if (rinfo == null) | ||
166 | rinfo = base.GetRegionByUUID(scopeID, regionID); | ||
167 | |||
168 | return rinfo; | ||
169 | } | ||
170 | |||
171 | public override GridRegion GetRegionByPosition(UUID scopeID, int x, int y) | ||
172 | { | ||
173 | GridRegion rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); | ||
174 | if (rinfo == null) | ||
175 | rinfo = base.GetRegionByPosition(scopeID, x, y); | ||
176 | |||
177 | return rinfo; | ||
178 | } | ||
179 | |||
180 | public override GridRegion GetRegionByName(UUID scopeID, string regionName) | ||
181 | { | ||
182 | GridRegion rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName); | ||
183 | if (rinfo == null) | ||
184 | rinfo = base.GetRegionByName(scopeID, regionName); | ||
185 | |||
186 | return rinfo; | ||
187 | } | ||
188 | |||
189 | // Let's not override GetRegionsByName -- let's get them all from the grid server | ||
190 | // Let's not override GetRegionRange -- let's get them all from the grid server | ||
191 | |||
192 | #endregion | ||
193 | } | ||
194 | } | ||