Changeset 13541 for branches/thasling
- Timestamp:
- 01/18/16 15:15:19 (9 years ago)
- Location:
- branches/thasling/DistributedGA
- Files:
-
- 6 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/thasling/DistributedGA/DistributedGA.Core.Host/App.config
r13538 r13541 6 6 <appSettings> 7 7 <add key="ContactServerURL" value="http://localhost:9090/DistributedGA.ContactServer/ContactService"/> 8 <add key="LanIpPrefix" value="10."/> 8 9 </appSettings> 9 10 </configuration> -
branches/thasling/DistributedGA/DistributedGA.Core.Host/DistributedGA.Core.Host.csproj
r13524 r13541 46 46 </ItemGroup> 47 47 <ItemGroup> 48 <None Include="App.config" /> 48 <None Include="App.config"> 49 <SubType>Designer</SubType> 50 </None> 49 51 </ItemGroup> 50 52 <ItemGroup> -
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/PeerNetworkMessageHandler.cs
r13538 r13541 2 2 using System.Collections.Concurrent; 3 3 using System.Collections.Generic; 4 using System.Configuration; 5 using System.Linq; 4 6 using System.Net; 5 using System.Text.RegularExpressions;6 7 using DistributedGA.Core.Domain; 7 8 using DistributedGA.Core.Interface; … … 20 21 //provides current population for the higher layer IMigrationOperator 21 22 //to queues are used to gather and and provide population more efficiently 22 private ConcurrentQueue<SolutionInfo> collectedResults1; 23 private ConcurrentQueue<SolutionInfo> collectedResults2; 23 private object activeQueueLocker = new object(); 24 private ConcurrentQueue<SolutionInfo> writeQueue; 25 private ConcurrentQueue<SolutionInfo> readQueue; 24 26 private bool collectingInFirstQueue = true; //currently first queue is filled with recieved populations 25 27 26 28 //uses IMessageService for recieving population from one peer at once 27 29 private IMessageService host = null; 30 31 28 32 29 33 public void Init() { … … 35 39 }; // TODO: get own peerinfo 36 40 37 collectedResults1= new ConcurrentQueue<SolutionInfo>();38 collectedResults2= new ConcurrentQueue<SolutionInfo>();41 writeQueue = new ConcurrentQueue<SolutionInfo>(); 42 readQueue = new ConcurrentQueue<SolutionInfo>(); 39 43 40 44 host = new WcfMessageService(); … … 82 86 try { 83 87 List<SolutionInfo> res = new List<SolutionInfo>(); 84 ConcurrentQueue<SolutionInfo> source = null;85 88 SolutionInfo item = null; 86 if (collectingInFirstQueue) { 87 collectingInFirstQueue = false; //switching queue 88 source = collectedResults1; 89 } else { 90 collectingInFirstQueue = true; //switching queue 91 source = collectedResults2; 89 lock (activeQueueLocker) { 90 var tmp = readQueue; 91 readQueue = writeQueue; 92 writeQueue = tmp; 92 93 } 94 93 95 //creating resultset 94 while (! source.IsEmpty) {95 if ( source.TryDequeue(out item)) {96 while (!readQueue.IsEmpty) { 97 if (readQueue.TryDequeue(out item)) { 96 98 res.Add(item); 97 99 } … … 114 116 private string GetExternalIpAddress() { 115 117 try { 116 string externalIP; 117 externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/"); 118 externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")) 119 .Matches(externalIP)[0].ToString(); 120 return externalIP; 118 var strHostName = Dns.GetHostName(); 119 // Then using host name, get the IP address list.. 120 IPHostEntry ipEntry = Dns.GetHostEntry(strHostName); 121 IPAddress[] addr = ipEntry.AddressList; 122 123 return addr 124 .Select(ip => ip.ToString()) 125 .First(str => str.StartsWith(ConfigurationManager.AppSettings["LanIpPrefix"])); 121 126 } catch { return null; } 122 127 } … … 124 129 private void OnPopulationRecieved(object sender, MessageRecieveEventArgs e) { 125 130 if (e != null) { 126 foreach (SolutionInfo si in e.Population) { 127 if (collectingInFirstQueue) { 128 collectedResults1.Enqueue(si); 129 } else { 130 collectedResults2.Enqueue(si); 131 lock (activeQueueLocker) { 132 foreach (SolutionInfo si in e.Population) { 133 writeQueue.Enqueue(si); 131 134 } 132 135 } … … 141 144 } 142 145 } 143 144 146 } 145 147 } -
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageService.cs
r13538 r13541 17 17 public int Init(string ip) { 18 18 int port = 0; 19 //port = GetRanodmFreePort();20 19 port = FreeTcpPort(); 21 20 -
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfPeerListManager.cs
r13538 r13541 9 9 namespace DistributedGA.Core.Implementation { 10 10 public class WcfPeerListManager : IPeerListManager { 11 private string SERVER_STRING= null;11 private string serverString = null; 12 12 13 13 private IContactService client = null; … … 19 19 20 20 public void Init(PeerInfo source) { 21 SERVER_STRING= ConfigurationManager.AppSettings["ContactServerURL"];21 serverString = ConfigurationManager.AppSettings["ContactServerURL"]; 22 22 client = CreateClient(); 23 23 myself = source; … … 41 41 private IContactService CreateClient() { 42 42 var binding = new BasicHttpBinding(); 43 var endpoint = new EndpointAddress( SERVER_STRING);43 var endpoint = new EndpointAddress(serverString); 44 44 var myChannelFactory = new ChannelFactory<IContactService>(binding, endpoint); 45 45 … … 52 52 //communicate with 10% of the network 53 53 int noOfPeers = allPeers.Count / 10; 54 List< Int32> indexList = GetRandomItemIndexes(noOfPeers, 0, allPeers.Count - 1);54 List<int> indexList = GetRandomItemIndexes(noOfPeers, 0, allPeers.Count - 1); 55 55 List<PeerInfo> res = new List<PeerInfo>(); 56 foreach ( Int32index in indexList) {56 foreach (int index in indexList) { 57 57 res.Add(allPeers.ElementAt(index)); 58 58 } … … 60 60 } 61 61 62 private List< Int32> GetRandomItemIndexes(int noOfItems, int minValue, int maxValue) {63 List< Int32> res = new List<Int32>();62 private List<int> GetRandomItemIndexes(int noOfItems, int minValue, int maxValue) { 63 List<int> res = new List<int>(); 64 64 Random rnd = new Random(); 65 65 int tmp = -1; -
branches/thasling/DistributedGA/DistributedGA.Test/DistributedGA.Test.csproj
r13524 r13541 76 76 </ItemGroup> 77 77 <ItemGroup> 78 <None Include="App.config" /> 78 <None Include="App.config"> 79 <SubType>Designer</SubType> 80 </None> 79 81 </ItemGroup> 80 82 <ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.