示例#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;
   }
 }
示例#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;
   }
 }
示例#3
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;
   }
 }
示例#4
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;
   }
 }
示例#5
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;
   }
 }
示例#6
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;
   }
 }