Changeset 13541


Ignore:
Timestamp:
01/18/16 15:15:19 (5 years ago)
Author:
thasling
Message:

added new empty project for test on hive
changed scheme for ip determination
changed handling of queues in messagehandler

Location:
branches/thasling/DistributedGA
Files:
6 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/thasling/DistributedGA/DistributedGA.Core.Host/App.config

    r13538 r13541  
    66  <appSettings>
    77    <add key="ContactServerURL" value="http://localhost:9090/DistributedGA.ContactServer/ContactService"/>
     8    <add key="LanIpPrefix" value="10."/>
    89  </appSettings>
    910</configuration>
  • branches/thasling/DistributedGA/DistributedGA.Core.Host/DistributedGA.Core.Host.csproj

    r13524 r13541  
    4646  </ItemGroup>
    4747  <ItemGroup>
    48     <None Include="App.config" />
     48    <None Include="App.config">
     49      <SubType>Designer</SubType>
     50    </None>
    4951  </ItemGroup>
    5052  <ItemGroup>
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/PeerNetworkMessageHandler.cs

    r13538 r13541  
    22using System.Collections.Concurrent;
    33using System.Collections.Generic;
     4using System.Configuration;
     5using System.Linq;
    46using System.Net;
    5 using System.Text.RegularExpressions;
    67using DistributedGA.Core.Domain;
    78using DistributedGA.Core.Interface;
     
    2021    //provides current population for the higher layer IMigrationOperator
    2122    //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;
    2426    private bool collectingInFirstQueue = true; //currently first queue is filled with recieved populations
    2527
    2628    //uses IMessageService for recieving population from one peer at once
    2729    private IMessageService host = null;
     30
     31
    2832
    2933    public void Init() {
     
    3539        }; // TODO: get own peerinfo
    3640
    37         collectedResults1 = new ConcurrentQueue<SolutionInfo>();
    38         collectedResults2 = new ConcurrentQueue<SolutionInfo>();
     41        writeQueue = new ConcurrentQueue<SolutionInfo>();
     42        readQueue = new ConcurrentQueue<SolutionInfo>();
    3943
    4044        host = new WcfMessageService();
     
    8286      try {
    8387        List<SolutionInfo> res = new List<SolutionInfo>();
    84         ConcurrentQueue<SolutionInfo> source = null;
    8588        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;
    9293        }
     94
    9395        //creating resultset
    94         while (!source.IsEmpty) {
    95           if (source.TryDequeue(out item)) {
     96        while (!readQueue.IsEmpty) {
     97          if (readQueue.TryDequeue(out item)) {
    9698            res.Add(item);
    9799          }
     
    114116    private string GetExternalIpAddress() {
    115117      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"]));
    121126      } catch { return null; }
    122127    }
     
    124129    private void OnPopulationRecieved(object sender, MessageRecieveEventArgs e) {
    125130      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);
    131134          }
    132135        }
     
    141144      }
    142145    }
    143 
    144146  }
    145147}
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageService.cs

    r13538 r13541  
    1717    public int Init(string ip) {
    1818      int port = 0;
    19       //port = GetRanodmFreePort();
    2019      port = FreeTcpPort();
    2120
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfPeerListManager.cs

    r13538 r13541  
    99namespace DistributedGA.Core.Implementation {
    1010  public class WcfPeerListManager : IPeerListManager {
    11     private string SERVER_STRING = null;
     11    private string serverString = null;
    1212
    1313    private IContactService client = null;
     
    1919
    2020    public void Init(PeerInfo source) {
    21       SERVER_STRING = ConfigurationManager.AppSettings["ContactServerURL"];
     21      serverString = ConfigurationManager.AppSettings["ContactServerURL"];
    2222      client = CreateClient();
    2323      myself = source;
     
    4141    private IContactService CreateClient() {
    4242      var binding = new BasicHttpBinding();
    43       var endpoint = new EndpointAddress(SERVER_STRING);
     43      var endpoint = new EndpointAddress(serverString);
    4444      var myChannelFactory = new ChannelFactory<IContactService>(binding, endpoint);
    4545
     
    5252      //communicate with 10% of the network
    5353      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);
    5555      List<PeerInfo> res = new List<PeerInfo>();
    56       foreach (Int32 index in indexList) {
     56      foreach (int index in indexList) {
    5757        res.Add(allPeers.ElementAt(index));
    5858      }
     
    6060    }
    6161
    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>();
    6464      Random rnd = new Random();
    6565      int tmp = -1;
  • branches/thasling/DistributedGA/DistributedGA.Test/DistributedGA.Test.csproj

    r13524 r13541  
    7676  </ItemGroup>
    7777  <ItemGroup>
    78     <None Include="App.config" />
     78    <None Include="App.config">
     79      <SubType>Designer</SubType>
     80    </None>
    7981  </ItemGroup>
    8082  <ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.