Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Server/3.3/Server.cs @ 2075

Last change on this file since 2075 was 2075, checked in by gkronber, 15 years ago

Fixed a bug which prevented that more than 10 jobs are dispatched concurrently. #642

File size: 4.4 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;
32using HeuristicLab.Grid;
33using HeuristicLab.Grid.HiveBridge;
34
35namespace HeuristicLab.CEDMA.Server {
36  public class Server {
37    private static readonly string rdfFile = AppDomain.CurrentDomain.BaseDirectory + "rdf_store.db3";
38    private static readonly string rdfConnectionString = "sqlite:rdf:Data Source=\"" + rdfFile + "\"";
39
40    private ServiceHost host;
41    private Store store;
42    private IDispatcher dispatcher;
43    private IExecuter executer;
44
45    private string gridServiceUrl;
46    public string GridServiceUrl {
47      get { return gridServiceUrl; }
48      set { gridServiceUrl = value; }
49    }
50
51    private string cedmaServiceUrl;
52    public string CedmaServiceUrl {
53      get { return cedmaServiceUrl; }
54      set { cedmaServiceUrl = value; }
55    }
56
57    private int maxActiveJobs;
58    public int MaxActiveJobs {
59      get { return maxActiveJobs; }
60      set {
61        if (value > 0) {
62          maxActiveJobs = value;
63          if (executer != null) {
64            executer.MaxActiveJobs = value;
65          }
66        }
67      }
68    }
69
70    public Server() {
71      IPAddress[] addresses = Dns.GetHostAddresses(Dns.GetHostName());
72      // windows XP returns the external ip on index 0 while windows vista returns the external ip as one of the last entries
73      // also if IPv6 protocol is installed we want to find an entry that is IPv4
74      int index = 0;
75      if (System.Environment.OSVersion.Version.Major >= 6) {
76        for (index = addresses.Length - 1; index >= 0; index--)
77          if (addresses[index].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
78            break;
79      }
80      cedmaServiceUrl = "net.tcp://" + addresses[index] + ":8002/CEDMA";
81      store = new Store(rdfConnectionString);
82      maxActiveJobs = 10;
83    }
84
85    public void Start() {
86      host = new ServiceHost(store, new Uri(cedmaServiceUrl));
87      ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior();
88      throttlingBehavior.MaxConcurrentSessions = 20;
89      host.Description.Behaviors.Add(throttlingBehavior);
90      try {
91        NetTcpBinding binding = new NetTcpBinding();
92        binding.SendTimeout = new TimeSpan(10, 0, 0);
93        binding.MaxReceivedMessageSize = int.MaxValue;
94        binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
95        binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
96        host.AddServiceEndpoint(typeof(IStore), binding, cedmaServiceUrl);
97        host.Open();
98      }
99      catch (CommunicationException ex) {
100        MessageBox.Show("An exception occurred: " + ex.Message);
101        host.Abort();
102      }
103    }
104
105    internal string[] GetActiveJobDescriptions() {
106      if (executer != null) return executer.GetJobs();
107      else return new string[] { };
108    }
109
110    internal void Connect(string serverUrl) {
111      dispatcher = new SimpleDispatcher(store);
112      IGridServer gridServer = null;
113      if (serverUrl.Contains("ExecutionEngine")) {
114        gridServer = new HiveGridServerWrapper(serverUrl);
115      } else {
116        // default is grid backend
117        gridServer = new GridServerProxy(serverUrl);
118      }
119      executer = new GridExecuter(dispatcher, store, gridServer);
120      executer.MaxActiveJobs = MaxActiveJobs;
121      executer.Start();
122    }
123  }
124}
Note: See TracBrowser for help on using the repository browser.