Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13905 for branches


Ignore:
Timestamp:
06/17/16 12:03:25 (8 years ago)
Author:
gkronber
Message:

#2615: added a first version of an analyzer

Location:
branches/thasling/DistributedGA
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/thasling/DistributedGA/DistributedGA.ContactServer.Host/DistributedGA.ContactServer.Host.csproj

    r13887 r13905  
    4848  <ItemGroup>
    4949    <None Include="App.config" />
    50     <None Include="startServer.bat">
    51       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    52     </None>
    5350  </ItemGroup>
    5451  <ItemGroup>
  • branches/thasling/DistributedGA/DistributedGA.ContactServer/ContactServiceImpl.cs

    r13888 r13905  
    88using DistributedGA.Core.Domain;
    99
    10 namespace DistributedGA.ContactServer
    11 {
     10namespace DistributedGA.ContactServer {
    1211
    13     [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    14     public class ContactServiceImpl : IContactService
    15     {
     12  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
     13  public class ContactServiceImpl : IContactService {
    1614
    17         private ConcurrentDictionary<PeerInfo, DateTime> allPeers = null;
     15    private ConcurrentDictionary<PeerInfo, DateTime> allPeers = null;
    1816
    19         private Timer timer = null;
     17    private Timer timer = null;
    2018
    21         private Object logLock = new Object();
     19    private Object logLock = new Object();
    2220
    23         public ContactServiceImpl()
    24         {
    25             allPeers = new ConcurrentDictionary<PeerInfo, DateTime>();
     21    public ContactServiceImpl() {
     22      allPeers = new ConcurrentDictionary<PeerInfo, DateTime>();
    2623
    27             timer = new Timer(1000); //each hour
    28             timer.Elapsed += CleanUpContactTable;
    29             timer.Start();
     24      timer = new Timer(1000); //each hour
     25      timer.Elapsed += CleanUpContactTable;
     26      timer.Start();
     27    }
     28
     29    public void RegisterPeer(PeerInfo source) {
     30      try {
     31        UpdateHeartbeat(source);
     32      } catch (Exception ex) {
     33        AddError("ContactServiceImpl.RegisterPeer", ex);
     34      }
     35    }
     36
     37    public List<PeerInfo> GetPeerList(PeerInfo source) {
     38      try {
     39        UpdateHeartbeat(source);
     40        //only return peers of the same work group and not the sender itself
     41        return allPeers.Keys.Where(x => {
     42          if (source.ProblemInstance.Equals(x.ProblemInstance) &&
     43              (!(x.IpAddress.Equals(source.IpAddress) && (x.Port.Equals(source.Port)))))
     44            return true;
     45          else
     46            return false;
     47        }).ToList();
     48      } catch (Exception ex) {
     49        AddError("ContactServiceImpl.GetPeerList", ex);
     50        return null;
     51      }
     52    }
     53
     54    public void MakeLog(PeerInfo source, string msg) {
     55      try {
     56        // TODO
     57        lock (logLock) {
     58          File.AppendAllText("Log.txt", string.Concat(source.IpAddress, ":", source.Port, ",", source.ProblemInstance, ",", msg, Environment.NewLine));
    3059        }
     60      } catch (Exception ex) {
     61        //Nothing to do because maybe called from adderror
     62      }
     63    }
    3164
    32         public void RegisterPeer(PeerInfo source)
    33         {
    34             try
    35             {
    36                 UpdateHeartbeat(source);
    37             }
    38             catch (Exception ex)
    39             {
    40                 AddError("ContactServiceImpl.RegisterPeer", ex);
    41             }
     65    public void UpdateHeartbeat(PeerInfo source) {
     66      try {
     67        Console.WriteLine("hb from {0}:{1}", source.IpAddress, source.Port);
     68        DateTime now = DateTime.Now;
     69        allPeers.AddOrUpdate(source, now, (k, v) => v = now);
     70      } catch (Exception ex) {
     71        AddError("ContactServiceImpl.UpdateHeartbeat", ex);
     72      }
     73    }
     74
     75    private void CleanUpContactTable(object sender, ElapsedEventArgs e) {
     76      DateTime deadline = DateTime.Now;
     77      //collect items to remove
     78      List<PeerInfo> itemsToDelete = new List<PeerInfo>();
     79      foreach (PeerInfo pi in allPeers.Keys) {
     80        DateTime tmp;
     81        if (allPeers.TryGetValue(pi, out tmp)) {
     82          //if (tmp.AddHours(1f) < deadline)
     83          if (tmp.AddMinutes(1) < deadline)  //TODO
     84                    {
     85            //if (tmp < deadline.AddHours(1f)) {
     86            itemsToDelete.Add(pi);
     87          }
    4288        }
     89      }
     90      //remove items
     91      foreach (PeerInfo pi in itemsToDelete) {
     92        DateTime tmp;
     93        allPeers.TryRemove(pi, out tmp);
     94      }
     95    }
    4396
    44         public List<PeerInfo> GetPeerList(PeerInfo source)
    45         {
    46             try
    47             {
    48                 UpdateHeartbeat(source);
    49                 //only return peers of the same work group and not the sender itself
    50                 return allPeers.Keys.Where(x =>
    51                 {
    52                     if (source.ProblemInstance.Equals(x.ProblemInstance) &&
    53                         (!(x.IpAddress.Equals(source.IpAddress) && (x.Port.Equals(source.Port)))))
    54                         return true;
    55                     else
    56                         return false;
    57                 }).ToList();
    58             }
    59             catch (Exception ex)
    60             {
    61                 AddError("ContactServiceImpl.GetPeerList", ex);
    62                 return null;
    63             }
    64         }
     97    private void AddError(string source, Exception ex) {
     98      MakeLog(new PeerInfo() { ProblemInstance = "ContactServer  Error at " + source }, ex.Message);
     99    }
    65100
    66         public void MakeLog(PeerInfo source, string msg)
    67         {
    68             try
    69             {
    70                 // TODO
    71                 lock (logLock)
    72                 {
    73                     File.AppendAllText("Log.txt", string.Concat(source.IpAddress, ":", source.Port, ",", source.ProblemInstance, ",", msg, Environment.NewLine));
    74                 }
    75             }
    76             catch (Exception ex)
    77             {
    78                 //Nothing to do because maybe called from adderror
    79             }
    80         }
    81 
    82         public void UpdateHeartbeat(PeerInfo source)
    83         {
    84             try
    85             {
    86                 Console.WriteLine("hb from {0}:{1}", source.IpAddress, source.Port);
    87                 DateTime now = DateTime.Now;
    88                 allPeers.AddOrUpdate(source, now, (k, v) => v = now);
    89             }
    90             catch (Exception ex)
    91             {
    92                 AddError("ContactServiceImpl.UpdateHeartbeat", ex);
    93             }
    94         }
    95 
    96         private void CleanUpContactTable(object sender, ElapsedEventArgs e)
    97         {
    98             DateTime deadline = DateTime.Now;
    99             //collect items to remove
    100             List<PeerInfo> itemsToDelete = new List<PeerInfo>();
    101             foreach (PeerInfo pi in allPeers.Keys)
    102             {
    103                 DateTime tmp;
    104                 if (allPeers.TryGetValue(pi, out tmp))
    105                 {
    106                     //if (tmp.AddHours(1f) < deadline)
    107                     if (tmp.AddMinutes(1) < deadline)  //TODO
    108                     {
    109                         //if (tmp < deadline.AddHours(1f)) {
    110                         itemsToDelete.Add(pi);
    111                     }
    112                 }
    113             }
    114             //remove items
    115             foreach (PeerInfo pi in itemsToDelete)
    116             {
    117                 DateTime tmp;
    118                 allPeers.TryRemove(pi, out tmp);
    119             }
    120         }
    121 
    122         private void AddError(string source, Exception ex)
    123         {
    124             MakeLog(new PeerInfo() { ProblemInstance = "ContactServer  Error at " + source }, ex.Message);
    125         }
    126 
    127     }
     101  }
    128102}
  • branches/thasling/DistributedGA/DistributedGA.Hive/DistributedGA.Hive.csproj

    r13903 r13905  
    1818    <DebugType>full</DebugType>
    1919    <Optimize>false</Optimize>
    20     <OutputPath>..\..\..\stable\bin\</OutputPath>
     20    <OutputPath>..\..\..\..\stable\bin\</OutputPath>
    2121    <DefineConstants>DEBUG;TRACE</DefineConstants>
    2222    <ErrorReport>prompt</ErrorReport>
     
    2727    <DebugType>pdbonly</DebugType>
    2828    <Optimize>true</Optimize>
    29     <OutputPath>bin\Release\</OutputPath>
     29    <OutputPath>..\..\..\..\stable\bin\</OutputPath>
    3030    <DefineConstants>TRACE</DefineConstants>
    3131    <ErrorReport>prompt</ErrorReport>
     
    4343  <ItemGroup>
    4444    <Reference Include="HeuristicLab.Clients.Hive-3.3">
    45       <HintPath>..\..\..\..\HeuristicLab\HeuristicLab 3.3.13\HeuristicLab.Clients.Hive-3.3.dll</HintPath>
     45      <HintPath>..\..\..\stable\bin\HeuristicLab.Clients.Hive-3.3.dll</HintPath>
    4646      <Private>False</Private>
    4747    </Reference>
    4848    <Reference Include="HeuristicLab.Collections-3.3">
    49       <HintPath>..\..\..\..\HeuristicLab\HeuristicLab 3.3.13\HeuristicLab.Collections-3.3.dll</HintPath>
     49      <HintPath>..\..\..\..\stable\bin\HeuristicLab.Collections-3.3.dll</HintPath>
    5050      <Private>False</Private>
    5151    </Reference>
    5252    <Reference Include="HeuristicLab.Common-3.3">
    53       <HintPath>..\..\..\..\HeuristicLab\HeuristicLab 3.3.13\HeuristicLab.Common-3.3.dll</HintPath>
    54       <Private>False</Private>
     53      <HintPath>..\..\..\..\stable\bin\HeuristicLab.Common-3.3.dll</HintPath>
    5554    </Reference>
    5655    <Reference Include="HeuristicLab.Core-3.3">
    57       <HintPath>..\..\..\..\HeuristicLab\HeuristicLab 3.3.13\HeuristicLab.Core-3.3.dll</HintPath>
     56      <HintPath>..\..\..\..\stable\bin\HeuristicLab.Core-3.3.dll</HintPath>
    5857      <Private>False</Private>
    5958    </Reference>
    6059    <Reference Include="HeuristicLab.Data-3.3">
    61       <HintPath>..\..\..\..\HeuristicLab\HeuristicLab 3.3.13\HeuristicLab.Data-3.3.dll</HintPath>
     60      <HintPath>..\..\..\..\stable\bin\HeuristicLab.Data-3.3.dll</HintPath>
    6261      <Private>False</Private>
    6362    </Reference>
    6463    <Reference Include="HeuristicLab.Hive-3.3">
    65       <HintPath>..\..\..\..\HeuristicLab\HeuristicLab 3.3.13\HeuristicLab.Hive-3.3.dll</HintPath>
     64      <HintPath>..\..\..\..\stable\bin\HeuristicLab.Hive-3.3.dll</HintPath>
    6665      <Private>False</Private>
    6766    </Reference>
     67    <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     68      <SpecificVersion>False</SpecificVersion>
     69      <HintPath>..\..\..\..\stable\bin\HeuristicLab.Operators-3.3.dll</HintPath>
     70    </Reference>
    6871    <Reference Include="HeuristicLab.Optimization-3.3">
    69       <HintPath>..\..\..\..\HeuristicLab\HeuristicLab 3.3.13\HeuristicLab.Optimization-3.3.dll</HintPath>
     72      <HintPath>..\..\..\..\stable\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
    7073      <Private>False</Private>
    7174    </Reference>
    7275    <Reference Include="HeuristicLab.Parameters-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    7376      <SpecificVersion>False</SpecificVersion>
    74       <HintPath>..\..\..\..\HeuristicLab\HeuristicLab 3.3.13\HeuristicLab.Parameters-3.3.dll</HintPath>
     77      <HintPath>..\..\..\..\stable\bin\HeuristicLab.Parameters-3.3.dll</HintPath>
    7578      <Private>False</Private>
    7679    </Reference>
    7780    <Reference Include="HeuristicLab.Persistence-3.3">
    78       <HintPath>..\..\..\..\HeuristicLab\HeuristicLab 3.3.13\HeuristicLab.Persistence-3.3.dll</HintPath>
     81      <HintPath>..\..\..\..\stable\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
    7982      <Private>False</Private>
    8083    </Reference>
    8184    <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
    82       <HintPath>..\..\..\..\HeuristicLab\HeuristicLab 3.3.13\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     85      <HintPath>..\..\..\..\stable\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
    8386      <Private>False</Private>
    8487    </Reference>
     
    97100    <Compile Include="Plugin.cs" />
    98101    <Compile Include="Properties\AssemblyInfo.cs" />
     102    <Compile Include="P2PMigrationAnalyzer.cs" />
    99103  </ItemGroup>
    100104  <ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.