// placement
 IPlacementBuilder IPlacementBuilder.PlaceByJumpConsistentHash<TAffinity, TKey>()
 {
     if (!process.Affinities.TryGetValue(typeof(TAffinity), out var keyInfo))
     {
         throw new BuilderException($"undefined key {typeof(TAffinity).FullName}");
     }
     ((PartitionedAffinityInfo<TAffinity, TKey>)keyInfo).SetPlacementFunction(
         (Func<TKey, uint, uint>)
         KeyFunctions.GetJumpConsistentHashFor<TKey>(process.Serializer));
     return this;
 }
 IPlacementBuilder IPlacementBuilder.PlaceByIndex<TAffinity, TKey>(uint chunksize)
 {
     if (!process.Affinities.TryGetValue(typeof(TAffinity), out var keyInfo))
     {
         throw new BuilderException($"undefined key {typeof(TAffinity).FullName}");
     }
      ((PartitionedAffinityInfo<TAffinity, TKey>)keyInfo).SetPlacementFunction(
          (Func<TKey, uint, uint>)
          KeyFunctions.GetRoundRobinFor<TKey>(chunksize));
     return this;
 }
示例#3
0
        public PartitionedAffinityInfo(Process process) : base(process)
        {
            var properties = typeof(TAffinity).GetProperties();

            if (properties.Length != 1 ||
                properties[0].GetGetMethod().ReturnType != typeof(TKey))
            {
                throw new BuilderException($"invalid affinity {typeof(TAffinity).Name} : interface must define a single property of type {typeof(TKey).Name}");
            }
            var method = properties[0].GetGetMethod();

            RoundRobinAttribute = properties[0].GetCustomAttributes(typeof(RoundRobinPlacementAttribute), false).Count() > 0;
            Selector            = (x) => (TKey)method.Invoke(x, emptyArgs);
            Comparator          = (Func <TKey, TKey, int>)KeyFunctions.GetComparatorFor <TKey>();
        }