Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone3/sources/HeuristicLab.CEDMA.Server/3.3/Server.cs @ 5143

Last change on this file since 5143 was 2094, checked in by gkronber, 16 years ago

Fixed updating of executer and dispatcher views and renamed ServerForm to ServerView. #676 (Cockpit for the CEDMA Server to control algorithm settings)

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