return false;
}
public Integer sum(){ // used in sanity checks only
Integer sum=0;
INode pred = null, curr = null,front=null, end=null;
Address server=null,predServer = null, currServer=null, endServer=null;
String predId=null, firstId=null, currId=null;
try {
//Get a lock on front and end node so no one else can delete the nodes in queue
//While traversing through it
server = (Address) Network.getAddress(Benchmark.getServerId(HEAD));
front = (INode)LocateRegistry.getRegistry(server.inetAddress.getHostAddress(), server.port).lookup(HEAD);
Network.linkDelay(true, server);
front.lock();
Network.linkDelay(true, server);
predId= front.getNext();
//Get lock on END node
endServer = (Address) Network.getAddress(Benchmark.getServerId(TAIL));
end = (INode)LocateRegistry.getRegistry(endServer.inetAddress.getHostAddress(), endServer.port).lookup(TAIL);
Network.linkDelay(true, endServer);
end.lock();
Network.linkDelay(true, endServer);
//Get dummy node in queue
predServer = (Address) Network.getAddress(Benchmark.getServerId(predId));
pred = (INode)LocateRegistry.getRegistry(predServer.inetAddress.getHostAddress(), predServer.port).lookup(predId);
Network.linkDelay(true, predServer);
pred.lock();
Network.linkDelay(true, predServer);
firstId = pred.getNext();
//Check if queue is Empty
if(firstId == null){
Logger.debug("NOT FOUND..Queue is Empty");
front.unlock();
end.unlock();
pred.unlock();
return sum;
}
else{
//Unlock front node
front.unlock();
//Get Value of first node as current Node
currServer = (Address) Network.getAddress(Benchmark.getServerId(firstId));
curr = (INode)LocateRegistry.getRegistry(currServer.inetAddress.getHostAddress(), currServer.port).lookup(firstId);
Network.linkDelay(true, currServer);
curr.lock();
Network.linkDelay(true, currServer);
//Get New Current Id
currId = curr.getNext();
while(true){
sum += curr.getValue();
pred.unlock();
//Check new current ID
if(currId == null){
Logger.debug("Calculated Sum="+sum);
end.unlock();
curr.unlock();
return sum;
}
//Make current node Previous node
pred=curr;
//Get Details of New Current Node
currServer = (Address) Network.getAddress(Benchmark.getServerId(currId));
curr = (INode)LocateRegistry.getRegistry(currServer.inetAddress.getHostAddress(), currServer.port).lookup(currId);
Network.linkDelay(true, currServer);
curr.lock();
Network.linkDelay(true, currServer);
//Get next New Node
currId = curr.getNext();
}
}
} catch (AccessException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (NotBoundException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
try {
edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
if(pred!=null){
Network.linkDelay(true, predServer);
pred.unlock();
}
} catch (RemoteException e) {
e.printStackTrace();
}
try {