本文整理汇总了C#中SiloAddress.GetConsistentHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# SiloAddress.GetConsistentHashCode方法的具体用法?C# SiloAddress.GetConsistentHashCode怎么用?C# SiloAddress.GetConsistentHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiloAddress
的用法示例。
在下文中一共展示了SiloAddress.GetConsistentHashCode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConsistentRingProvider
public ConsistentRingProvider(SiloAddress siloAddr)
{
log = LogManager.GetLogger(typeof(ConsistentRingProvider).Name);
membershipRingList = new List<SiloAddress>();
MyAddress = siloAddr;
myKey = MyAddress.GetConsistentHashCode();
// add myself to the list of members
AddServer(MyAddress);
MyRange = RangeFactory.CreateFullRange(); // i am responsible for the whole range
statusListeners = new List<IRingRangeListener>();
Start();
}
示例2: CompareSiloAddressesByHash
/// <summary>
/// Compare SiloAddress-es based on their consistent hash code
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
private static int CompareSiloAddressesByHash(SiloAddress x, SiloAddress y)
{
if (x == null)
{
return y == null ? 0 : -1;
}
else
{
if (y == null)
{
return 1;
}
else
{
// real comparison is here
return x.GetConsistentHashCode().CompareTo(y.GetConsistentHashCode());
}
}
}
示例3: CalcRingDistance
private static long CalcRingDistance(SiloAddress silo1, SiloAddress silo2)
{
const long ringSize = int.MaxValue * 2L;
long hash1 = silo1.GetConsistentHashCode();
long hash2 = silo2.GetConsistentHashCode();
if (hash2 > hash1) return hash2 - hash1;
if (hash2 < hash1) return ringSize - (hash1 - hash2);
return 0;
}
示例4: AddServer
protected void AddServer(SiloAddress silo)
{
lock (membershipCache)
{
if (membershipCache.Contains(silo))
{
// we have already cached this silo
return;
}
membershipCache.Add(silo);
// insert new silo in the sorted order
long hash = silo.GetConsistentHashCode();
// Find the last silo with hash smaller than the new silo, and insert the latter after (this is why we have +1 here) the former.
// Notice that FindLastIndex might return -1 if this should be the first silo in the list, but then
// 'index' will get 0, as needed.
int index = membershipRingList.FindLastIndex(siloAddr => siloAddr.GetConsistentHashCode() < hash) + 1;
membershipRingList.Insert(index, silo);
HandoffManager.ProcessSiloAddEvent(silo);
if (log.IsVerbose) log.Verbose("Silo {0} added silo {1}", MyAddress, silo);
}
}
示例5: AddServer
internal void AddServer(SiloAddress silo)
{
lock (membershipRingList)
{
if (membershipRingList.Contains(silo)) return; // we already have this silo
int myOldIndex = membershipRingList.FindIndex(elem => elem.Equals(MyAddress));
if (!(membershipRingList.Count == 0 || myOldIndex != -1))
throw new OrleansException(string.Format("{0}: Couldn't find my position in the ring {1}.", MyAddress, Utils.EnumerableToString(membershipRingList)));
// insert new silo in the sorted order
int hash = silo.GetConsistentHashCode();
// Find the last silo with hash smaller than the new silo, and insert the latter after (this is why we have +1 here) the former.
// Notice that FindLastIndex might return -1 if this should be the first silo in the list, but then
// 'index' will get 0, as needed.
int index = membershipRingList.FindLastIndex(siloAddr => siloAddr.GetConsistentHashCode() < hash) + 1;
membershipRingList.Insert(index, silo);
// relating to triggering handler ... new node took over some of my responsibility
if (index == myOldIndex || // new node was inserted in my place
(myOldIndex == 0 && index == membershipRingList.Count - 1)) // I am the first node, and the new server is the last node
{
IRingRange oldRange = MyRange;
try
{
MyRange = RangeFactory.CreateRange(unchecked((uint)hash), unchecked((uint)myKey));
}
catch (OverflowException exc)
{
log.Error(ErrorCode.ConsistentRingProviderBase + 5,
String.Format("OverflowException: hash as int= x{0, 8:X8}, hash as uint= x{1, 8:X8}, myKey as int x{2, 8:X8}, myKey as uint x{3, 8:X8}.",
hash, (uint)hash, myKey, (uint)myKey), exc);
}
NotifyLocalRangeSubscribers(oldRange, MyRange, false);
}
log.Info("Added Server {0}. Current view: {1}", silo.ToStringWithHashCode(), this.ToString());
}
}
示例6: RemoveServer
internal void RemoveServer(SiloAddress silo)
{
lock (membershipRingList)
{
int indexOfFailedSilo = membershipRingList.FindIndex(elem => elem.Equals(silo));
if (indexOfFailedSilo < 0) return; // we have already removed this silo
membershipRingList.Remove(silo);
// related to triggering handler
int myNewIndex = membershipRingList.FindIndex(elem => elem.Equals(MyAddress));
if (myNewIndex == -1)
throw new OrleansException(string.Format("{0}: Couldn't find my position in the ring {1}.", MyAddress, this.ToString()));
bool wasMyPred = ((myNewIndex == indexOfFailedSilo) || (myNewIndex == 0 && indexOfFailedSilo == membershipRingList.Count)); // no need for '- 1'
if (wasMyPred) // failed node was our predecessor
{
if (log.IsVerbose) log.Verbose("Failed server was my pred? {0}, updated view {1}", wasMyPred, this.ToString());
IRingRange oldRange = MyRange;
if (membershipRingList.Count == 1) // i'm the only one left
{
MyRange = RangeFactory.CreateFullRange();
NotifyLocalRangeSubscribers(oldRange, MyRange, true);
}
else
{
int myNewPredIndex = myNewIndex == 0 ? membershipRingList.Count - 1 : myNewIndex - 1;
int myPredecessorsHash = membershipRingList[myNewPredIndex].GetConsistentHashCode();
MyRange = RangeFactory.CreateRange(unchecked((uint)myPredecessorsHash), unchecked((uint)myKey));
NotifyLocalRangeSubscribers(oldRange, MyRange, true);
}
}
log.Info("Removed Server {0} hash {1}. Current view {2}", silo, silo.GetConsistentHashCode(), this.ToString());
}
}
示例7: IsSiloNextInTheRing
private bool IsSiloNextInTheRing(SiloAddress siloAddr, uint hash, bool excludeMySelf)
{
return siloAddr.GetConsistentHashCode() >= hash && (!siloAddr.Equals(MyAddress) || !excludeMySelf);
}