Exemple #1
1
 public int newCustomer(int id) throws RemoteException {
   Trace.info("INFO: RM::newCustomer(" + id + ") called");
   // Generate a globally unique ID for the new customer
   int cid =
       Integer.parseInt(
           String.valueOf(id)
               + String.valueOf(Calendar.getInstance().get(Calendar.MILLISECOND))
               + String.valueOf(Math.round(Math.random() * 100 + 1)));
   Customer cust = new Customer(cid);
   writeData(id, cust.getKey(), cust);
   Customer temp = cust.clone();
   temp.setID(-1);
   temp.setType(1);
   writeDataToLog(id, cust.getKey(), temp);
   Trace.info("RM::newCustomer(" + cid + ") returns ID=" + cid);
   return cid;
 }
 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;
   }
 }