IReservation[] reservIds = new IReservation[3];
boolean isFound = false;
Object[] reservations = null;
Address[] reservationsServers;
ICustomer customer;
Address customerServer;
while(true){
int i=0;
try {
Object[] data = open(objId);
reservations = (Object[])data[0];
reservationsServers = (Address[])data[1];
data = open(customerId);
customer = (data==null ? null : (ICustomer)((Object[])data[0])[0]);
customerServer = (data==null ? null : ((Address[])data[1])[0]);
for(; i<reservations.length; i++){
IReservation reservation = (IReservation)reservations[i];
if(reservation!=null)
reservation.rLock();
}
if(customer!=null)
customer.wLock();
break;
}catch (NoSuchObjectException e) {
for(int j=0; j<i; j++){
IReservation reservation = (IReservation)reservations[j];
if(reservation!=null)
reservation.rUnlock();
}
return;
}catch (InterruptedException e) {
for(int j=0; j<i; j++){
IReservation reservation = (IReservation)reservations[j];
if(reservation!=null)
reservation.rUnlock();
}
}
}
try {
for(int i=0; i<Benchmark.queryPerTransaction; i++){
int price = Integer.MAX_VALUE;
IReservation car = (IReservation)reservations[i];
if(car==null)
continue;
if(car.isAvailable())
price = car.getPrice();
if(price < minPrice[objType[i]]){
minPrice[objType[i]] = price;
minIds[objType[i]] = objId[i];
reservIds[objType[i]] = car;
isFound = true;
}
}
if(isFound){
// create customer
if(customer==null)
try {
Address address = (Address) Network.getAddress(Benchmark.getServerId(customerId));
IVacation vacation = (IVacation)LocateRegistry.getRegistry(address.inetAddress.getHostAddress(), address.port).lookup("vacation");
customer = vacation.createCustomer(customerId);
} catch (RemoteException e1) {
e1.printStackTrace();
} catch (NotBoundException e) {