Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/23/10 13:07:11 (14 years ago)
Author:
cneumuel
Message:
  • changed Hive.Server WCF services to be configurable in app.config
  • changed endpoints to wsHttpBinding
  • changed project type of Hive.Server.Core to WCF Service Library, so that it can be started directly to be able to test the service (and update references) (#1159)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server/3.3/HeuristicLabHiveServerApplication.cs

    r4267 r4285  
    3535  [Application("Hive Server", "Server application for the distributed hive engine.", true)]
    3636  public class HeuristicLabHiveServerApplication : ApplicationBase {
    37     public const string STR_SlaveCommunicator = "SlaveCommunicator";
     37    public const string STR_SlaveCommunicator = "HiveServer";
    3838    public const string STR_ServerConsoleFacade = "ServerConsoleFacade";
    3939    public const string STR_ExecutionEngineFacade = "ExecutionEngineFacade";
    40 
    41     private Dictionary<string, ServiceHost> runningServices = new Dictionary<string, ServiceHost>();
    42     private NetTcpBinding binding = (NetTcpBinding)WcfSettings.GetBinding();
    43     private NetTcpBinding streamedBinding = (NetTcpBinding)WcfSettings.GetStreamedBinding();
    44 
    45     private enum Services {
    46       SlaveCommunicator,
    47       ServerConsoleFacade,
    48       ExecutionEngineFacade,
    49       All
    50     }
    51 
    52     private bool AddMexEndpoint(ServiceHost serviceHost) {
    53       if (serviceHost != null) {
    54         ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
    55         serviceHost.Description.Behaviors.Add(behavior);
    56 
    57         return serviceHost.AddServiceEndpoint(
    58           typeof(IMetadataExchange),
    59           MetadataExchangeBindings.CreateMexTcpBinding(),
    60           "mex") != null;
    61       } else
    62         return false;
    63     }
    64 
    65     private Uri StartService(Services svc, IPAddress ipAddress, int port) {
    66       string curServiceHost = "";
    67       Uri uriTcp;
    68       ISlaveFacade clientCommunicatorInstance = ApplicationManager.Manager.GetInstances<ISlaveFacade>().First();
    69       IServerConsoleFacade serverConsoleInstance = ApplicationManager.Manager.GetInstances<IServerConsoleFacade>().First();
    70       IExecutionEngineFacade executionEngineInstance = ApplicationManager.Manager.GetInstances<IExecutionEngineFacade>().First();
    71       //SpringServiceHost serviceHost = null;
    72       ServiceHost serviceHost = null;
    73 
    74       switch (svc) {
    75         case Services.SlaveCommunicator:
    76           //  if (clientCommunicatorInstances.Count() > 0) {
    77           uriTcp = new Uri("net.tcp://" + ipAddress + ":" + port + "/HiveServer/");
    78           serviceHost = new ServiceHost(clientCommunicatorInstance.GetType(), uriTcp);
    79           //serviceHost = new ServiceHost(typeof(SlaveFacade), uriTcp);
    80           //serviceHost = new SpringServiceHost("clientFacade", uriTcp);
    81           serviceHost.AddServiceEndpoint(typeof(ISlaveFacade), streamedBinding, STR_SlaveCommunicator);
    82 
    83           ServiceDebugBehavior sdb = serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>();
    84           if (sdb == null) {
    85             sdb = new ServiceDebugBehavior();
    86             serviceHost.Description.Behaviors.Add(sdb);
    87           }
    88           sdb.IncludeExceptionDetailInFaults = true;
    89 
    90 
    91 
    92           curServiceHost = STR_SlaveCommunicator;
    93           //  }
    94           break;
    95         case Services.ServerConsoleFacade:
    96           //  if (serverConsoleInstances.Count() > 0) {
    97           uriTcp = new Uri("net.tcp://" + ipAddress + ":" + port + "/HiveServerConsole/");
    98           serviceHost = new ServiceHost(serverConsoleInstance.GetType(), uriTcp);
    99           //serviceHost = new SpringServiceHost("serverConsoleFacade", uriTcp);
    100           serviceHost.AddServiceEndpoint(typeof(IServerConsoleFacade), binding, STR_ServerConsoleFacade);
    101           curServiceHost = STR_ServerConsoleFacade;
    102           //  }
    103           break;
    104         case Services.ExecutionEngineFacade:
    105           //  if (executionEngineInstances.Count() > 0) {
    106           uriTcp = new Uri("net.tcp://" + ipAddress + ":" + port + "/ExecutionEngine/");
    107           serviceHost = new ServiceHost(executionEngineInstance.GetType(), uriTcp);
    108           //serviceHost = new SpringServiceHost("executionEngineFacade", uriTcp);
    109           serviceHost.AddServiceEndpoint(typeof(IExecutionEngineFacade), streamedBinding, STR_ExecutionEngineFacade);
    110           curServiceHost = STR_ExecutionEngineFacade;
    111           //  }
    112           break;
    113         case Services.All:
    114           throw new InvalidOperationException("Not supported!");
    115         default:
    116           return null;
    117       }
    118       if (!String.IsNullOrEmpty(curServiceHost)) {
    119         AddMexEndpoint(serviceHost);
    120         //WcfSettings.SetServiceCertificate(serviceHost);
    121         serviceHost.Open();
    122         runningServices.Add(curServiceHost, serviceHost);
    123         return serviceHost.BaseAddresses[0];
    124       } else
    125         return null;
    126     }
    127 
    128     private void StopService(Services svc) {
    129       ServiceHost svcHost = null;
    130       switch (svc) {
    131         case Services.SlaveCommunicator:
    132           runningServices.TryGetValue(STR_SlaveCommunicator, out svcHost);
    133           break;
    134         case Services.ServerConsoleFacade:
    135           runningServices.TryGetValue(STR_ServerConsoleFacade, out svcHost);
    136           break;
    137         case Services.ExecutionEngineFacade:
    138           runningServices.TryGetValue(STR_ExecutionEngineFacade, out svcHost);
    139           break;
    140         case Services.All:
    141           foreach (KeyValuePair<string, ServiceHost> item in runningServices)
    142             item.Value.Close();
    143           return;
    144         default:
    145           throw new InvalidOperationException("Not supported!");
    146       }
    147       svcHost.Close();
    148     }
     40    Dictionary<string, Uri> baseAddrDict = new Dictionary<string, Uri>();
    14941
    15042    public override void Run() {
    151       IPAddress[] addresses = Dns.GetHostAddresses(Dns.GetHostName());
    152       int index = 0;
    153       if (System.Environment.OSVersion.Version.Major >= 6) {
    154         for (index = addresses.Length - 1; index >= 0; index--)
    155           if (addresses[index].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
    156             break;
    157       }
     43      ServiceHost slaveHost = new ServiceHost(ApplicationManager.Manager.GetTypes(typeof(ISlaveFacade)).First(), GetUri(STR_SlaveCommunicator));
     44      slaveHost.Open();
    15845
    159       //Start services and record their base address
    160       Dictionary<string, Uri> baseAddrDict = new Dictionary<string, Uri>();
    161       baseAddrDict.Add(STR_SlaveCommunicator, StartService(Services.SlaveCommunicator, addresses[index], WcfSettings.DEFAULTPORT));
    162       baseAddrDict.Add(STR_ServerConsoleFacade, StartService(Services.ServerConsoleFacade, addresses[index], WcfSettings.DEFAULTPORT));
    163       baseAddrDict.Add(STR_ExecutionEngineFacade, StartService(Services.ExecutionEngineFacade, addresses[index], WcfSettings.DEFAULTPORT));
     46      ServiceHost serverConsoleHost = new ServiceHost(ApplicationManager.Manager.GetTypes(typeof(IServerConsoleFacade)).First(), GetUri(STR_ServerConsoleFacade));
     47      serverConsoleHost.Open();
     48
     49      ServiceHost executionEngineHost = new ServiceHost(ApplicationManager.Manager.GetTypes(typeof(IExecutionEngineFacade)).First(), GetUri(STR_ExecutionEngineFacade));
     50      executionEngineHost.Open();
    16451
    16552      ILifecycleManager lifecycleManager = ServiceLocator.GetLifecycleManager();
    166 
    16753      lifecycleManager.Init();
    16854
     
    17056      Application.Run();
    17157
     58      slaveHost.Close();
     59      serverConsoleHost.Close();
     60      executionEngineHost.Close();
     61
    17262      lifecycleManager.Shutdown();
    173      
    174       StopService(Services.All);
    17563    }
     64
     65    private Uri GetUri(string serviceName) {
     66      string ipAddress = WcfSettings.GetActiveIP().ToString();
     67      string port = WcfSettings.DEFAULTPORT.ToString();
     68      Uri uriHttp = new Uri("http://" + ipAddress + ":" + port + "/" + serviceName + "/");
     69      baseAddrDict.Add(serviceName, uriHttp);
     70      return uriHttp;
     71    }
     72
    17673  }
    17774}
Note: See TracChangeset for help on using the changeset viewer.