/// <summary> /// Starts the service hosts that are declaratively attached to the hosting worker role and the AutoStart attribute of which matches the specified value. /// </summary> /// <param name="autoStartOnly">A flag indicating whether to start only those service hosts that are marked with the AutoStart attribute.</param> public void StartAll(bool autoStartOnly) { var callToken = TraceManager.WorkerRoleComponent.TraceIn(autoStartOnly); var startScopeOpenServiceHosts = TraceManager.WorkerRoleComponent.TraceStartScope(TraceLogMessages.ScopeOpenServiceHosts, callToken); if (this.workerRole != null) { IRoleConfigurationSettingsExtension roleConfigExtension = this.workerRole.Extensions.Find <IRoleConfigurationSettingsExtension>(); if (roleConfigExtension != null) { foreach (var ep in serviceEndpoints.Values) { if (null == ep.ServiceHost) { TraceManager.WorkerRoleComponent.TraceInfo(TraceLogMessages.AboutToCreateServiceHost, ep.ServiceType.FullName, ep.EndpointInfo.Name, ep.EndpointInfo.ServiceNamespace, ep.EndpointInfo.ServicePath, ep.EndpointInfo.EndpointType); ep.ServiceHost = new ReliableServiceBusHost <object>(ServiceBusHostFactory.CreateServiceBusHost(ep.EndpointInfo, ep.ServiceType), roleConfigExtension.CommunicationRetryPolicy); } if (ep.ServiceHost != null && ep.ServiceHost.State != CommunicationState.Opened && (!autoStartOnly || ep.AutoStart)) { ep.ServiceHost.Open(); } } } } else { throw new CloudApplicationException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.CloudRoleExtensionNotAttached, this.GetType().Name)); } TraceManager.WorkerRoleComponent.TraceEndScope(TraceLogMessages.ScopeOpenServiceHosts, startScopeOpenServiceHosts, callToken); TraceManager.WorkerRoleComponent.TraceOut(callToken); }
private void ConfigureServiceHostWorkerRole(IExtensibleCloudServiceComponent ownerRole) { var callToken = TraceManager.WorkerRoleComponent.TraceIn(ownerRole != null ? ownerRole.GetType().FullName : null); var startScopeCreateServiceHosts = TraceManager.WorkerRoleComponent.TraceStartScope(TraceLogMessages.ScopeCreateServiceHosts, callToken); if (ownerRole != null) { IList <ServiceBusHostWorkerRoleAttribute> serviceHostAttributes = FrameworkUtility.GetDeclarativeAttributes <ServiceBusHostWorkerRoleAttribute>(ownerRole.GetType()); IRoleConfigurationSettingsExtension roleConfigExtension = ownerRole.Extensions.Find <IRoleConfigurationSettingsExtension>(); if (serviceHostAttributes != null && serviceHostAttributes.Count > 0 && roleConfigExtension != null) { ServiceBusEndpointInfo endpointInfo = null; ServiceBusListenerRegistration listenerInfo = null; foreach (ServiceBusHostWorkerRoleAttribute serviceHostAttr in serviceHostAttributes) { endpointInfo = roleConfigExtension.GetServiceBusEndpoint(serviceHostAttr.ServiceBusEndpoint); if (endpointInfo != null) { listenerInfo = new ServiceBusListenerRegistration() { ServiceType = serviceHostAttr.ServiceType, EndpointInfo = endpointInfo, AutoStart = serviceHostAttr.AutoStart }; // All services that are enabled for auto-start will have their service hosts pre-initialized but not as yet openned. if (listenerInfo.AutoStart) { TraceManager.WorkerRoleComponent.TraceInfo(TraceLogMessages.AboutToCreateServiceHost, listenerInfo.ServiceType.FullName, endpointInfo.Name, endpointInfo.ServiceNamespace, endpointInfo.ServicePath, endpointInfo.EndpointType); listenerInfo.ServiceHost = new ReliableServiceBusHost <object>(ServiceBusHostFactory.CreateServiceBusHost(endpointInfo, listenerInfo.ServiceType), roleConfigExtension.CommunicationRetryPolicy); } this.serviceEndpoints.Add(endpointInfo, listenerInfo); } else { throw new CloudApplicationException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.SpecifiedServiceBusEndpointNotFound, serviceHostAttr.ServiceBusEndpoint, ServiceBusConfigurationSettings.SectionName)); } } } } TraceManager.WorkerRoleComponent.TraceEndScope(TraceLogMessages.ScopeCreateServiceHosts, startScopeCreateServiceHosts, callToken); TraceManager.WorkerRoleComponent.TraceOut(callToken); }