public override void SetRoutees(HashSet <PID> routees) { _routeeMap = new Dictionary <string, PID>(); var nodes = new List <string>(); foreach (var pid in routees) { var nodeName = pid.ToShortString(); nodes.Add(nodeName); _routeeMap[nodeName] = pid; } _hashRing = new HashRing(nodes, _hash, _replicaCount); }
public override void SetRoutees(HashSet <PID> routees) { _routeeMap = new Dictionary <string, PID>(); var nodes = new List <string>(); foreach (var pid in routees) { var nodeName = pid.Address + "@" + pid.Id; nodes.Add(nodeName); _routeeMap[nodeName] = pid; } _hashRing = new HashRing(nodes); }
public HashRingBasedStreamQueueMapper(int nQueues, string queueNamePrefix) { numQueues = nQueues; var queueIds = new List<QueueId>(numQueues); if (nQueues == 1) { uint uniformHashCode = 0; queueIds.Add(QueueId.GetQueueId(queueNamePrefix, 0, uniformHashCode)); } else { uint portion = checked((uint)(RangeFactory.RING_SIZE / numQueues + 1)); for (uint i = 0; i < numQueues; i++) { uint uniformHashCode = checked(portion * i); queueIds.Add(QueueId.GetQueueId(queueNamePrefix, i, uniformHashCode)); } } this.hashRing = new HashRing<QueueId>(queueIds); }
public HashRingBasedStreamQueueMapper(int nQueues, string queueNamePrefix) { numQueues = nQueues; var queueIds = new List <QueueId>(numQueues); if (nQueues == 1) { uint uniformHashCode = 0; queueIds.Add(QueueId.GetQueueId(queueNamePrefix, 0, uniformHashCode)); } else { uint portion = checked ((uint)(RangeFactory.RING_SIZE / numQueues + 1)); for (uint i = 0; i < numQueues; i++) { uint uniformHashCode = checked (portion * i); queueIds.Add(QueueId.GetQueueId(queueNamePrefix, i, uniformHashCode)); } } this.hashRing = new HashRing <QueueId>(queueIds); }
/// <summary> /// Initializes a new instance of the <see cref="HashRingBasedStreamQueueMapper"/> class. /// </summary> /// <param name="options">The options.</param> /// <param name="queueNamePrefix">The queue name prefix.</param> public HashRingBasedStreamQueueMapper(HashRingStreamQueueMapperOptions options, string queueNamePrefix) { var numQueues = options.TotalQueueCount; var queueIds = new QueueId[numQueues]; if (numQueues == 1) { queueIds[0] = QueueId.GetQueueId(queueNamePrefix, 0, 0); } else { uint portion = checked ((uint)(RangeFactory.RING_SIZE / numQueues + 1)); for (uint i = 0; i < numQueues; i++) { uint uniformHashCode = checked (portion * i); queueIds[i] = QueueId.GetQueueId(queueNamePrefix, i, uniformHashCode); } } this.hashRing = new HashRing <QueueId>(queueIds); }
static void Main(string[] args) { Console.WriteLine("Consistent Hash Ring Test"); // Make location keys for the ring string[] locationKeys = { "A", "B", "C", "D" }; // Instantiate the HashRing HashRing <string> hashRing = new HashRing <string>(); hashRing.RingLocationReceived += new HashRing <string> .RingLocationReceivedItemDelegate((key, item) => { Console.WriteLine($"Received on {key}: {item}"); }); // Add the location keys for (var i = 0; i < locationKeys.Length; i++) { var location = hashRing.AddLocation(locationKeys[i]); } Console.WriteLine($"Locations in the HashRing {hashRing.LocationCount}"); // Now add items to the Ring and display the location counts while (true) { Console.WriteLine("Enter some text (empty line quits)"); var someText = Console.ReadLine(); if (someText == string.Empty) { break; } hashRing.AddItem(someText); Console.WriteLine(); } Console.WriteLine("Press any key to quit"); Console.ReadKey(); }
public void GettingStartedSample() { var hashRing = new HashRing <string>(); hashRing.AddNode("a", 100); hashRing.AddNode("b", 200); hashRing.AddNode("a", 250); hashRing.AddNode("c", 300); Assert.Equal("a", hashRing.GetNode(0)); Assert.Equal("a", hashRing.GetNode(100)); Assert.Equal("a", hashRing.GetNode(500)); Assert.Equal("b", hashRing.GetNode(200)); Assert.Equal("a", hashRing.GetNode(225)); Assert.Equal("c", hashRing.GetNode(300)); Assert.Equal("a", hashRing.GetNode(400)); foreach (Partition <string> p in hashRing.Partitions) { this.output.WriteLine($"{p.Node}: ({p.Range.StartExclusive}, {p.Range.EndInclusive}]"); } }
public override async Task OnActivateAsync() { _ring = new HashRing <int>(3, x => x); await base.OnActivateAsync(); }
public override Task OnActivateAsync() { _ring = new HashRing <int>(3, x => x); return(base.OnActivateAsync()); }