本文整理汇总了C#中SortedSet.headSet方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.headSet方法的具体用法?C# SortedSet.headSet怎么用?C# SortedSet.headSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedSet
的用法示例。
在下文中一共展示了SortedSet.headSet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: execute
/// <summary>
/// the command that is run and retried for actually
/// obtaining the lock
/// </summary>
/// <returns> if the command was successful or not </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean execute() throws org.apache.zookeeper.KeeperException, InterruptedException
public virtual bool execute()
{
do
{
if (string.ReferenceEquals(outerInstance.id, null))
{
long sessionId = outerInstance.zookeeper.SessionId;
string prefix = "x-" + sessionId + "-";
// lets try look up the current ID if we failed
// in the middle of creating the znode
findPrefixInChildren(prefix, outerInstance.zookeeper, outerInstance.dir);
outerInstance.idName = new ZNodeName(outerInstance.id);
}
if (!string.ReferenceEquals(outerInstance.id, null))
{
IList<string> names = outerInstance.zookeeper.getChildren(outerInstance.dir, false);
if (names.Count == 0)
{
LOG.warn("No children in: " + outerInstance.dir + " when we've just " + "created one! Lets recreate it...");
// lets force the recreation of the id
outerInstance.id = null;
}
else
{
// lets sort them explicitly (though they do seem to come back in order ususally :)
SortedSet<ZNodeName> sortedNames = new SortedSet<ZNodeName>();
foreach (string name in names)
{
sortedNames.Add(new ZNodeName(outerInstance.dir + "/" + name));
}
outerInstance.ownerId = sortedNames.Min.Name;
SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(outerInstance.idName);
if (lessThanMe.Count > 0)
{
ZNodeName lastChildName = lessThanMe.Max;
outerInstance.lastChildId = lastChildName.Name;
if (LOG.DebugEnabled)
{
LOG.debug("watching less than me node: " + outerInstance.lastChildId);
}
Stat stat = outerInstance.zookeeper.exists(outerInstance.lastChildId, new LockWatcher(outerInstance));
if (stat != null)
{
return false;
}
else
{
LOG.warn("Could not find the" + " stats for less than me: " + lastChildName.Name);
}
}
else
{
if (outerInstance.Owner)
{
if (outerInstance.callback != null)
{
outerInstance.callback.lockAcquired();
}
return true;
}
}
}
}
} while (string.ReferenceEquals(outerInstance.id, null));
return false;
}