return false;
}
public static boolean transfer(Timespec deadline, Timespec period_ts, String[] lockedAccounts, String subAccountNum1, String subAccountNum2, int amount) {
IBankAccount subAccount1 = null;
IBankAccount subAccount2 = null;
Address server1 = null, server2 = null;
Timespec currenttime = new Timespec();
char num1 = subAccountNum1.split("-")[1].charAt(0);
char num2 = subAccountNum2.split("-")[1].charAt(0);
boolean locked1 = false;
boolean locked2 = false;
String strAccount1, strAccount2;
if((int)num1 > (int)num2) {
strAccount1 = subAccountNum2;
strAccount2 = subAccountNum1;
} else {
strAccount1 = subAccountNum1;
strAccount2 = subAccountNum2;
}
try {
try {
server1 = (Address) Network.getAddress(Benchmark.getServerId(strAccount1));
subAccount1 = (IBankAccount)LocateRegistry.getRegistry(server1.inetAddress.getHostAddress(), server1.port).lookup(subAccountNum1);
Network.linkDelay(true, server1);
subAccount1.wLock(deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
locked1 = true;
lockedAccounts[0] = strAccount1;
server2 = (Address) Network.getAddress(Benchmark.getServerId(strAccount2));
subAccount2 = (IBankAccount)LocateRegistry.getRegistry(server2.inetAddress.getHostAddress(), server2.port).lookup(strAccount2);
Network.linkDelay(true, server2);
subAccount2.wLock(deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
lockedAccounts[1] = strAccount2;
} catch (InterruptedException e) {
if(locked1){
Network.linkDelay(true, server1);
subAccount1.wUnlock();
lockedAccounts[0] = null;
}
return false;
}catch (NotBoundException e) {
if(locked1){
Network.linkDelay(true, server1);
subAccount1.wUnlock();
lockedAccounts[0] = null;
}
return false;
}
Logger.debug("In");
if(subAccount1 == null) {
System.out.println("Ac1Null");
return false;
}
else if (subAccount2 == null) {
System.out.println("Ac2Null");
return false;
}
if((int)num1 > (int)num2) {
for(int i=0; i<Benchmark.calls; i++){
Network.linkDelay(true, server1);
subAccount2.deposit(amount, deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
}
edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
for(int i=0; i<Benchmark.calls; i++){
Network.linkDelay(true, server2);
subAccount1.withdraw(amount, deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
}
} else {
for(int i=0; i<Benchmark.calls; i++){
Network.linkDelay(true, server1);
subAccount1.deposit(amount, deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
}
edu.vt.rt.hyflow.benchmark.Benchmark.processingDelay();
for(int i=0; i<Benchmark.calls; i++){
Network.linkDelay(true, server2);
subAccount2.withdraw(amount, deadline.getSeconds(), deadline.getNanoseconds(), period_ts.getSeconds(), period_ts.getNanoseconds());
}
}
Logger.debug("Out");
//Logger.fetal("Succeeded [" + subAccountNum1 + ", " +subAccountNum2 + "]");
return true;
} catch (AccessException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (NullPointerException e) {
System.out.println("NPE2"); //e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(subAccount1!=null)
try {
Network.linkDelay(true, server1);
subAccount1.wUnlock();
} catch (RemoteException e) {
e.printStackTrace();
}
if(subAccount2!=null)
try {
Network.linkDelay(true, server2);
subAccount2.wUnlock();
} catch (RemoteException e) {
e.printStackTrace();
}
}