Beispiel #1
0
 // Returns room price at this location
 public ReturnTuple<Integer> queryRoomsPrice(int id, String location, Timestamp timestamp)
     throws RemoteException, TransactionAbortedException, InvalidTransactionException {
   if (!isMaster) {
     System.out.println("Slave retransmitting queryRoomsPrice to master");
     return this.getMaster().queryRoomsPrice(id, location, timestamp);
   } else {
     timestamp.stamp();
     QueryRoomsPriceRMICommand qrp = new QueryRoomsPriceRMICommand(roomGroup, id, location);
     qrp.setTimestampObject(timestamp);
     ReturnTuple<Integer> result = null;
     try {
       overseer.validTransaction(id);
       lm.Lock(id, Hotel.getKey(location), qrp.getRequiredLock());
       qrp.execute();
       result = qrp.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;
   }
 }
Beispiel #2
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;
   }
 }
  @Override
  public ReviewsSummary getReviewSummary(Hotel hotel) {
    Collection<RatingCount> ratingCounts =
        ratingCountListCacheRedisRepository.get(
            "ratingcounts:hotel:" + hotel.getId(), RatingCount.class);

    if (ratingCounts == null || ratingCounts.isEmpty()) {
      ratingCounts = this.hotelRepository.findRatingCounts(hotel);
      if (ratingCounts != null) {
        ratingCountListCacheRedisRepository.multiAdd(
            "ratingcounts:hotel:" + hotel.getId(), ratingCounts, true);
        ratingCountListCacheRedisRepository.expire(
            "ratingcounts:hotel:" + hotel.getId(), 60, TimeUnit.SECONDS);
      }
    }

    return new ReviewsSummaryImpl(new ArrayList<>(ratingCounts));
  }
Beispiel #4
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;
   }
 }
Beispiel #5
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;
   }
 }
Beispiel #6
0
 // Adds room reservation to this customer.
 public boolean reserveRoom(int id, int customerID, String location) throws RemoteException {
   return reserveItem(id, customerID, Hotel.getKey(location), location);
 }
Beispiel #7
0
 // Returns room price at this location
 public int queryRoomsPrice(int id, String location) throws RemoteException {
   return queryPrice(id, Hotel.getKey(location));
 }
Beispiel #8
0
 // Delete rooms from a location
 public boolean deleteRooms(int id, String location) throws RemoteException {
   return deleteItem(id, Hotel.getKey(location));
 }