Changeset 13553
- Timestamp:
- 01/19/16 09:49:35 (9 years ago)
- Location:
- branches/thasling/DistributedGA
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/thasling/DistributedGA/DistributedGA.Core.Host/Program.cs
r13537 r13553 25 25 var pop1 = CreatePopulation(); 26 26 Console.WriteLine("Publish population into network..."); 27 h.Publish MigrationInfo(pop1);27 h.PublishDataToNetwork(pop1); 28 28 Console.WriteLine("Population published."); 29 29 Console.WriteLine("Recieved populations:"); 30 foreach (var item in h.Get MigrationInfo()) {30 foreach (var item in h.GetDataFromNetwork()) { 31 31 Console.WriteLine(string.Format("Population with Quality: {0:2} in Iteration {1}", item.Quality, item.IterationNumber)); 32 32 } -
branches/thasling/DistributedGA/DistributedGA.Core/Domain/MessageRecieveEventArgs.cs
r13524 r13553 1 1 using System; 2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 2 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 } 3 namespace 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 } 15 9 } -
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/MessageContractImpl.cs
r13538 r13553 7 7 [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] 8 8 public class MessageContractImpl : IMessageContract { 9 public void Send Population(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 }; 11 11 12 12 if (MessageRecieved != null) { -
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/PeerNetworkMessageHandler.cs
r13548 r13553 43 43 host = new WcfMessageService(); 44 44 ownInstance.Port = host.Init(ownInstance.IpAddress); //getting port, on which service is hostet 45 host.On PopulationRecieved += new EventHandler<MessageRecieveEventArgs>(OnPopulationRecieved);45 host.OnDataRecieved += new EventHandler<MessageRecieveEventArgs>(OnPopulationRecieved); 46 46 47 47 peerListManager = new WcfPeerListManager(); … … 65 65 } 66 66 67 public void Publish MigrationInfo(SolutionInfo[] population) {67 public void PublishDataToNetwork(SolutionInfo[] data) { 68 68 try { 69 69 foreach (PeerInfo peer in peerListManager.GetPeerList()) { 70 70 //HACK: manipulate for monitoring in test 71 foreach (SolutionInfo si in population) {71 foreach (SolutionInfo si in data) { 72 72 si.IterationNumber = ownInstance.Port; 73 73 } 74 74 //maybe something will go wrong during network communication... 75 75 try { 76 sender.Send Population(peer, population);76 sender.SendData(peer, data); 77 77 } catch (Exception ex) { 78 78 AddError("PeerNetworkMessageHandler.PublishMigrationInfo(during sending to one peer!)", ex); … … 84 84 } 85 85 86 public SolutionInfo[] Get MigrationInfo() {86 public SolutionInfo[] GetDataFromNetwork() { 87 87 try { 88 88 List<SolutionInfo> res = new List<SolutionInfo>(); … … 131 131 if (e != null) { 132 132 lock (activeQueueLocker) { 133 foreach (SolutionInfo si in e. Population) {133 foreach (SolutionInfo si in e.data) { 134 134 writeQueue.Enqueue(si); 135 135 } -
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageSender.cs
r13524 r13553 1 using DistributedGA.Core.Domain; 1 using System; 2 using System.ServiceModel; 3 using DistributedGA.Core.Domain; 2 4 using 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;9 5 10 namespace DistributedGA.Core.Implementation 11 { 12 public class WcfMessageSender : IMessageSender 13 { 14 private PeerInfo myself; 6 namespace DistributedGA.Core.Implementation { 7 public class WcfMessageSender : IMessageSender { 8 private PeerInfo myself; 15 9 16 public void Init(PeerInfo source) 17 { 18 myself = source; 19 } 10 public void Init(PeerInfo source) { 11 myself = source; 12 } 20 13 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 } 26 18 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); 32 23 33 34 35 24 var binding = new BasicHttpBinding(); 25 var endpoint = new EndpointAddress(serviceUri); 26 var myChannelFactory = new ChannelFactory<IMessageContract>(binding, endpoint); 36 27 37 38 39 40 28 IMessageContract client = null; 29 client = myChannelFactory.CreateChannel(); 30 return client; 31 } 41 32 42 33 } 43 34 } -
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageService.cs
r13547 r13553 9 9 namespace DistributedGA.Core.Implementation { 10 10 public class WcfMessageService : IMessageService { 11 public event EventHandler<MessageRecieveEventArgs> On PopulationRecieved;11 public event EventHandler<MessageRecieveEventArgs> OnDataRecieved; 12 12 13 13 private static ManualResetEvent _ResetEvent = new ManualResetEvent(false); … … 55 55 56 56 private void OnMessageRecieved(object sender, MessageRecieveEventArgs e) { 57 if (On PopulationRecieved != null) {58 On PopulationRecieved(this, e);57 if (OnDataRecieved != null) { 58 OnDataRecieved(this, e); 59 59 } 60 60 } -
branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageContract.cs
r13538 r13553 7 7 public interface IMessageContract { 8 8 [OperationContract] 9 void Send Population(PeerInfo sender, SolutionInfo[] population);9 void SendData(PeerInfo sender, SolutionInfo[] data); 10 10 11 11 event EventHandler<MessageRecieveEventArgs> MessageRecieved; -
branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageHandler.cs
r13547 r13553 6 6 void Init(); //Registers at contract-server 7 7 8 void Publish MigrationInfo(SolutionInfo[] population);8 void PublishDataToNetwork(SolutionInfo[] data); 9 9 10 SolutionInfo[] Get MigrationInfo();10 SolutionInfo[] GetDataFromNetwork(); 11 11 12 12 PeerInfo GetPeerInfo(); -
branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageSender.cs
r13524 r13553 1 1 using DistributedGA.Core.Domain; 2 using System;3 using System.Collections.Generic;4 using System.Linq;5 using System.Text;6 using System.Threading.Tasks;7 2 8 namespace DistributedGA.Core.Interface 9 { 10 public interface IMessageSender 11 { 12 void Init(PeerInfo source); 3 namespace DistributedGA.Core.Interface { 4 public interface IMessageSender { 5 void Init(PeerInfo source); 13 6 14 void SendPopulation(PeerInfo destination, SolutionInfo[] population);15 7 void SendData(PeerInfo destination, SolutionInfo[] data); 8 } 16 9 } -
branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageService.cs
r13547 r13553 13 13 void Dispose(); 14 14 15 event EventHandler<MessageRecieveEventArgs> On PopulationRecieved;15 event EventHandler<MessageRecieveEventArgs> OnDataRecieved; 16 16 } 17 17 } -
branches/thasling/DistributedGA/DistributedGA.Test/Form1.cs
r13538 r13553 21 21 IMessageSender c = new WcfMessageSender(); 22 22 c.Init(null); 23 c.Send Population(null, null);23 c.SendData(null, null); 24 24 } 25 25 … … 36 36 h5.Init(); 37 37 var pop1 = CreatePopulation(); 38 h1.Publish MigrationInfo(pop1);39 h1.Publish MigrationInfo(pop1);40 var res1 = h1.Get MigrationInfo();41 var res2 = h2.Get MigrationInfo();42 h1.Publish MigrationInfo(pop1);43 h1.Publish MigrationInfo(pop1);44 var res3 = h1.Get MigrationInfo();45 var res4 = h2.Get MigrationInfo();46 h1.Publish MigrationInfo(pop1);47 h1.Publish MigrationInfo(pop1);48 var res5 = h1.Get MigrationInfo();49 var res6 = h2.Get MigrationInfo();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(); 50 50 int i = 0; 51 51 }
Note: See TracChangeset
for help on using the changeset viewer.