public ServicePerformanceCounterProvider(Guid partitionId, long replicaOrInstanceId, ServiceTypeInformation serviceTypeInformation) { this.partitionId = partitionId; this.serviceTypeInformation = serviceTypeInformation; var ticks = (long)((DateTime.UtcNow.Ticks) % Math.Pow(10, MaxDigits)); this.counterInstanceDifferentiator = String.Concat(replicaOrInstanceId, "_", ticks.ToString("D")); var serviceCounterInstanceName = String.Concat(this.partitionId.ToString("D"), "_", this.counterInstanceDifferentiator); try { //Create ServiceCounterSetInstance this.serviceCounterSetInstance = ServiceCounterSet.CreateCounterSetInstance(serviceCounterInstanceName); } catch (Exception ex) { //Instance creation failed, Be done. ServiceTrace.Source.WriteWarning(TraceType, "Data for performance counter instance {0} of categoryName {1} will not be provided because an exception occurred during its initialization. Exception info: {2}", serviceCounterInstanceName, ServiceRemotingPerformanceCounters.ServiceCategoryName, ex); return; } this.CreateserviceCounterWriters(serviceCounterInstanceName); this.InitializeServiceMethodInfo(); }
/// <summary> /// Instantiates the ServiceRemotingDispatcher that uses the given service context and /// dispatches messages to the given service implementation. /// </summary> /// <param name="serviceContext">Service context</param> /// <param name="service">Service implementation that implements interfaces of type <see cref="IService"/></param> public ServiceRemotingDispatcher(ServiceContext serviceContext, IService service) { Requires.ThrowIfNull(serviceContext, "serviceContext"); this.cancellationHelper = new ServiceRemotingCancellationHelper(serviceContext.TraceId); this.methodDispatcherMap = new Dictionary <int, ServiceMethodDispatcherBase>(); this.service = service; if (service != null) { var serviceTypeInformation = ServiceTypeInformation.Get(service.GetType()); List <ServiceInterfaceDescription> interfaceDescriptions = new List <ServiceInterfaceDescription>(); foreach (var interfaceType in serviceTypeInformation.InterfaceTypes) { var methodDispatcher = ServiceCodeBuilder.GetOrCreateMethodDispatcher(interfaceType); this.methodDispatcherMap.Add(methodDispatcher.InterfaceId, methodDispatcher); interfaceDescriptions.Add(ServiceInterfaceDescription.Create(interfaceType)); } this.servicePerformanceCounterProvider = new ServicePerformanceCounterProvider(serviceContext.PartitionId, serviceContext.ReplicaOrInstanceId, interfaceDescriptions); } }
public static IEnumerable <ServiceRequestHeader> GetServiceRequestHeader(ServiceContext serviceContext, IService service) { var types = ServiceTypeInformation.Get(service.GetType()).InterfaceTypes; if (types != null) { foreach (var type in types) { var customAttributes = type.Assembly.GetCustomAttributes <ServiceRequestHeaderAttribute>(); if (customAttributes != null) { foreach (var customAttribute in customAttributes) { yield return((ServiceRequestHeader)Activator.CreateInstance(customAttribute.HeaderType)); } } } } var entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly != (Assembly)null) { var customAttributes = entryAssembly.GetCustomAttributes <ServiceRequestHeaderAttribute>(); if (customAttributes != null) { foreach (var customAttribute in customAttributes) { yield return((ServiceRequestHeader)Activator.CreateInstance(customAttribute.HeaderType)); } } } }
/// <summary> /// Instantiates the ServiceRemotingDispatcher that uses the given service context and /// dispatches messages to the given service implementation. /// </summary> /// <param name="serviceContext">Service context</param> /// <param name="serviceImplementation">Service implementation that implements interfaces of type <see cref="IService"/></param> /// <param name="serviceRemotingMessageBodyFactory">This is the factory used by Dispatcher to create Remoting Response object</param> public ServiceRemotingMessageDispatcher(ServiceContext serviceContext, IService serviceImplementation, IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory = null) { var serviceTypeInformation = ServiceTypeInformation.Get(serviceImplementation.GetType()); this.Initialize(serviceContext, serviceImplementation, serviceTypeInformation.InterfaceTypes, false, serviceRemotingMessageBodyFactory); }
public static IServiceRemotingMessageHandler GetServiceRemotingDispatcher(ServiceContext serviceContext, IService service) { try { var types = ServiceTypeInformation.Get(service.GetType()).InterfaceTypes; if (types != null) { foreach (var type in types) { var customAttribute = type.Assembly.GetCustomAttribute <ServiceRemotingDispatcherAttribute>(); if (customAttribute != null) { return ((IServiceRemotingMessageHandler) Activator.CreateInstance(customAttribute.ServiceRemotingDispatcherType, new object[] { serviceContext, service })); } } } var entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly != (Assembly)null) { var customAttribute = entryAssembly.GetCustomAttribute <ServiceRemotingDispatcherAttribute>(); if (customAttribute != null) { return ((IServiceRemotingMessageHandler) Activator.CreateInstance(customAttribute.ServiceRemotingDispatcherType, new object[] { serviceContext, service })); } } } catch (Exception) { // Ignore // TODO: Should probably log this. } return(new ServiceRemotingDispatcher(service, new Microsoft.ServiceFabric.Services.Remoting.Runtime.ServiceRemotingDispatcher(serviceContext, service), null)); }