本文整理汇总了Java中peersim.core.Linkable类的典型用法代码示例。如果您正苦于以下问题:Java Linkable类的具体用法?Java Linkable怎么用?Java Linkable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Linkable类属于peersim.core包,在下文中一共展示了Linkable类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRandomNeighbor
import peersim.core.Linkable; //导入依赖的package包/类
/**
* Returns a randomly selected neighbor of {@code self}.
*
* @param self
* the calling node.
* @param protocolID
* the ID of the {@link Linkable} protocol to use.
* @return a randomly selected node from the neighbors of {@code self}, or
* {@code null} if {@code self} has no neighbors or the chosen
* neighbor is down.
*/
public static Node getRandomNeighbor(Node self, int protocolID)
{
Linkable linkable = (Linkable) self.getProtocol(FastConfig.getLinkable(protocolID));
if (linkable.degree() > 0)
{
Node neighbor = linkable.getNeighbor(CommonState.r.nextInt(linkable.degree()));
if (neighbor.isUp())
{
return neighbor;
}
}
return null;
}
示例2: initialize
import peersim.core.Linkable; //导入依赖的package包/类
@Override
public void initialize(Node n)
{
if (Network.size() == 0)
return;
Linkable linkable = (Linkable) n.getProtocol(pid);
for (int j = 0; j < k; ++j)
{
int r = CommonState.r.nextInt(Network.size());
linkable.addNeighbor(Network.get(r));
((Linkable) Network.get(r).getProtocol(pid)).addNeighbor(n);
}
if (pack)
linkable.pack();
}