Changeset 13553


Ignore:
Timestamp:
01/19/16 09:49:35 (5 years ago)
Author:
thasling
Message:

changed a few method names and other refactoring

Location:
branches/thasling/DistributedGA
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/thasling/DistributedGA/DistributedGA.Core.Host/Program.cs

    r13537 r13553  
    2525          var pop1 = CreatePopulation();
    2626          Console.WriteLine("Publish population into network...");
    27           h.PublishMigrationInfo(pop1);
     27          h.PublishDataToNetwork(pop1);
    2828          Console.WriteLine("Population published.");
    2929          Console.WriteLine("Recieved populations:");
    30           foreach (var item in h.GetMigrationInfo()) {
     30          foreach (var item in h.GetDataFromNetwork()) {
    3131            Console.WriteLine(string.Format("Population with Quality: {0:2} in Iteration {1}", item.Quality, item.IterationNumber));
    3232          }
  • branches/thasling/DistributedGA/DistributedGA.Core/Domain/MessageRecieveEventArgs.cs

    r13524 r13553  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    62
    7 namespace DistributedGA.Core.Domain
    8 {
    9     public class MessageRecieveEventArgs : EventArgs
    10     {
    11         public int val;
    12         public SolutionInfo[] Population { get; set; }
    13         public PeerInfo Sender { get; set; }
    14     }
     3namespace DistributedGA.Core.Domain {
     4  public class MessageRecieveEventArgs : EventArgs {
     5    public int val;
     6    public SolutionInfo[] data { get; set; }
     7    public PeerInfo Sender { get; set; }
     8  }
    159}
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/MessageContractImpl.cs

    r13538 r13553  
    77  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    88  public class MessageContractImpl : IMessageContract {
    9     public void SendPopulation(PeerInfo sender, SolutionInfo[] population) {
    10       MessageRecieveEventArgs args = new MessageRecieveEventArgs() { Sender = sender, Population = population };
     9    public void SendData(PeerInfo sender, SolutionInfo[] data) {
     10      MessageRecieveEventArgs args = new MessageRecieveEventArgs() { Sender = sender, data = data };
    1111
    1212      if (MessageRecieved != null) {
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/PeerNetworkMessageHandler.cs

    r13548 r13553  
    4343        host = new WcfMessageService();
    4444        ownInstance.Port = host.Init(ownInstance.IpAddress); //getting port, on which service is hostet
    45         host.OnPopulationRecieved += new EventHandler<MessageRecieveEventArgs>(OnPopulationRecieved);
     45        host.OnDataRecieved += new EventHandler<MessageRecieveEventArgs>(OnPopulationRecieved);
    4646
    4747        peerListManager = new WcfPeerListManager();
     
    6565    }
    6666
    67     public void PublishMigrationInfo(SolutionInfo[] population) {
     67    public void PublishDataToNetwork(SolutionInfo[] data) {
    6868      try {
    6969        foreach (PeerInfo peer in peerListManager.GetPeerList()) {
    7070          //HACK: manipulate for monitoring in test
    71           foreach (SolutionInfo si in population) {
     71          foreach (SolutionInfo si in data) {
    7272            si.IterationNumber = ownInstance.Port;
    7373          }
    7474          //maybe something will go wrong during network communication...
    7575          try {
    76             sender.SendPopulation(peer, population);
     76            sender.SendData(peer, data);
    7777          } catch (Exception ex) {
    7878            AddError("PeerNetworkMessageHandler.PublishMigrationInfo(during sending to one peer!)", ex);
     
    8484    }
    8585
    86     public SolutionInfo[] GetMigrationInfo() {
     86    public SolutionInfo[] GetDataFromNetwork() {
    8787      try {
    8888        List<SolutionInfo> res = new List<SolutionInfo>();
     
    131131      if (e != null) {
    132132        lock (activeQueueLocker) {
    133           foreach (SolutionInfo si in e.Population) {
     133          foreach (SolutionInfo si in e.data) {
    134134            writeQueue.Enqueue(si);
    135135          }
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageSender.cs

    r13524 r13553  
    1 using DistributedGA.Core.Domain;
     1using System;
     2using System.ServiceModel;
     3using DistributedGA.Core.Domain;
    24using DistributedGA.Core.Interface;
    3 using System;
    4 using System.Collections.Generic;
    5 using System.Linq;
    6 using System.ServiceModel;
    7 using System.Text;
    8 using System.Threading.Tasks;
    95
    10 namespace DistributedGA.Core.Implementation
    11 {
    12     public class WcfMessageSender : IMessageSender
    13     {
    14         private PeerInfo myself;
     6namespace DistributedGA.Core.Implementation {
     7  public class WcfMessageSender : IMessageSender {
     8    private PeerInfo myself;
    159
    16         public void Init(PeerInfo source)
    17         {
    18             myself = source;
    19         }
     10    public void Init(PeerInfo source) {
     11      myself = source;
     12    }
    2013
    21         public void SendPopulation(PeerInfo destination, SolutionInfo[] population)
    22         {
    23             var client = CreateServerClient(destination.IpAddress, destination.Port);
    24             client.SendPopulation(myself, population); //maybe timout exception...
    25         }
     14    public void SendData(PeerInfo destination, SolutionInfo[] data) {
     15      var client = CreateServerClient(destination.IpAddress, destination.Port);
     16      client.SendData(myself, data); //maybe timout exception...
     17    }
    2618
    27         private IMessageContract CreateServerClient(string ip, int port)
    28         {
    29             var serviceUrl = "DistributedGA.svc";
    30             var baseUri = new Uri(string.Concat("http://", ip, ":", port, "/DistributedGA"));
    31             var serviceUri = new Uri(baseUri, serviceUrl);
     19    private IMessageContract CreateServerClient(string ip, int port) {
     20      var serviceUrl = "DistributedGA.svc";
     21      var baseUri = new Uri(string.Concat("http://", ip, ":", port, "/DistributedGA"));
     22      var serviceUri = new Uri(baseUri, serviceUrl);
    3223
    33             var binding = new BasicHttpBinding();
    34             var endpoint = new EndpointAddress(serviceUri);
    35             var myChannelFactory = new ChannelFactory<IMessageContract>(binding, endpoint);
     24      var binding = new BasicHttpBinding();
     25      var endpoint = new EndpointAddress(serviceUri);
     26      var myChannelFactory = new ChannelFactory<IMessageContract>(binding, endpoint);
    3627
    37             IMessageContract client = null;
    38             client = myChannelFactory.CreateChannel();
    39             return client;
    40         }
     28      IMessageContract client = null;
     29      client = myChannelFactory.CreateChannel();
     30      return client;
     31    }
    4132
    42     }
     33  }
    4334}
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageService.cs

    r13547 r13553  
    99namespace DistributedGA.Core.Implementation {
    1010  public class WcfMessageService : IMessageService {
    11     public event EventHandler<MessageRecieveEventArgs> OnPopulationRecieved;
     11    public event EventHandler<MessageRecieveEventArgs> OnDataRecieved;
    1212
    1313    private static ManualResetEvent _ResetEvent = new ManualResetEvent(false);
     
    5555
    5656    private void OnMessageRecieved(object sender, MessageRecieveEventArgs e) {
    57       if (OnPopulationRecieved != null) {
    58         OnPopulationRecieved(this, e);
     57      if (OnDataRecieved != null) {
     58        OnDataRecieved(this, e);
    5959      }
    6060    }
  • branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageContract.cs

    r13538 r13553  
    77  public interface IMessageContract {
    88    [OperationContract]
    9     void SendPopulation(PeerInfo sender, SolutionInfo[] population);
     9    void SendData(PeerInfo sender, SolutionInfo[] data);
    1010
    1111    event EventHandler<MessageRecieveEventArgs> MessageRecieved;
  • branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageHandler.cs

    r13547 r13553  
    66    void Init(); //Registers at contract-server
    77
    8     void PublishMigrationInfo(SolutionInfo[] population);
     8    void PublishDataToNetwork(SolutionInfo[] data);
    99
    10     SolutionInfo[] GetMigrationInfo();
     10    SolutionInfo[] GetDataFromNetwork();
    1111
    1212    PeerInfo GetPeerInfo();
  • branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageSender.cs

    r13524 r13553  
    11using DistributedGA.Core.Domain;
    2 using System;
    3 using System.Collections.Generic;
    4 using System.Linq;
    5 using System.Text;
    6 using System.Threading.Tasks;
    72
    8 namespace DistributedGA.Core.Interface
    9 {
    10     public interface IMessageSender
    11     {
    12         void Init(PeerInfo source);
     3namespace DistributedGA.Core.Interface {
     4  public interface IMessageSender {
     5    void Init(PeerInfo source);
    136
    14         void SendPopulation(PeerInfo destination, SolutionInfo[] population);
    15     }
     7    void SendData(PeerInfo destination, SolutionInfo[] data);
     8  }
    169}
  • branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageService.cs

    r13547 r13553  
    1313    void Dispose();
    1414
    15     event EventHandler<MessageRecieveEventArgs> OnPopulationRecieved;
     15    event EventHandler<MessageRecieveEventArgs> OnDataRecieved;
    1616  }
    1717}
  • branches/thasling/DistributedGA/DistributedGA.Test/Form1.cs

    r13538 r13553  
    2121      IMessageSender c = new WcfMessageSender();
    2222      c.Init(null);
    23       c.SendPopulation(null, null);
     23      c.SendData(null, null);
    2424    }
    2525
     
    3636      h5.Init();
    3737      var pop1 = CreatePopulation();
    38       h1.PublishMigrationInfo(pop1);
    39       h1.PublishMigrationInfo(pop1);
    40       var res1 = h1.GetMigrationInfo();
    41       var res2 = h2.GetMigrationInfo();
    42       h1.PublishMigrationInfo(pop1);
    43       h1.PublishMigrationInfo(pop1);
    44       var res3 = h1.GetMigrationInfo();
    45       var res4 = h2.GetMigrationInfo();
    46       h1.PublishMigrationInfo(pop1);
    47       h1.PublishMigrationInfo(pop1);
    48       var res5 = h1.GetMigrationInfo();
    49       var res6 = h2.GetMigrationInfo();
     38      h1.PublishDataToNetwork(pop1);
     39      h1.PublishDataToNetwork(pop1);
     40      var res1 = h1.GetDataFromNetwork();
     41      var res2 = h2.GetDataFromNetwork();
     42      h1.PublishDataToNetwork(pop1);
     43      h1.PublishDataToNetwork(pop1);
     44      var res3 = h1.GetDataFromNetwork();
     45      var res4 = h2.GetDataFromNetwork();
     46      h1.PublishDataToNetwork(pop1);
     47      h1.PublishDataToNetwork(pop1);
     48      var res5 = h1.GetDataFromNetwork();
     49      var res6 = h2.GetDataFromNetwork();
    5050      int i = 0;
    5151    }
Note: See TracChangeset for help on using the changeset viewer.