int r = randomPtr.posrandom_generate() % 100;
int action = selectAction(r, percentUser);
- switch (action) {
- case ACTION_MAKE_RESERVATION: {
+ if(action==ACTION_MAKE_RESERVATION) {
int maxPrices[]=new int[NUM_RESERVATION_TYPE];
int maxIds[]=new int[NUM_RESERVATION_TYPE];
maxPrices[0]=-1;
int t = types[n];
int id = ids[n];
int price = -1;
- switch (t) {
- case RESERVATION_CAR:
+ if (t==RESERVATION_CAR) {
if (managerPtr.manager_queryCar(id) >= 0) {
price = managerPtr.manager_queryCarPrice(id);
}
- break;
- case RESERVATION_FLIGHT:
+ } else if (t==RESERVATION_FLIGHT) {
if (managerPtr.manager_queryFlight(id) >= 0) {
price = managerPtr.manager_queryFlightPrice(id);
}
- break;
- case RESERVATION_ROOM:
+ } else if (t==RESERVATION_ROOM) {
if (managerPtr.manager_queryRoom(id) >= 0) {
price = managerPtr.manager_queryRoomPrice(id);
}
- break;
- default:
- //assert(0);
}
if (price > maxPrices[t]) {
maxPrices[t] = price;
managerPtr.manager_reserveRoom(customerId, maxIds[RESERVATION_ROOM]);
}
}
- break;
- }
-
- case ACTION_DELETE_CUSTOMER: {
+ } else if (action==ACTION_DELETE_CUSTOMER) {
int customerId = randomPtr.posrandom_generate() % queryRange + 1;
atomic {
int bill = managerPtr.manager_queryCustomerBill(customerId);
managerPtr.manager_deleteCustomer(customerId);
}
}
- break;
- }
-
- case ACTION_UPDATE_TABLES: {
+ } else if (action==ACTION_UPDATE_TABLES) {
int numUpdate = randomPtr.posrandom_generate() % numQueryPerTransaction + 1;
int n;
for (n = 0; n < numUpdate; n++) {
int doAdd = ops[n];
if (doAdd==1) {
int newPrice = prices[n];
- switch (t) {
- case RESERVATION_CAR:
+ if (t==RESERVATION_CAR) {
managerPtr.manager_addCar(id, 100, newPrice);
- break;
- case RESERVATION_FLIGHT:
+ } else if (t==RESERVATION_FLIGHT) {
managerPtr.manager_addFlight(id, 100, newPrice);
- break;
- case RESERVATION_ROOM:
+ } else if (t==RESERVATION_ROOM) {
managerPtr.manager_addRoom(id, 100, newPrice);
- break;
- default:
- //assert(0);
}
} else { /* do delete */
- switch (t) {
- case RESERVATION_CAR:
+ if (t==RESERVATION_CAR) {
managerPtr.manager_deleteCar(id, 100);
- break;
- case RESERVATION_FLIGHT:
+ } else if (t==RESERVATION_FLIGHT) {
managerPtr.manager_deleteFlight(id);
- break;
- case RESERVATION_ROOM:
+ } else if (t==RESERVATION_ROOM) {
managerPtr.manager_deleteRoom(id, 100);
- break;
- default:
- //assert(0);
}
}
}
}
- break;
}
-
- default:
- //assert(0);
- } /* switch (action) */
} /* for i */
Barrier.enterBarrier();
}
boolean status = reservationInfoListPtr.remove(findReservationInfo);
if (!status) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART15");
System.exit(-1);
}
if (reservationPtr.numTotal == 0) {
boolean status = tablePtr.remove(id);
if (!status) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART7");
System.exit(-1);
}
} else {
// assert(customerPtr != null);
status = customerTablePtr.insert(customerId, customerPtr);
if (!status) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART8");
System.exit(-1);
}
reservationInfoPtr =(Reservation_Info)it.dataPtr;
reservationPtr = (Reservation)reservationTables[reservationInfoPtr.type].find(reservationInfoPtr.id);
if (reservationPtr == null) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART9");
System.exit(-1);
}
status = reservationPtr.reservation_cancel();
if (!status) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART10");
System.exit(-1);
}
}
status = customerTablePtr.remove(customerId);
if (!status) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART11");
System.exit(-1);
}
return true;
/* Undo previous successful reservation */
boolean status = reservationPtr.reservation_cancel();
if (!status) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART12");
System.exit(-1);
}
return false;
/* Undo previous successful cancellation */
boolean status = reservationPtr.reservation_make();
if (!status) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART13");
System.exit(-1);
}
return false;
this.numFree=numTotal;
this.numTotal=numTotal;
this.price=price;
+ checkReservation();
}
int id;
public void checkReservation() {
int numUsed = this.numUsed;
if (numUsed < 0) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART1");
System.exit(-1);
}
int numFree = this.numFree;
if (numFree < 0) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART2");
System.exit(-1);
}
int numTotal = this.numTotal;
if (numTotal < 0) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART3");
System.exit(-1);
}
if ((numUsed + numFree) != numTotal) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART4");
System.exit(-1);
}
int price = this.price;
if (price < 0) {
- System.out.println("TMRESTART");
+ System.out.println("TMRESTART5");
System.exit(-1);
}
}
numFree+=num;
numTotal+=num;
+ checkReservation();
return true;
}
}
numUsed++;
numFree--;
+ checkReservation();
return true;
}
}
numUsed--;
numFree++;
- return false;
+ checkReservation();
+ return true;
}
}
this.price=newPrice;
+ checkReservation();
return true;
}
* displayUsage
* =============================================================================
*/
+ public Vacation() {
+ }
public static void displayUsage (String appName) {
System.out.println("Usage: %s [options]\n"+ appName);
int id = ids[i];
int num = ((randomPtr.posrandom_generate() % 5) + 1) * 100;
int price = ((randomPtr.posrandom_generate() % 5) * 10) + 50;
- switch(t) {
- case 0:
+ if (t==0) {
status=managerPtr.manager_addCar(id, num, price);
- break;
- case 1:
+ } else if (t==1) {
status=managerPtr.manager_addFlight(id, num, price);
- break;
- case 2:
+ } else if (t==2) {
status=managerPtr.manager_addRoom(id, num, price);
- break;
- case 3:
+ } else if (t==3) {
status=managerPtr.manager_addCustomer(id);
- break;
}
//assert(status);
}
MAINCLASS=Vacation
SRC=tmpVacation.java tmpClient.java tmpManager.java tmpRBTree.java \
-../../../ClassLibrary/JavaSTM/Barrier.java
+../../../ClassLibrary/JavaSTM/Barrier.java ../common/Random.java
include ../common/Makefile.flags