Example #1
1
 public ReturnTuple<Integer> newCustomer(int id, Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting newCustomer to master");
     return this.getMaster().newCustomer(id, timestamp);
   } else {
     timestamp.stamp();
     int rid =
         Integer.parseInt(
             String.valueOf(id)
                 + String.valueOf(Calendar.getInstance().get(Calendar.MILLISECOND))
                 + String.valueOf(Math.round(Math.random() * 100 + 1)));
     NewCustomerWithIdRMICommand nc =
         new NewCustomerWithIdRMICommand(carGroup, flightGroup, roomGroup, id, rid);
     nc.setTimestampObject(timestamp);
     ReturnTuple<Integer> result = null;
     try {
       overseer.validTransaction(id);
       lm.Lock(id, Customer.getKey(rid), nc.getRequiredLock());
       nc.execute();
       result = new ReturnTuple<Integer>(rid, nc.success.timestamp);
       overseer.addCommandToTransaction(id, nc);
     } catch (DeadlockException d) {
       timestamp.stamp();
       overseer.abort(id);
       timestamp.stamp();
       throw new TransactionAbortedException(timestamp);
     } catch (TransactionAbortedException tae) {
       tae.t = timestamp;
       throw tae;
     } catch (InvalidTransactionException ite) {
       ite.t = timestamp;
       throw ite;
     }
     result.timestamp.stamp();
     return result;
   }
 }
Example #2
0
 // Deletes customer from the database.
 public ReturnTuple<Boolean> deleteCustomer(int id, int customerID, Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting deleteCustomer to master");
     return this.getMaster().deleteCustomer(id, customerID, timestamp);
   } else {
     timestamp.stamp();
     DeleteCustomerRMICommand dc =
         new DeleteCustomerRMICommand(carGroup, flightGroup, roomGroup, id, customerID);
     dc.setTimestampObject(timestamp);
     ReturnTuple<Boolean> result = null;
     try {
       overseer.validTransaction(id);
       lm.Lock(id, Customer.getKey(customerID), dc.getRequiredLock());
       dc.execute();
       result = dc.success;
       if (result.result) overseer.addCommandToTransaction(id, dc);
     } catch (DeadlockException d) {
       timestamp.stamp();
       overseer.abort(id);
       timestamp.stamp();
       throw new TransactionAbortedException(timestamp);
     } catch (TransactionAbortedException tae) {
       tae.t = timestamp;
       throw tae;
     } catch (InvalidTransactionException ite) {
       ite.t = timestamp;
       throw ite;
     }
     result.timestamp.stamp();
     return result;
   }
 }
Example #3
0
 // Returns the number of empty seats on this flight
 public ReturnTuple<Integer> queryFlight(int id, int flightNum, Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting queryFlight to master");
     return this.getMaster().queryFlight(id, flightNum, timestamp);
   } else {
     timestamp.stamp();
     QueryFlightRMICommand qf = new QueryFlightRMICommand(flightGroup, id, flightNum);
     qf.setTimestampObject(timestamp);
     ReturnTuple<Integer> result = null;
     try {
       overseer.validTransaction(id);
       lm.Lock(id, Flight.getKey(flightNum), qf.getRequiredLock());
       qf.execute();
       result = qf.numSeats;
     } catch (DeadlockException d) {
       timestamp.stamp();
       overseer.abort(id);
       timestamp.stamp();
       throw new TransactionAbortedException(timestamp);
     } catch (TransactionAbortedException tae) {
       tae.t = timestamp;
       throw tae;
     } catch (InvalidTransactionException ite) {
       ite.t = timestamp;
       throw ite;
     }
     result.timestamp.stamp();
     return result;
   }
 }
Example #4
0
 // Returns price of cars at this location
 public ReturnTuple<Integer> queryCarsPrice(int id, String location, Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting queryCarsPrice to master");
     return this.getMaster().queryCarsPrice(id, location, timestamp);
   } else {
     QueryCarsPriceRMICommand qcp = new QueryCarsPriceRMICommand(roomGroup, id, location);
     qcp.setTimestampObject(timestamp);
     ReturnTuple<Integer> result = null;
     try {
       overseer.validTransaction(id);
       lm.Lock(id, Car.getKey(location), qcp.getRequiredLock());
       qcp.execute();
       result = qcp.price;
     } catch (DeadlockException d) {
       timestamp.stamp();
       overseer.abort(id);
       timestamp.stamp();
       throw new TransactionAbortedException(timestamp);
     } catch (TransactionAbortedException tae) {
       tae.t = timestamp;
       throw tae;
     } catch (InvalidTransactionException ite) {
       ite.t = timestamp;
       throw ite;
     }
     result.timestamp.stamp();
     return result;
   }
 }
Example #5
0
 // Delete rooms from a location
 public ReturnTuple<Boolean> deleteRooms(int id, String location, Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting deleteRooms to master");
     return this.getMaster().deleteRooms(id, location, timestamp);
   } else {
     timestamp.stamp();
     DeleteRoomsRMICommand dr = new DeleteRoomsRMICommand(roomGroup, id, location);
     dr.setTimestampObject(timestamp);
     ReturnTuple<Boolean> result = null;
     try {
       overseer.validTransaction(id);
       lm.Lock(id, Hotel.getKey(location), dr.getRequiredLock());
       dr.execute();
       result = dr.success;
       if (result.result) overseer.addCommandToTransaction(id, dr);
     } catch (DeadlockException d) {
       timestamp.stamp();
       overseer.abort(id);
       timestamp.stamp();
       throw new TransactionAbortedException(timestamp);
     } catch (TransactionAbortedException tae) {
       tae.t = timestamp;
       throw tae;
     } catch (InvalidTransactionException ite) {
       ite.t = timestamp;
       throw ite;
     }
     result.timestamp.stamp();
     return result;
   }
 }
Example #6
0
 // Create a new car location or add cars to an existing location
 //  NOTE: if price <= 0 and the location already exists, it maintains its current price
 public ReturnTuple<Boolean> addCars(
     int id, String location, int count, int price, Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting addCars to master");
     return this.getMaster().addCars(id, location, count, price, timestamp);
   } else {
     timestamp.stamp();
     AddCarsRMICommand ac = new AddCarsRMICommand(carGroup, id, location, count, price);
     ac.setTimestampObject(timestamp);
     ReturnTuple<Boolean> result = null;
     try {
       overseer.validTransaction(id);
       lm.Lock(id, Car.getKey(location), ac.getRequiredLock());
       ac.execute();
       result = ac.success;
       if (result.result) overseer.addCommandToTransaction(id, ac);
     } catch (DeadlockException d) {
       timestamp.stamp();
       overseer.abort(id);
       timestamp.stamp();
       throw new TransactionAbortedException(timestamp);
     } catch (TransactionAbortedException tae) {
       tae.t = timestamp;
       throw tae;
     } catch (InvalidTransactionException ite) {
       ite.t = timestamp;
       throw ite;
     }
     result.timestamp.stamp();
     return result;
   }
 }
Example #7
0
 // Create a new flight, or add seats to existing flight
 //  NOTE: if flightPrice <= 0 and the flight already exists, it maintains its current price
 public ReturnTuple<Boolean> addFlight(
     int id, int flightNum, int flightSeats, int flightPrice, Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting addFlight to master");
     return this.getMaster().addFlight(id, flightNum, flightSeats, flightPrice, timestamp);
   } else {
     timestamp.stamp();
     AddFlightRMICommand af =
         new AddFlightRMICommand(flightGroup, id, flightNum, flightSeats, flightPrice);
     af.setTimestampObject(timestamp);
     ReturnTuple<Boolean> result = null;
     try {
       overseer.validTransaction(id);
       lm.Lock(id, Flight.getKey(flightNum), af.getRequiredLock());
       af.execute();
       result = af.success;
       if (result.result) overseer.addCommandToTransaction(id, af);
     } catch (DeadlockException d) {
       timestamp.stamp();
       overseer.abort(id);
       timestamp.stamp();
       throw new TransactionAbortedException(timestamp);
     } catch (TransactionAbortedException tae) {
       tae.t = timestamp;
       throw tae;
     } catch (InvalidTransactionException ite) {
       ite.t = timestamp;
       throw ite;
     }
     result.timestamp.stamp();
     return result;
   }
 }
Example #8
0
 /* reserve an itinerary */
 public ReturnTuple<Boolean> itinerary(
     int id,
     int customer,
     Vector flightNumbers,
     String location,
     boolean Car,
     boolean Room,
     Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting itinerary to master");
     return this.getMaster()
         .itinerary(id, customer, flightNumbers, location, Car, Room, timestamp);
   } else {
     timestamp.stamp();
     ItineraryRMICommand i =
         new ItineraryRMICommand(
             carGroup, flightGroup, roomGroup, id, customer, flightNumbers, location, Car, Room);
     i.setTimestampObject(timestamp);
     ReturnTuple<Boolean> result = null;
     try {
       overseer.validTransaction(id);
       lm.Lock(id, Customer.getKey(customer), i.getRequiredLock());
       lm.Lock(id, ResImpl.Car.getKey(location), i.getRequiredLock());
       lm.Lock(id, Hotel.getKey(location), i.getRequiredLock());
       for (Object flightNo : flightNumbers) {
         int flightNum = Integer.parseInt((String) flightNo);
         lm.Lock(id, Flight.getKey(flightNum), i.getRequiredLock());
       }
       i.execute();
       result = i.success;
       if (result.result && !i.error()) overseer.addCommandToTransaction(id, i);
     } catch (DeadlockException d) {
       timestamp.stamp();
       overseer.abort(id);
       timestamp.stamp();
       throw new TransactionAbortedException(timestamp);
     } catch (TransactionAbortedException tae) {
       tae.t = timestamp;
       throw tae;
     } catch (InvalidTransactionException ite) {
       ite.t = timestamp;
       throw ite;
     }
     result.timestamp.stamp();
     return result;
   }
 }
Example #9
0
 // return a bill
 public ReturnTuple<String> queryCustomerInfo(int id, int customerID, Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting queryCustomerInfo to master");
     return this.getMaster().queryCustomerInfo(id, customerID, timestamp);
   } else {
     timestamp.stamp();
     QueryCustomerInfoRMICommand qci =
         new QueryCustomerInfoRMICommand(carGroup, flightGroup, roomGroup, id, customerID);
     qci.setTimestampObject(timestamp);
     ReturnTuple<String> result = null;
     try {
       Vector<Integer> flightNos;
       Vector<String> locations;
       overseer.validTransaction(id);
       lm.Lock(id, Customer.getKey(customerID), qci.getRequiredLock());
       qci.execute();
       flightNos = qci.getCustomerFlightReservations();
       for (int flightNo : flightNos) {
         lm.Lock(id, Flight.getKey(flightNo), qci.getRequiredLock());
       }
       locations = qci.getCustomerRoomReservations();
       for (String location : locations) {
         lm.Lock(id, Hotel.getKey(location), qci.getRequiredLock());
       }
       locations = qci.getCustomerCarReservations();
       for (String location : locations) {
         lm.Lock(id, Car.getKey(location), qci.getRequiredLock());
       }
       qci.execute();
       result = qci.customerInfo;
     } catch (DeadlockException d) {
       timestamp.stamp();
       overseer.abort(id);
       timestamp.stamp();
       throw new TransactionAbortedException(timestamp);
     } catch (TransactionAbortedException tae) {
       tae.t = timestamp;
       throw tae;
     } catch (InvalidTransactionException ite) {
       ite.t = timestamp;
       throw ite;
     }
     result.timestamp.stamp();
     return result;
   }
 }
Example #10
0
 public ReturnTuple<Integer> start(Timestamp timestamp) throws RemoteException {
   if (!isMaster) {
     System.out.println("Slave retransmitting start to master");
     return this.getMaster().start(timestamp);
   } else {
     timestamp.stamp();
     int tId;
     tId = overseer.createTransaction(lm);
     timestamp.stamp();
     return new ReturnTuple<Integer>(tId, timestamp);
   }
 }
Example #11
0
 public ReturnTuple<Boolean> commit(int id, Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting commit to master");
     return this.getMaster().commit(id, timestamp);
   } else {
     timestamp.stamp();
     boolean result = overseer.commit(id);
     timestamp.stamp();
     return new ReturnTuple<Boolean>(result, timestamp);
   }
 }
Example #12
0
 public ReturnTuple<Object> abort(int id, Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting abort to master");
     return this.getMaster().abort(id, timestamp);
   } else {
     timestamp.stamp();
     overseer.abort(id);
     timestamp.stamp();
     return new ReturnTuple<Object>(null, timestamp);
   }
 }