📄 trivialnode.java
字号:
* Shows whenever this method is alive.
* @return true if the node is alive. false in other case.
* @see planet.commonapi.Node#isAlive()
*/
public boolean isAlive() {
return alive;
}
/**
* Gets the successor list.
* @param max Maximum number of successor to be returned.
* @return A vector with a <b>max</b> as maximum.
* @see planet.commonapi.Node#getSuccList(int)
*/
public Vector getSuccList(int max) {
//NOTE: only exists one successor
return successors;
}
/**
* Always return null.
* @param key Key to be found
* @param max Maximum number of nodehandles to be returned.
* @param safe Shows if the connections have to be safe.
* @return Always null.
* @see planet.commonapi.Node#localLookup(planet.commonapi.Id, int, boolean)
*/
public Vector localLookup(Id key, int max, boolean safe) {
return null;
}
/**
* Always return null.
* @param max Maximum number of neighbors to be returned.
* @return Always null.
* @see planet.commonapi.Node#neighborSet(int)
*/
public Vector neighborSet(int max) {
return null;
}
/**
* Always return null.
* @param key Key to be replicated.
* @param maxRank Maximum number of nodes where to save the replicas.
* @return Always null.
* @see planet.commonapi.Node#replicaSet(planet.commonapi.Id, int)
*/
public Vector replicaSet(Id key, int maxRank) {
return null;
}
/**
* This methods ALWAYS return false. It is not implemented yet.
* <br><br>
* This operation provides information about ranges of keys for
* which the <b>node</b> is currently a root. Returns false if
* the range could not be determined, true otherwise.
* <br><br>
* It is an error to query the range of a node not present in
* the neighbor set.
* <br><br>
* The [leftKey,rightKey] denotes the inclusive range of key values.
* @param node Node that is currently a root of some range of keys.
* @param rank Number of keys that is root the node (rank=rightKey-leftKey).
* @param leftKey The value that appears in the invokation is the candidate left
* key of the range. It may be modified to reflect the correct left margin
* once invokation has finished.
* @param rightKey Shows once the invokation has finished the left margin of
* the range.
* @return true if the range chold be determined; false otherwise, including
* the case of node is not present in the neighbor set returned by neighborSet().
* @see planet.commonapi.Node#range(planet.commonapi.NodeHandle,
* planet.commonapi.Id, planet.commonapi.Id, planet.commonapi.Id)
*/
public boolean range(NodeHandle node, Id rank, Id leftKey, Id rightKey) {
return false;
}
/**
* Build the edges for its sucessor and predecessor links.
* @param resultName Result name to be used.
* @param edgeCollection Edge collection where to add all the new ones.
* @param constraint Constraint to verify the addition of the edges.
* @see planet.commonapi.Node#buildEdges(java.lang.String, java.util.Collection, planet.commonapi.results.ResultsConstraint)
*/
public void buildEdges(String resultName, Collection edgeCollection, ResultsConstraint constraint) {
if (edgeCollection == null || constraint == null) return;
//neighbours (successors and predecessors)
ResultsEdge e = buildNewEdge(resultName,id,successor.getId(),"#0000FF");
if (e!=null)
if (constraint.isACompliantEdge(e)) edgeCollection.add(e);
e = buildNewEdge(resultName,id,predecessor.getId(),"#0000FF");
if (e!=null)
if (constraint.isACompliantEdge(e)) edgeCollection.add(e);
}
/**
* @return All the local links.
* @see planet.commonapi.Node#getAllLinks()
*/
public Set getAllLinks() {
return this.links;
}
/**
* Process the local incoming messages.
* @param actualStep Actual step in the simulation process.
* @return Always false, whenever the node always is stabilized and don't
* require more steps for its stabilization.
* @see planet.commonapi.Node#process(int)
*/
public boolean process(int actualStep) {
//always must be invoked at the beginning
super.process(actualStep);
//here starts your node process
if (Properties.overlayWithBehaviours)
{
//you may use this structure when your implemented overlay use behaviours
dispatchMessagesWithBehaviours();
} else {
//you may use this structure when your implemented overlay don't use behaviours
dispatchMessages();
}
//always must be invoked at the end
invokeByStepToAllApplications();
return false;
}
/** Sets the new Id.
* @param newId New Id.
* @return This instance after it has been updated.
* @throws InitializationException if any error has occurred.
* @see planet.commonapi.Node#setValues(planet.commonapi.Id)
*/
public Node setValues(Id newId) throws InitializationException {
super.setValues(newId);
//this overlay doesn't require any other action.
return this;
}
/* ****************** SPECIFIC OVERLAY METHODS *************************/
/**
* Updates the node predecessor.
* @param pred The new node predecessor.
*/
public void setPredecessor(NodeHandle pred)
{
if (predecessor!=null)
links.remove(predecessor);
predecessor = pred;
links.add(pred);
}
/**
* Updates the node successor.
* @param succ The new node successor.
*/
public void setSuccessor(NodeHandle succ)
{
if (successor!=null)
{
links.remove(successor);
successors.remove(0);
}
successor = succ;
links.add(succ);
successors.add(succ);
}
/**
* Dispatch all incoming messages of applicaion level.
*/
private void dispatchMessages()
{
while (hasMoreMessages())
{
RouteMessage msg = nextMessage();
//Only application level messages are delivered
dispatchDataMessage(msg,REQUEST,REFRESH);
}
}
/**
* Dispatch all incoming messages of application level using behaviours.
*
*/
private void dispatchMessagesWithBehaviours()
{
while (hasMoreMessages()) {
RouteMessage msg = nextMessage();
try {
behPool.onMessage(msg, this);
GenericFactory.freeMessage(msg);
} catch (planet.commonapi.behaviours.exception.NoSuchBehaviourException e) {
throw new Error("An applicable behaviour is not found");
} catch (planet.commonapi.behaviours.exception.NoBehaviourDispatchedException d) {
throw new Error("An applicable behaviour is not found");
}
}
}
/* END ************** SPECIFIC OVERLAY METHODS *************************/
/**
* @return The string representation of this node.
* @see java.lang.Object#toString()
*/
public String toString()
{
return "<TrivialNode id=\""+id+"\">";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -