Changeset 1376 for trunk/sources
- Timestamp:
- 03/20/09 13:23:54 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Hive.Server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Server/HiveServerApplication.cs
r1165 r1376 35 35 Description = "Server application for the distributed hive engine.", 36 36 AutoRestart = true)] 37 class HiveServerApplication : ApplicationBase { 38 const int port = 39 9000; 37 public class HiveServerApplication : ApplicationBase { 38 private const int DEFAULT_PORT = 9000; 39 public const string STR_ClientCommunicator = "ClientCommunicator"; 40 public const string STR_ServerConsoleFacade = "ServerConsoleFacade"; 41 public const string STR_ExecutionEngineFacade = "ExecutionEngineFacade"; 40 42 41 DiscoveryService discService = 42 new DiscoveryService(); 43 private DiscoveryService discService = new DiscoveryService(); 44 private Dictionary<string, ServiceHost> runningServices = new Dictionary<string, ServiceHost>(); 45 private NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, true); 46 //private WSHttpBinding binding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential, true); 43 47 48 private enum Services { 49 ClientCommunicator, 50 ServerConsoleFacade, 51 ExecutionEngineFacade, 52 All 53 } 54 44 55 private bool AddMexEndpoint(ServiceHost serviceHost) { 45 56 if (serviceHost != null) { 46 ServiceMetadataBehavior behavior = 47 new ServiceMetadataBehavior(); 57 ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); 48 58 serviceHost.Description.Behaviors.Add(behavior); 49 59 … … 56 66 } 57 67 58 private ServiceHost StartClientCommunicator(Uri uriTcp) { 59 IClientFacade[] clientCommunicatorInstances = 60 discService.GetInstances<IClientFacade>(); 61 62 if (clientCommunicatorInstances.Length > 0) { 63 ServiceHost serviceHost = 64 new ServiceHost(clientCommunicatorInstances[0].GetType(), 65 uriTcp); 66 67 System.ServiceModel.Channels.Binding binding = 68 new NetTcpBinding(); 69 70 serviceHost.AddServiceEndpoint( 71 typeof(IClientCommunicator), 72 binding, 73 "ClientCommunicator"); 74 68 private Uri StartService(Services svc, IPAddress ipAddress, int port) { 69 string curServiceHost = ""; 70 Uri uriTcp; 71 IClientFacade[] clientCommunicatorInstances = discService.GetInstances<IClientFacade>(); 72 IServerConsoleFacade[] serverConsoleInstances = discService.GetInstances<IServerConsoleFacade>(); 73 IExecutionEngineFacade[] executionEngineInstances = discService.GetInstances<IExecutionEngineFacade>(); 74 ServiceHost serviceHost = null; 75 switch (svc) { 76 case Services.ClientCommunicator: 77 if (clientCommunicatorInstances.Length > 0) { 78 uriTcp = new Uri("net.tcp://" + ipAddress + ":" + port + "/HiveServer/"); 79 serviceHost = new ServiceHost(clientCommunicatorInstances[0].GetType(), uriTcp); 80 serviceHost.AddServiceEndpoint(typeof(IClientCommunicator), binding, STR_ClientCommunicator); 81 curServiceHost = STR_ClientCommunicator; 82 } 83 break; 84 case Services.ServerConsoleFacade: 85 if (serverConsoleInstances.Length > 0) { 86 uriTcp = new Uri("net.tcp://" + ipAddress + ":" + port + "/HiveServerConsole/"); 87 serviceHost = new ServiceHost(serverConsoleInstances[0].GetType(), uriTcp); 88 serviceHost.AddServiceEndpoint(typeof(IServerConsoleFacade), binding, STR_ServerConsoleFacade); 89 curServiceHost = STR_ServerConsoleFacade; 90 } 91 break; 92 case Services.ExecutionEngineFacade: 93 if (executionEngineInstances.Length > 0) { 94 uriTcp = new Uri("net.tcp://" + ipAddress + ":" + port + "/ExecutionEngine/"); 95 serviceHost = new ServiceHost(executionEngineInstances[0].GetType(), uriTcp); 96 serviceHost.AddServiceEndpoint(typeof(IExecutionEngineFacade), binding, STR_ExecutionEngineFacade); 97 curServiceHost = STR_ExecutionEngineFacade; 98 } 99 break; 100 case Services.All: 101 throw new InvalidOperationException("Not supported!"); 102 default: 103 return null; 104 } 105 if ((serviceHost != null) && (!String.IsNullOrEmpty(curServiceHost))) { 75 106 AddMexEndpoint(serviceHost); 76 77 107 serviceHost.Open(); 78 79 return serviceHost ;108 runningServices.Add(curServiceHost, serviceHost); 109 return serviceHost.BaseAddresses[0]; 80 110 } else 81 111 return null; 82 112 } 83 113 84 private ServiceHost StartServerConsoleFacade(Uri uriTcp) { 85 IServerConsoleFacade[] serverConsoleInstances = 86 discService.GetInstances<IServerConsoleFacade>(); 87 88 if (serverConsoleInstances.Length > 0) { 89 ServiceHost serviceHost = 90 new ServiceHost(serverConsoleInstances[0].GetType(), 91 uriTcp); 92 93 System.ServiceModel.Channels.Binding binding = 94 new NetTcpBinding(); 95 96 serviceHost.AddServiceEndpoint( 97 typeof(IServerConsoleFacade), 98 binding, 99 "ServerConsoleFacade"); 100 101 AddMexEndpoint(serviceHost); 102 103 serviceHost.Open(); 104 105 return serviceHost; 106 } else 107 return null; 108 } 109 110 private ServiceHost StartExecutionEngineFacade(Uri uriTcp) { 111 IExecutionEngineFacade[] serverConsoleInstances = 112 discService.GetInstances<IExecutionEngineFacade>(); 113 114 if (serverConsoleInstances.Length > 0) { 115 ServiceHost serviceHost = 116 new ServiceHost(serverConsoleInstances[0].GetType(), 117 uriTcp); 118 119 System.ServiceModel.Channels.Binding binding = 120 new NetTcpBinding(); 121 122 serviceHost.AddServiceEndpoint( 123 typeof(IExecutionEngineFacade), 124 binding, 125 "ExecutionEngineFacade"); 126 127 AddMexEndpoint(serviceHost); 128 129 serviceHost.Open(); 130 131 return serviceHost; 132 } else 133 return null; 114 private void StopService(Services svc) { 115 ServiceHost svcHost = null; 116 switch (svc) { 117 case Services.ClientCommunicator: 118 runningServices.TryGetValue(STR_ClientCommunicator, out svcHost); 119 break; 120 case Services.ServerConsoleFacade: 121 runningServices.TryGetValue(STR_ServerConsoleFacade, out svcHost); 122 break; 123 case Services.ExecutionEngineFacade: 124 runningServices.TryGetValue(STR_ExecutionEngineFacade, out svcHost); 125 break; 126 case Services.All: 127 foreach (KeyValuePair<string, ServiceHost> item in runningServices) 128 item.Value.Close(); 129 return; 130 default: 131 throw new InvalidOperationException("Not supported!"); 132 } 133 svcHost.Close(); 134 134 } 135 135 … … 142 142 break; 143 143 } 144 145 //Start services and record their base address 146 Dictionary<string, Uri> baseAddrDict = new Dictionary<string, Uri>(); 147 baseAddrDict.Add(STR_ClientCommunicator, 148 StartService(Services.ClientCommunicator, addresses[index], DEFAULT_PORT)); 149 baseAddrDict.Add(STR_ServerConsoleFacade, 150 StartService(Services.ServerConsoleFacade, addresses[index], DEFAULT_PORT)); 151 baseAddrDict.Add(STR_ExecutionEngineFacade, 152 StartService(Services.ExecutionEngineFacade, addresses[index], DEFAULT_PORT)); 144 153 145 Uri uriTcp = 146 new Uri("net.tcp://" + addresses[index] + ":" + port + "/HiveServer/"); 147 148 ServiceHost clientCommunicator = 149 StartClientCommunicator(uriTcp); 150 151 uriTcp = 152 new Uri("net.tcp://" + addresses[index] + ":" + port + "/HiveServerConsole/"); 153 154 ServiceHost serverConsoleFacade = 155 StartServerConsoleFacade(uriTcp); 156 157 uriTcp = 158 new Uri("net.tcp://" + addresses[index] + ":" + port + "/ExecutionEngine/"); 159 160 ServiceHost executionEngineFacade = 161 StartExecutionEngineFacade(uriTcp); 162 163 ILifecycleManager[] lifecycleManagers = 164 discService.GetInstances<ILifecycleManager>(); 165 154 ILifecycleManager[] lifecycleManagers = discService.GetInstances<ILifecycleManager>(); 166 155 if (lifecycleManagers.Length > 0) { 167 ILifecycleManager lifecycleManager = 156 ILifecycleManager lifecycleManager = 168 157 lifecycleManagers[0]; 169 158 … … 173 162 new TimeSpan(0, 0, 30)); 174 163 175 Form mainForm = new MainForm(clientCommunicator.BaseAddresses[0], 176 serverConsoleFacade.BaseAddresses[0], 177 executionEngineFacade.BaseAddresses[0]); 164 Form mainForm = new MainForm(baseAddrDict); 178 165 179 166 Application.Run(mainForm); 180 167 181 168 lifecycleManager.Shutdown(); 182 169 } 183 184 clientCommunicator.Close(); 185 serverConsoleFacade.Close(); 186 executionEngineFacade.Close(); 170 StopService(Services.All); 187 171 } 188 172 } -
trunk/sources/HeuristicLab.Hive.Server/MainForm.cs
r1120 r1376 11 11 { 12 12 public partial class MainForm : Form { 13 public MainForm( Uri address1, Uri address2, Uri address3) {13 public MainForm(Dictionary<string, Uri> addresses) { 14 14 InitializeComponent(); 15 if(address1 != null) 16 this.lblAddress1.Text = address1.ToString(); 17 if (address2 != null) 18 this.lblAddress2.Text = address2.ToString(); 19 if (address3 != null) 20 this.lblAddress3.Text = address3.ToString(); 15 Uri uri; 16 addresses.TryGetValue(HiveServerApplication.STR_ClientCommunicator, out uri); 17 if(uri!=null) 18 this.lblAddress1.Text = uri.ToString(); 19 addresses.TryGetValue(HiveServerApplication.STR_ServerConsoleFacade, out uri); 20 if (uri != null) 21 this.lblAddress2.Text = uri.ToString(); 22 addresses.TryGetValue(HiveServerApplication.STR_ExecutionEngineFacade, out uri); 23 if (uri != null) 24 this.lblAddress3.Text = uri.ToString(); 21 25 } 22 26
Note: See TracChangeset
for help on using the changeset viewer.