source: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Server.cs @ 1060

Last change on this file since 1060 was 1060, checked in by gkronber, 13 years ago

worked on executer which retrieves the next job from the dispatcher and sends it to the grid for execution. #419 (Refactor CEDMA plugins)

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Windows.Forms;
26using HeuristicLab.PluginInfrastructure;
27using System.Net;
28using System.ServiceModel;
29using HeuristicLab.CEDMA.DB.Interfaces;
30using HeuristicLab.CEDMA.DB;
31using System.ServiceModel.Description;
32
33namespace HeuristicLab.CEDMA.Server {
34  public class Server {
35    private ServiceHost host;
36    private IStore store;
37
38    private string gridServiceUrl;
39
40    public string GridServiceUrl {
41      get { return gridServiceUrl; }
42      set { gridServiceUrl = value; }
43    }
44
45    private string cedmaServiceUrl;
46
47    public string CedmaServiceUrl {
48      get { return cedmaServiceUrl; }
49      set { cedmaServiceUrl = value; }
50    }
51
52    public Server(IStore store) {
53      IPAddress[] addresses = Dns.GetHostAddresses(Dns.GetHostName());
54      // windows XP returns the external ip on index 0 while windows vista returns the external ip as one of the last entries
55      // also if IPv6 protocol is installed we want to find an entry that is IPv4
56      int index = 0;
57      if (System.Environment.OSVersion.Version.Major >= 6) {
58        for (index = addresses.Length - 1; index >= 0; index--)
59          if (addresses[index].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
60            break;
61      }
62      cedmaServiceUrl = "net.tcp://" + addresses[index] + ":8002/CEDMA";
63      this.store = store;
64    }
65
66    public void Start() {
67      host = new ServiceHost(store, new Uri(cedmaServiceUrl));
68      ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior();
69      throttlingBehavior.MaxConcurrentSessions = 20;
70      host.Description.Behaviors.Add(throttlingBehavior);
71      try {
72        NetTcpBinding binding = new NetTcpBinding();
73        binding.MaxReceivedMessageSize = 100000000; // 100Mbytes
74        binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars
75        binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements;
76        binding.Security.Mode = SecurityMode.None;
77
78        host.AddServiceEndpoint(typeof(IStore), binding, cedmaServiceUrl);
79        host.Open();
80      }
81      catch (CommunicationException ex) {
82        MessageBox.Show("An exception occurred: " + ex.Message);
83        host.Abort();
84      }
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.