diff options
author | Jeff Ames | 2008-03-04 06:02:48 +0000 |
---|---|---|
committer | Jeff Ames | 2008-03-04 06:02:48 +0000 |
commit | 75f6f6e3ffeca74ca75f80685e243103fe97cf98 (patch) | |
tree | 7541cdfce74eb7378e468a70680216b76a60188a /ThirdParty/3Di/LoadBalancer/LoadBalancerPlugin.cs | |
parent | Merged 3Di code that provides scene and avatar serialization, and plugin supp... (diff) | |
download | opensim-SC-75f6f6e3ffeca74ca75f80685e243103fe97cf98.zip opensim-SC-75f6f6e3ffeca74ca75f80685e243103fe97cf98.tar.gz opensim-SC-75f6f6e3ffeca74ca75f80685e243103fe97cf98.tar.bz2 opensim-SC-75f6f6e3ffeca74ca75f80685e243103fe97cf98.tar.xz |
Update svn properties. Minor formatting cleanup.
Diffstat (limited to 'ThirdParty/3Di/LoadBalancer/LoadBalancerPlugin.cs')
-rw-r--r-- | ThirdParty/3Di/LoadBalancer/LoadBalancerPlugin.cs | 579 |
1 files changed, 289 insertions, 290 deletions
diff --git a/ThirdParty/3Di/LoadBalancer/LoadBalancerPlugin.cs b/ThirdParty/3Di/LoadBalancer/LoadBalancerPlugin.cs index 6812777..f58e0ee 100644 --- a/ThirdParty/3Di/LoadBalancer/LoadBalancerPlugin.cs +++ b/ThirdParty/3Di/LoadBalancer/LoadBalancerPlugin.cs | |||
@@ -1,30 +1,29 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | */ |
27 | */ | ||
28 | 27 | ||
29 | using System; | 28 | using System; |
30 | using System.IO; | 29 | using System.IO; |
@@ -72,7 +71,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer | |||
72 | private int proxyOffset; | 71 | private int proxyOffset; |
73 | private string proxyURL; | 72 | private string proxyURL; |
74 | private SceneManager sceneManager; | 73 | private SceneManager sceneManager; |
75 | private string serializeDir; | 74 | private string serializeDir; |
76 | 75 | ||
77 | private TcpServer mTcpServer; | 76 | private TcpServer mTcpServer; |
78 | private TcpClient mTcpClient; | 77 | private TcpClient mTcpClient; |
@@ -81,7 +80,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer | |||
81 | { | 80 | { |
82 | m_log.Info("[BALANCER] "+"Entering Initialize()"); | 81 | m_log.Info("[BALANCER] "+"Entering Initialize()"); |
83 | 82 | ||
84 | StartTcpServer(); | 83 | StartTcpServer(); |
85 | ClientView.SynchronizeClient = new ClientView.SynchronizeClientHandler(SynchronizePackets); | 84 | ClientView.SynchronizeClient = new ClientView.SynchronizeClientHandler(SynchronizePackets); |
86 | AsynchronousSocketListener.PacketHandler = new AsynchronousSocketListener.PacketRecieveHandler(SynchronizePacketRecieve); | 85 | AsynchronousSocketListener.PacketHandler = new AsynchronousSocketListener.PacketRecieveHandler(SynchronizePacketRecieve); |
87 | 86 | ||
@@ -113,10 +112,10 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer | |||
113 | private void StartTcpServer() | 112 | private void StartTcpServer() |
114 | { | 113 | { |
115 | Thread server_thread = new Thread(new ThreadStart( | 114 | Thread server_thread = new Thread(new ThreadStart( |
116 | delegate { | 115 | delegate { |
117 | mTcpServer = new TcpServer(10001); | 116 | mTcpServer = new TcpServer(10001); |
118 | mTcpServer.start(); | 117 | mTcpServer.start(); |
119 | })); | 118 | })); |
120 | server_thread.Start(); | 119 | server_thread.Start(); |
121 | } | 120 | } |
122 | 121 | ||
@@ -126,67 +125,67 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer | |||
126 | 125 | ||
127 | private XmlRpcResponse GetStatus(XmlRpcRequest request) | 126 | private XmlRpcResponse GetStatus(XmlRpcRequest request) |
128 | { | 127 | { |
129 | XmlRpcResponse response = new XmlRpcResponse(); | 128 | XmlRpcResponse response = new XmlRpcResponse(); |
130 | try | 129 | try |
131 | { | 130 | { |
132 | m_log.Info("[BALANCER] "+"Entering RegionStatus()"); | 131 | m_log.Info("[BALANCER] "+"Entering RegionStatus()"); |
133 | 132 | ||
134 | int src_port = (int)request.Params[0]; | 133 | int src_port = (int)request.Params[0]; |
135 | Scene scene = null; | 134 | Scene scene = null; |
136 | // try to get the scene object | 135 | // try to get the scene object |
137 | RegionInfo src_region = SearchRegionFromPortNum(src_port); | 136 | RegionInfo src_region = SearchRegionFromPortNum(src_port); |
138 | if (sceneManager.TryGetScene(src_region.RegionID, out scene) == false) | 137 | if (sceneManager.TryGetScene(src_region.RegionID, out scene) == false) |
139 | { | 138 | { |
140 | m_log.Error("[BALANCER] "+"The Scene is not found"); | 139 | m_log.Error("[BALANCER] "+"The Scene is not found"); |
141 | return response; | 140 | return response; |
142 | } | 141 | } |
143 | // serialization of client's informations | 142 | // serialization of client's informations |
144 | List<ScenePresence> presences = scene.GetScenePresences(); | 143 | List<ScenePresence> presences = scene.GetScenePresences(); |
145 | int get_scene_presence = presences.Count; | 144 | int get_scene_presence = presences.Count; |
146 | int get_scene_presence_filter = 0; | 145 | int get_scene_presence_filter = 0; |
147 | foreach (ScenePresence pre in presences) | 146 | foreach (ScenePresence pre in presences) |
148 | { | 147 | { |
149 | ClientView client = (ClientView) pre.ControllingClient; | 148 | ClientView client = (ClientView) pre.ControllingClient; |
150 | //if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) { | 149 | //if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) { |
151 | if(client.PacketProcessingEnabled==true) { | 150 | if(client.PacketProcessingEnabled==true) { |
152 | get_scene_presence_filter++; | 151 | get_scene_presence_filter++; |
153 | } | 152 | } |
154 | } | 153 | } |
155 | List<ScenePresence> avatars = scene.GetAvatars(); | 154 | List<ScenePresence> avatars = scene.GetAvatars(); |
156 | int get_avatar = avatars.Count; | 155 | int get_avatar = avatars.Count; |
157 | int get_avatar_filter = 0; | 156 | int get_avatar_filter = 0; |
158 | string avatar_names = ""; | 157 | string avatar_names = ""; |
159 | foreach (ScenePresence pre in avatars) | 158 | foreach (ScenePresence pre in avatars) |
160 | { | 159 | { |
161 | ClientView client = (ClientView) pre.ControllingClient; | 160 | ClientView client = (ClientView) pre.ControllingClient; |
162 | //if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) { | 161 | //if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) { |
163 | if(client.PacketProcessingEnabled==true) { | 162 | if(client.PacketProcessingEnabled==true) { |
164 | get_avatar_filter++; | 163 | get_avatar_filter++; |
165 | avatar_names += pre.Firstname + " " + pre.Lastname + "; "; | 164 | avatar_names += pre.Firstname + " " + pre.Lastname + "; "; |
166 | } | 165 | } |
167 | } | 166 | } |
168 | 167 | ||
169 | Hashtable responseData = new Hashtable(); | 168 | Hashtable responseData = new Hashtable(); |
170 | responseData["get_scene_presence_filter"] = get_scene_presence_filter; | 169 | responseData["get_scene_presence_filter"] = get_scene_presence_filter; |
171 | responseData["get_scene_presence"] = get_scene_presence; | 170 | responseData["get_scene_presence"] = get_scene_presence; |
172 | responseData["get_avatar_filter"] = get_avatar_filter; | 171 | responseData["get_avatar_filter"] = get_avatar_filter; |
173 | responseData["get_avatar"] = get_avatar; | 172 | responseData["get_avatar"] = get_avatar; |
174 | responseData["avatar_names"] = avatar_names; | 173 | responseData["avatar_names"] = avatar_names; |
175 | response.Value = responseData; | 174 | response.Value = responseData; |
176 | 175 | ||
177 | m_log.Info("[BALANCER] "+"Exiting RegionStatus()"); | 176 | m_log.Info("[BALANCER] "+"Exiting RegionStatus()"); |
178 | } | 177 | } |
179 | catch (Exception e) | 178 | catch (Exception e) |
180 | { | 179 | { |
181 | m_log.Error("[BALANCER] "+e.ToString()); | 180 | m_log.Error("[BALANCER] "+e.ToString()); |
182 | m_log.Error("[BALANCER] "+e.StackTrace); | 181 | m_log.Error("[BALANCER] "+e.StackTrace); |
183 | } | 182 | } |
184 | return response; | 183 | return response; |
185 | } | 184 | } |
186 | 185 | ||
187 | private XmlRpcResponse SerializeRegion(XmlRpcRequest request) | 186 | private XmlRpcResponse SerializeRegion(XmlRpcRequest request) |
188 | { | 187 | { |
189 | try | 188 | try |
190 | { | 189 | { |
191 | m_log.Info("[BALANCER] "+"Entering SerializeRegion()"); | 190 | m_log.Info("[BALANCER] "+"Entering SerializeRegion()"); |
192 | 191 | ||
@@ -431,7 +430,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer | |||
431 | //scene.Backup(); | 430 | //scene.Backup(); |
432 | 431 | ||
433 | m_log.InfoFormat("[BALANCER] "+"region serialization completed [{0}]", | 432 | m_log.InfoFormat("[BALANCER] "+"region serialization completed [{0}]", |
434 | src_region.RegionID.ToString()); | 433 | src_region.RegionID.ToString()); |
435 | } | 434 | } |
436 | 435 | ||
437 | private void SerializeClient(int idx, Scene scene, ScenePresence pre, string export_dir) | 436 | private void SerializeClient(int idx, Scene scene, ScenePresence pre, string export_dir) |
@@ -499,7 +498,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer | |||
499 | DeserializeClient(dst_region, import_dir); | 498 | DeserializeClient(dst_region, import_dir); |
500 | 499 | ||
501 | m_log.InfoFormat("[BALANCER] "+"region deserialization completed [{0}]", | 500 | m_log.InfoFormat("[BALANCER] "+"region deserialization completed [{0}]", |
502 | dst_region.ToString()); | 501 | dst_region.ToString()); |
503 | } | 502 | } |
504 | catch (Exception e) | 503 | catch (Exception e) |
505 | { | 504 | { |
@@ -527,19 +526,19 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer | |||
527 | 526 | ||
528 | // restore the scene presence | 527 | // restore the scene presence |
529 | /* | 528 | /* |
530 | files = Directory.GetFiles(import_dir, "Presence_*.bin"); | 529 | files = Directory.GetFiles(import_dir, "Presence_*.bin"); |
531 | Array.Sort(files); | 530 | Array.Sort(files); |
532 | |||
533 | foreach (string filename in files) | ||
534 | { | ||
535 | sp = (ScenePresence)Util.DeserializeFromFile(filename); | ||
536 | Console.WriteLine("agent id = {0}", sp.m_uuid); | ||
537 | 531 | ||
538 | scene.m_restorePresences.Add(sp.m_uuid, sp); | 532 | foreach (string filename in files) |
539 | File.Delete(filename); | 533 | { |
534 | sp = (ScenePresence)Util.DeserializeFromFile(filename); | ||
535 | Console.WriteLine("agent id = {0}", sp.m_uuid); | ||
540 | 536 | ||
541 | m_log.InfoFormat("[BALANCER] "+"scene presence deserialized [{0}]", sp.m_uuid); | 537 | scene.m_restorePresences.Add(sp.m_uuid, sp); |
542 | } | 538 | File.Delete(filename); |
539 | |||
540 | m_log.InfoFormat("[BALANCER] "+"scene presence deserialized [{0}]", sp.m_uuid); | ||
541 | } | ||
543 | */ | 542 | */ |
544 | for (int i = 0; ; i++) | 543 | for (int i = 0; ; i++) |
545 | { | 544 | { |
@@ -576,18 +575,18 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer | |||
576 | 575 | ||
577 | udpserv.RestoreClient(agentdata, data.userEP, data.proxyEP); | 576 | udpserv.RestoreClient(agentdata, data.userEP, data.proxyEP); |
578 | 577 | ||
579 | // waiting for the scene-presense restored | 578 | // waiting for the scene-presense restored |
580 | lock (scene.m_restorePresences) | 579 | lock (scene.m_restorePresences) |
581 | { | 580 | { |
582 | Monitor.Wait(scene.m_restorePresences, 3000); | 581 | Monitor.Wait(scene.m_restorePresences, 3000); |
583 | } | 582 | } |
584 | 583 | ||
585 | if (scene.ClientManager.TryGetClient(circuit_code, out controller)) | 584 | if (scene.ClientManager.TryGetClient(circuit_code, out controller)) |
586 | { | 585 | { |
587 | m_log.InfoFormat("[BALANCER] " + "get client [{0}]", circuit_code); | 586 | m_log.InfoFormat("[BALANCER] " + "get client [{0}]", circuit_code); |
588 | controller.SetClientInfo(data); | 587 | controller.SetClientInfo(data); |
589 | } | 588 | } |
590 | 589 | ||
591 | File.Delete(fname); | 590 | File.Delete(fname); |
592 | 591 | ||
593 | m_log.InfoFormat("[BALANCER] " + "client info deserialized [{0}]", circuit_code); | 592 | m_log.InfoFormat("[BALANCER] " + "client info deserialized [{0}]", circuit_code); |
@@ -622,7 +621,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer | |||
622 | Console.WriteLine("scene found."); | 621 | Console.WriteLine("scene found."); |
623 | 622 | ||
624 | if ((sceneManager.CurrentScene != null) | 623 | if ((sceneManager.CurrentScene != null) |
625 | && (sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID)) | 624 | && (sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID)) |
626 | { | 625 | { |
627 | sceneManager.TrySetCurrentScene(".."); | 626 | sceneManager.TrySetCurrentScene(".."); |
628 | } | 627 | } |
@@ -671,10 +670,10 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer | |||
671 | { | 670 | { |
672 | // stopping clientview thread | 671 | // stopping clientview thread |
673 | if (((ClientView)controller).PacketProcessingEnabled) | 672 | if (((ClientView)controller).PacketProcessingEnabled) |
674 | { | 673 | { |
675 | controller.Stop(); | 674 | controller.Stop(); |
676 | ((ClientView)controller).PacketProcessingEnabled = false; | 675 | ((ClientView)controller).PacketProcessingEnabled = false; |
677 | } | 676 | } |
678 | // teminateing clientview thread | 677 | // teminateing clientview thread |
679 | controller.Terminate(); | 678 | controller.Terminate(); |
680 | m_log.Info("[BALANCER] "+"client thread stopped"); | 679 | m_log.Info("[BALANCER] "+"client thread stopped"); |
@@ -698,90 +697,90 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer | |||
698 | 697 | ||
699 | private XmlRpcResponse SplitRegion(XmlRpcRequest request) | 698 | private XmlRpcResponse SplitRegion(XmlRpcRequest request) |
700 | { | 699 | { |
701 | try | 700 | try |
702 | { | 701 | { |
703 | int myID = (int) request.Params[0]; | 702 | int myID = (int) request.Params[0]; |
704 | int numRegions = (int) request.Params[1]; | 703 | int numRegions = (int) request.Params[1]; |
705 | regionPortList = new int[numRegions]; | 704 | regionPortList = new int[numRegions]; |
706 | sceneURL = new string[numRegions]; | 705 | sceneURL = new string[numRegions]; |
707 | tcpClientList = new TcpClient[numRegions]; | 706 | tcpClientList = new TcpClient[numRegions]; |
708 | 707 | ||
709 | for(int i=0; i<numRegions; i++) | 708 | for(int i=0; i<numRegions; i++) |
710 | { | 709 | { |
711 | regionPortList[i]=(int) request.Params[i+2]; | 710 | regionPortList[i]=(int) request.Params[i+2]; |
712 | sceneURL[i]=(string) request.Params[i+2+numRegions]; | 711 | sceneURL[i]=(string) request.Params[i+2+numRegions]; |
713 | } | 712 | } |
714 | 713 | ||
715 | string hostname; | 714 | string hostname; |
716 | 715 | ||
717 | for(int i=0; i<numRegions; i++) | 716 | for(int i=0; i<numRegions; i++) |
718 | { | 717 | { |
719 | hostname = sceneURL[i].Split(new char[] { '/', ':' })[3]; | 718 | hostname = sceneURL[i].Split(new char[] { '/', ':' })[3]; |
720 | m_log.InfoFormat("[SPLITSCENE] "+"creating tcp client host:{0}", hostname); | 719 | m_log.InfoFormat("[SPLITSCENE] "+"creating tcp client host:{0}", hostname); |
721 | tcpClientList[i] = new TcpClient(hostname, 10001); | 720 | tcpClientList[i] = new TcpClient(hostname, 10001); |
722 | } | 721 | } |
723 | 722 | ||
724 | bool isMaster = (myID == 0); | 723 | bool isMaster = (myID == 0); |
725 | 724 | ||
726 | isLocalNeighbour = new bool[numRegions]; | 725 | isLocalNeighbour = new bool[numRegions]; |
727 | for(int i=0; i<numRegions; i++) isLocalNeighbour[i] = (sceneURL[i] == sceneURL[myID]); | 726 | for(int i=0; i<numRegions; i++) isLocalNeighbour[i] = (sceneURL[i] == sceneURL[myID]); |
728 | 727 | ||
729 | RegionInfo region = SearchRegionFromPortNum(regionPortList[myID]); | 728 | RegionInfo region = SearchRegionFromPortNum(regionPortList[myID]); |
730 | 729 | ||
731 | //Console.WriteLine("\n === SplitRegion {0}\n", region.RegionID); | 730 | //Console.WriteLine("\n === SplitRegion {0}\n", region.RegionID); |
732 | 731 | ||
733 | Scene scene; | 732 | Scene scene; |
734 | if (sceneManager.TryGetScene(region.RegionID, out scene)) | 733 | if (sceneManager.TryGetScene(region.RegionID, out scene)) |
735 | { | 734 | { |
736 | // Disable event updates, backups etc in the slave(s) | 735 | // Disable event updates, backups etc in the slave(s) |
737 | if (isMaster) { | 736 | if (isMaster) { |
738 | scene.Region_Status = RegionStatus.Up; | 737 | scene.Region_Status = RegionStatus.Up; |
739 | } | 738 | } |
740 | else | 739 | else |
741 | { | 740 | { |
742 | scene.Region_Status = RegionStatus.SlaveScene; | 741 | scene.Region_Status = RegionStatus.SlaveScene; |
743 | } | 742 | } |
744 | |||
745 | //Console.WriteLine("=== SplitRegion {0}: Scene found, status {1}", region.RegionID, scene.Region_Status); | ||
746 | 743 | ||
747 | // Disabling half of the avatars in master, and the other half in slave | 744 | //Console.WriteLine("=== SplitRegion {0}: Scene found, status {1}", region.RegionID, scene.Region_Status); |
748 | 745 | ||
749 | int i = 0; | 746 | // Disabling half of the avatars in master, and the other half in slave |
750 | List<ScenePresence> presences = scene.GetScenePresences(); | ||
751 | presences.Sort(); | ||
752 | foreach (ScenePresence pre in presences) | ||
753 | { | ||
754 | // Divide the presences evenly over the set of subscenes | ||
755 | ClientView client = (ClientView) pre.ControllingClient; | ||
756 | client.PacketProcessingEnabled = (( (i + myID) % sceneURL.Length) == 0); | ||
757 | 747 | ||
758 | m_log.InfoFormat("[SPLITSCENE] === SplitRegion {0}: SP.PacketEnabled {1}", region.RegionID, client.PacketProcessingEnabled); | 748 | int i = 0; |
749 | List<ScenePresence> presences = scene.GetScenePresences(); | ||
750 | presences.Sort(); | ||
751 | foreach (ScenePresence pre in presences) | ||
752 | { | ||
753 | // Divide the presences evenly over the set of subscenes | ||
754 | ClientView client = (ClientView) pre.ControllingClient; | ||
755 | client.PacketProcessingEnabled = (( (i + myID) % sceneURL.Length) == 0); | ||
759 | 756 | ||
760 | if (!client.PacketProcessingEnabled) | 757 | m_log.InfoFormat("[SPLITSCENE] === SplitRegion {0}: SP.PacketEnabled {1}", region.RegionID, client.PacketProcessingEnabled); |
761 | { | ||
762 | // stopping clientview thread | ||
763 | client.Stop(); | ||
764 | } | ||
765 | 758 | ||
766 | ++i; | 759 | if (!client.PacketProcessingEnabled) |
767 | } | 760 | { |
761 | // stopping clientview thread | ||
762 | client.Stop(); | ||
763 | } | ||
768 | 764 | ||
769 | scene.splitID = myID; | 765 | ++i; |
770 | scene.SynchronizeScene = new Scene.SynchronizeSceneHandler(SynchronizeScenes); | ||
771 | isSplit = true; | ||
772 | } | 766 | } |
773 | else | ||
774 | { | ||
775 | m_log.Error("[SPLITSCENE] "+String.Format("Scene not found {0}", region.RegionID)); | ||
776 | } | ||
777 | } | ||
778 | catch (Exception e) | ||
779 | { | ||
780 | m_log.Error("[SPLITSCENE] "+e.ToString()); | ||
781 | m_log.Error("[SPLITSCENE] "+e.StackTrace); | ||
782 | } | ||
783 | 767 | ||
784 | return new XmlRpcResponse(); | 768 | scene.splitID = myID; |
769 | scene.SynchronizeScene = new Scene.SynchronizeSceneHandler(SynchronizeScenes); | ||
770 | isSplit = true; | ||
771 | } | ||
772 | else | ||
773 | { | ||
774 | m_log.Error("[SPLITSCENE] "+String.Format("Scene not found {0}", region.RegionID)); | ||
775 | } | ||
776 | } | ||
777 | catch (Exception e) | ||
778 | { | ||
779 | m_log.Error("[SPLITSCENE] "+e.ToString()); | ||
780 | m_log.Error("[SPLITSCENE] "+e.StackTrace); | ||
781 | } | ||
782 | |||
783 | return new XmlRpcResponse(); | ||
785 | } | 784 | } |
786 | 785 | ||
787 | private XmlRpcResponse MergeRegions(XmlRpcRequest request) | 786 | private XmlRpcResponse MergeRegions(XmlRpcRequest request) |
@@ -794,40 +793,40 @@ presences.Sort(); | |||
794 | string src_url = (string) request.Params[0]; | 793 | string src_url = (string) request.Params[0]; |
795 | int src_port = (int) request.Params[1]; | 794 | int src_port = (int) request.Params[1]; |
796 | 795 | ||
797 | RegionInfo region = SearchRegionFromPortNum(src_port); | 796 | RegionInfo region = SearchRegionFromPortNum(src_port); |
798 | 797 | ||
799 | simMain.ProxyCommand(region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset); | 798 | simMain.ProxyCommand(region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset); |
800 | 799 | ||
801 | Scene scene; | 800 | Scene scene; |
802 | if (sceneManager.TryGetScene(region.RegionID, out scene)) | 801 | if (sceneManager.TryGetScene(region.RegionID, out scene)) |
803 | { | 802 | { |
804 | isSplit = false; | 803 | isSplit = false; |
805 | 804 | ||
806 | scene.SynchronizeScene = null; | 805 | scene.SynchronizeScene = null; |
807 | scene.Region_Status = RegionStatus.Up; | 806 | scene.Region_Status = RegionStatus.Up; |
808 | 807 | ||
809 | List<ScenePresence> presences = scene.GetScenePresences(); | 808 | List<ScenePresence> presences = scene.GetScenePresences(); |
810 | foreach (ScenePresence pre in presences) | 809 | foreach (ScenePresence pre in presences) |
811 | { | 810 | { |
812 | ClientView client = (ClientView) pre.ControllingClient; | 811 | ClientView client = (ClientView) pre.ControllingClient; |
813 | if (!client.PacketProcessingEnabled) | 812 | if (!client.PacketProcessingEnabled) |
814 | { | 813 | { |
815 | client.Restart(); | 814 | client.Restart(); |
816 | client.PacketProcessingEnabled = true; | 815 | client.PacketProcessingEnabled = true; |
817 | } | 816 | } |
818 | } | 817 | } |
819 | } | 818 | } |
820 | 819 | ||
821 | // Delete the slave scenes | 820 | // Delete the slave scenes |
822 | for(int i=1; i<sceneURL.Length; i++) | 821 | for(int i=1; i<sceneURL.Length; i++) |
823 | { | 822 | { |
824 | string url = (sceneURL[i].Split('/')[2]).Split(':')[0]; // get URL part from EP | 823 | string url = (sceneURL[i].Split('/')[2]).Split(':')[0]; // get URL part from EP |
825 | simMain.ProxyCommand(region.proxyUrl, "DeleteRegion", regionPortList[i] + proxyOffset, url); | 824 | simMain.ProxyCommand(region.proxyUrl, "DeleteRegion", regionPortList[i] + proxyOffset, url); |
826 | Thread.Sleep(1000); | 825 | Thread.Sleep(1000); |
827 | simMain.XmlRpcCommand(sceneURL[i], "TerminateRegion", regionPortList[i]); // TODO: need + proxyOffset? | 826 | simMain.XmlRpcCommand(sceneURL[i], "TerminateRegion", regionPortList[i]); // TODO: need + proxyOffset? |
828 | } | 827 | } |
829 | 828 | ||
830 | simMain.ProxyCommand(region.proxyUrl, "UnblockClientMessages", src_url, src_port + proxyOffset); | 829 | simMain.ProxyCommand(region.proxyUrl, "UnblockClientMessages", src_url, src_port + proxyOffset); |
831 | } | 830 | } |
832 | catch (Exception e) | 831 | catch (Exception e) |
833 | { | 832 | { |
@@ -835,7 +834,7 @@ presences.Sort(); | |||
835 | m_log.Error("[BALANCER] "+e.StackTrace); | 834 | m_log.Error("[BALANCER] "+e.StackTrace); |
836 | throw e; | 835 | throw e; |
837 | } | 836 | } |
838 | 837 | ||
839 | return new XmlRpcResponse(); | 838 | return new XmlRpcResponse(); |
840 | } | 839 | } |
841 | 840 | ||
@@ -870,11 +869,11 @@ presences.Sort(); | |||
870 | { | 869 | { |
871 | ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == scenePresenceID; }); | 870 | ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == scenePresenceID; }); |
872 | 871 | ||
873 | if (pre == null) | 872 | if (pre == null) |
874 | { | 873 | { |
875 | m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePhysics] ScenePresence is missing... ({0})", scenePresenceID.ToString()); | 874 | m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePhysics] ScenePresence is missing... ({0})", scenePresenceID.ToString()); |
876 | return; | 875 | return; |
877 | } | 876 | } |
878 | 877 | ||
879 | // m_log.Info("[SPLITSCENE] "+"LocalUpdatePhysics [region:{0}, client:{1}]", | 878 | // m_log.Info("[SPLITSCENE] "+"LocalUpdatePhysics [region:{0}, client:{1}]", |
880 | // regionID.ToString(), pre.UUID.ToString()); | 879 | // regionID.ToString(), pre.UUID.ToString()); |
@@ -905,56 +904,56 @@ presences.Sort(); | |||
905 | // Because data changes by the physics simulation when the client doesn't move, | 904 | // Because data changes by the physics simulation when the client doesn't move, |
906 | // if MovementFlag is false, It is necessary to synchronize. | 905 | // if MovementFlag is false, It is necessary to synchronize. |
907 | //if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) | 906 | //if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) |
908 | if(client.PacketProcessingEnabled==true) | 907 | if(client.PacketProcessingEnabled==true) |
909 | { | 908 | { |
910 | //m_log.Info("[SPLITSCENE] "+String.Format("Client moving in {0} {1}", scene.RegionInfo.RegionID, pre.AbsolutePosition)); | 909 | //m_log.Info("[SPLITSCENE] "+String.Format("Client moving in {0} {1}", scene.RegionInfo.RegionID, pre.AbsolutePosition)); |
911 | 910 | ||
912 | for (int i = 0; i < sceneURL.Length; i++) | 911 | for (int i = 0; i < sceneURL.Length; i++) |
913 | { | 912 | { |
914 | if (i == scene.splitID) | 913 | if (i == scene.splitID) |
915 | { | 914 | { |
916 | continue; | 915 | continue; |
917 | } | 916 | } |
918 | 917 | ||
919 | if(isLocalNeighbour[i]) | 918 | if(isLocalNeighbour[i]) |
920 | { | 919 | { |
921 | //m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Local) [region:{0}=>{1}, client:{2}]", | 920 | //m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Local) [region:{0}=>{1}, client:{2}]", |
922 | // scene.RegionInfo.RegionID, regionPortList[i], pre.UUID.ToString()); | 921 | // scene.RegionInfo.RegionID, regionPortList[i], pre.UUID.ToString()); |
923 | LocalUpdatePhysics(regionPortList[i], pre.UUID, pre.AbsolutePosition, pre.Velocity, pre.PhysicsActor.Flying); | 922 | LocalUpdatePhysics(regionPortList[i], pre.UUID, pre.AbsolutePosition, pre.Velocity, pre.PhysicsActor.Flying); |
924 | } | 923 | } |
925 | else | 924 | else |
926 | { | 925 | { |
927 | //m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Remote) [region port:{0}, client:{1}, position:{2}, velocity:{3}, flying:{4}]", | 926 | //m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Remote) [region port:{0}, client:{1}, position:{2}, velocity:{3}, flying:{4}]", |
928 | // regionPortList[i], pre.UUID.ToString(), pre.AbsolutePosition.ToString(), | 927 | // regionPortList[i], pre.UUID.ToString(), pre.AbsolutePosition.ToString(), |
929 | // pre.Velocity.ToString(), pre.PhysicsActor.Flying); | 928 | // pre.Velocity.ToString(), pre.PhysicsActor.Flying); |
930 | 929 | ||
931 | 930 | ||
932 | simMain.XmlRpcCommand(sceneURL[i], "UpdatePhysics", | 931 | simMain.XmlRpcCommand(sceneURL[i], "UpdatePhysics", |
933 | regionPortList[i], pre.UUID.GetBytes(), | 932 | regionPortList[i], pre.UUID.GetBytes(), |
934 | pre.AbsolutePosition.GetBytes(), pre.Velocity.GetBytes(), | 933 | pre.AbsolutePosition.GetBytes(), pre.Velocity.GetBytes(), |
935 | pre.PhysicsActor.Flying); | 934 | pre.PhysicsActor.Flying); |
936 | 935 | ||
937 | /* | 936 | /* |
938 | byte[] buff = new byte[12+12+1]; | 937 | byte[] buff = new byte[12+12+1]; |
939 | 938 | ||
940 | Buffer.BlockCopy(pre.AbsolutePosition.GetBytes(), 0, buff, 0, 12); | 939 | Buffer.BlockCopy(pre.AbsolutePosition.GetBytes(), 0, buff, 0, 12); |
941 | Buffer.BlockCopy(pre.Velocity.GetBytes(), 0, buff, 12, 12); | 940 | Buffer.BlockCopy(pre.Velocity.GetBytes(), 0, buff, 12, 12); |
942 | buff[24] = (byte)((pre.PhysicsActor.Flying)?1:0); | 941 | buff[24] = (byte)((pre.PhysicsActor.Flying)?1:0); |
943 | 942 | ||
944 | // create header | 943 | // create header |
945 | InternalPacketHeader header = new InternalPacketHeader(); | 944 | InternalPacketHeader header = new InternalPacketHeader(); |
946 | 945 | ||
947 | header.type = 1; | 946 | header.type = 1; |
948 | header.throttlePacketType = 0; | 947 | header.throttlePacketType = 0; |
949 | header.numbytes = buff.Length; | 948 | header.numbytes = buff.Length; |
950 | header.agent_id = pre.UUID.UUID; | 949 | header.agent_id = pre.UUID.UUID; |
951 | header.region_port = regionPortList[i]; | 950 | header.region_port = regionPortList[i]; |
952 | 951 | ||
953 | //Send | 952 | //Send |
954 | tcpClientList[i].send(header, buff); | 953 | tcpClientList[i].send(header, buff); |
955 | */ | 954 | */ |
956 | } | 955 | } |
957 | } | 956 | } |
958 | } | 957 | } |
959 | // ++i; | 958 | // ++i; |
960 | } | 959 | } |
@@ -968,41 +967,41 @@ presences.Sort(); | |||
968 | return false; | 967 | return false; |
969 | } | 968 | } |
970 | 969 | ||
971 | Scene localScene = (Scene)scene; | 970 | Scene localScene = (Scene)scene; |
972 | 971 | ||
973 | for (int i = 0; i < sceneURL.Length; i++) | 972 | for (int i = 0; i < sceneURL.Length; i++) |
974 | { | 973 | { |
975 | if (i == localScene.splitID) | 974 | if (i == localScene.splitID) |
976 | { | ||
977 | continue; | ||
978 | } | ||
979 | |||
980 | if(isLocalNeighbour[i]) | ||
981 | { | 975 | { |
982 | //m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Local) [type:{0}, client:{1}]", | 976 | continue; |
983 | // packet.Type.ToString(), agentID.ToString()); | ||
984 | LocalUpdatePacket(regionPortList[i], agentID, packet, throttlePacketType); | ||
985 | } | 977 | } |
986 | else | 978 | |
979 | if(isLocalNeighbour[i]) | ||
987 | { | 980 | { |
988 | //m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Remote) [type:{0}, client:{1}]", | 981 | //m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Local) [type:{0}, client:{1}]", |
989 | // packet.Type.ToString(), agentID.ToString()); | 982 | // packet.Type.ToString(), agentID.ToString()); |
990 | // to bytes | 983 | LocalUpdatePacket(regionPortList[i], agentID, packet, throttlePacketType); |
991 | byte[] buff = packet.ToBytes(); | 984 | } |
985 | else | ||
986 | { | ||
987 | //m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Remote) [type:{0}, client:{1}]", | ||
988 | // packet.Type.ToString(), agentID.ToString()); | ||
989 | // to bytes | ||
990 | byte[] buff = packet.ToBytes(); | ||
992 | 991 | ||
993 | // create header | 992 | // create header |
994 | InternalPacketHeader header = new InternalPacketHeader(); | 993 | InternalPacketHeader header = new InternalPacketHeader(); |
995 | 994 | ||
996 | header.type = 0; | 995 | header.type = 0; |
997 | header.throttlePacketType = (int)throttlePacketType; | 996 | header.throttlePacketType = (int)throttlePacketType; |
998 | header.numbytes = buff.Length; | 997 | header.numbytes = buff.Length; |
999 | header.agent_id = agentID.UUID; | 998 | header.agent_id = agentID.UUID; |
1000 | header.region_port = regionPortList[i]; | 999 | header.region_port = regionPortList[i]; |
1001 | 1000 | ||
1002 | //Send | 1001 | //Send |
1003 | tcpClientList[i].send(header, buff); | 1002 | tcpClientList[i].send(header, buff); |
1004 | 1003 | ||
1005 | PacketPool.Instance.ReturnPacket(packet); | 1004 | PacketPool.Instance.ReturnPacket(packet); |
1006 | } | 1005 | } |
1007 | } | 1006 | } |
1008 | 1007 | ||
@@ -1022,20 +1021,20 @@ presences.Sort(); | |||
1022 | { | 1021 | { |
1023 | ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == agentID; }); | 1022 | ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == agentID; }); |
1024 | 1023 | ||
1025 | if (pre == null) | 1024 | if (pre == null) |
1026 | { | 1025 | { |
1027 | m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePacket] ScenePresence is missing... ({0})", agentID.ToString()); | 1026 | m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePacket] ScenePresence is missing... ({0})", agentID.ToString()); |
1028 | return; | 1027 | return; |
1029 | } | 1028 | } |
1030 | 1029 | ||
1031 | if (((ClientView)pre.ControllingClient).PacketProcessingEnabled==true) | 1030 | if (((ClientView)pre.ControllingClient).PacketProcessingEnabled==true) |
1032 | { | 1031 | { |
1033 | pre.ControllingClient.OutPacket(packet, throttlePacketType); | 1032 | pre.ControllingClient.OutPacket(packet, throttlePacketType); |
1034 | } | 1033 | } |
1035 | else | 1034 | else |
1036 | { | 1035 | { |
1037 | PacketPool.Instance.ReturnPacket(packet); | 1036 | PacketPool.Instance.ReturnPacket(packet); |
1038 | } | 1037 | } |
1039 | } | 1038 | } |
1040 | } | 1039 | } |
1041 | 1040 | ||
@@ -1061,22 +1060,22 @@ presences.Sort(); | |||
1061 | // packetEnd = buff.Length; | 1060 | // packetEnd = buff.Length; |
1062 | 1061 | ||
1063 | try | 1062 | try |
1064 | { | 1063 | { |
1065 | //m_log.Info("[SPLITSCENE] "+"PacketPool.Instance : {0}", (PacketPool.Instance == null)?"null":"not null"); | 1064 | //m_log.Info("[SPLITSCENE] "+"PacketPool.Instance : {0}", (PacketPool.Instance == null)?"null":"not null"); |
1066 | //m_log.Info("[SPLITSCENE] "+"buff length={0}", buff.Length); | 1065 | //m_log.Info("[SPLITSCENE] "+"buff length={0}", buff.Length); |
1067 | 1066 | ||
1068 | packet = PacketPool.Instance.GetPacket(buff, ref packetEnd, zero); | 1067 | packet = PacketPool.Instance.GetPacket(buff, ref packetEnd, zero); |
1069 | 1068 | ||
1070 | LocalUpdatePacket(header.region_port, new LLUUID(header.agent_id), | 1069 | LocalUpdatePacket(header.region_port, new LLUUID(header.agent_id), |
1071 | packet, (ThrottleOutPacketType)header.throttlePacketType); | 1070 | packet, (ThrottleOutPacketType)header.throttlePacketType); |
1072 | } | 1071 | } |
1073 | catch (Exception e) | 1072 | catch (Exception e) |
1074 | { | 1073 | { |
1075 | m_log.Error("[SPLITSCENE] "+e.ToString()); | 1074 | m_log.Error("[SPLITSCENE] "+e.ToString()); |
1076 | m_log.Error("[SPLITSCENE] "+e.StackTrace); | 1075 | m_log.Error("[SPLITSCENE] "+e.StackTrace); |
1077 | } | 1076 | } |
1078 | 1077 | ||
1079 | break; | 1078 | break; |
1080 | 1079 | ||
1081 | case 1: | 1080 | case 1: |
1082 | 1081 | ||