dmy.setNext(null);
}
public void enqueue(Integer item) {
INode tail = null, last=null;
Address tailServer = null, lastServer=null;
String lastId = null;
try{
tailServer = (Address) Network.getAddress(Benchmark.getServerId(TAIL));
tail = (INode)LocateRegistry.getRegistry(tailServer.inetAddress.getHostAddress(), tailServer.port).lookup(TAIL);
Network.linkDelay(true, tailServer);
tail.lock();
Network.linkDelay(true, tailServer);
lastId = tail.getNext(); //Got Id for last node in queue
lastServer = (Address) Network.getAddress(Benchmark.getServerId(lastId));
last = (INode)LocateRegistry.getRegistry(lastServer.inetAddress.getHostAddress(), lastServer.port).lookup(lastId);
Network.linkDelay(true, lastServer);
last.lock();
Network.linkDelay(true, lastServer);
String newNodeId = Network.getInstance().getID() + "-" + Math.random(); // generate random id
Node newNode = new Node(newNodeId, item);
newNode.setNext(null);
tail.setNext(newNodeId);
Network.linkDelay(true, tailServer);
last.setNext(newNodeId);
Network.linkDelay(true, lastServer);
Logger.debug("list.add("+item+");");
} catch (AccessException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (NotBoundException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}finally {
try {
Benchmark.processingDelay();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(last!=null){
Network.linkDelay(true, lastServer);
try {
last.unlock();
} catch (RemoteException e) {
e.printStackTrace();
}
}
if(tail!=null ){
Network.linkDelay(true, tailServer);
try {
tail.unlock();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}