Ejemplo n.º 1
0
        /// <inheritdoc />
        public long RegisterPartitionChangeHandler(
            Uri serviceName,
            IResolvedServicePartition servicePartition,
            FabricPartitionResolutionChangeHandler handler)
        {
            var partition = servicePartition as ResolvedServicePartitionWrapper;

            if (partition == null)
            {
                throw new ArgumentException(
                          string.Format(
                              "Only partitions of type {0} are supported. Provided type {1} is not supported.",
                              nameof(ResolvedServicePartitionWrapper),
                              servicePartition.GetType()),
                          nameof(servicePartition));
            }

            // Wrap the provided handler so that it's compatible with Service Fabric.
            ServicePartitionResolutionChangeHandler actualHandler = (source, id, args) =>
            {
                ServicePartitionSilos result = null;
                if (!args.HasException)
                {
                    result = new ServicePartitionSilos(
                        new ResolvedServicePartitionWrapper(args.Result),
                        args.Result.GetPartitionEndpoints());
                }

                handler(
                    id,
                    new FabricPartitionResolutionChange(result, args.Exception));
            };

            var sm = this.fabricClient.ServiceManager;

            switch (servicePartition.Kind)
            {
            case ServicePartitionKind.Int64Range:
                return(sm.RegisterServicePartitionResolutionChangeHandler(
                           serviceName,
                           ((Int64RangePartitionInformation)partition.Partition.Info).LowKey,
                           actualHandler));

            case ServicePartitionKind.Named:
                return(sm.RegisterServicePartitionResolutionChangeHandler(
                           serviceName,
                           ((NamedPartitionInformation)partition.Partition.Info).Name,
                           actualHandler));

            case ServicePartitionKind.Singleton:
                return(sm.RegisterServicePartitionResolutionChangeHandler(serviceName, actualHandler));

            default:
                throw new ArgumentOutOfRangeException(
                          nameof(servicePartition),
                          $"Partition kind {servicePartition.Kind} is not supported");
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FabricServiceSiloResolver"/> class.
 /// </summary>
 /// <param name="serviceName">The name of the Service Fabric service which this instance will resolve.</param>
 /// <param name="queryManager">The fabric query manager.</param>
 /// <param name="loggerFactory">The logger factory.</param>
 public FabricServiceSiloResolver(
     Uri serviceName,
     IFabricQueryManager queryManager,
     Factory <string, Logger> loggerFactory)
 {
     this.serviceName            = serviceName;
     this.queryManager           = queryManager;
     this.log                    = loggerFactory(nameof(FabricServiceSiloResolver));
     this.partitionChangeHandler = this.OnPartitionChange;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FabricServiceSiloResolver"/> class.
 /// </summary>
 /// <param name="serviceName">The name of the Service Fabric service which this instance will resolve.</param>
 /// <param name="queryManager">The fabric query manager.</param>
 /// <param name="logger">The logger.</param>
 public FabricServiceSiloResolver(
     Uri serviceName,
     IFabricQueryManager queryManager,
     ILogger <FabricServiceSiloResolver> logger)
 {
     this.serviceName            = serviceName;
     this.queryManager           = queryManager;
     this.log                    = logger;
     this.partitionChangeHandler = this.OnPartitionChange;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FabricServiceSiloResolver"/> class.
 /// </summary>
 /// <param name="serviceName">The name of the Service Fabric service which this instance will resolve.</param>
 /// <param name="queryManager">The fabric query manager.</param>
 /// <param name="loggerFactory">The logger factory.</param>
 public FabricServiceSiloResolver(
     Uri serviceName,
     IFabricQueryManager queryManager,
     ILoggerFactory loggerFactory)
 {
     this.serviceName            = serviceName;
     this.queryManager           = queryManager;
     this.log                    = new LoggerWrapper <FabricServiceSiloResolver>(loggerFactory);
     this.partitionChangeHandler = this.OnPartitionChange;
 }