private int logContains(int xId) { synchronized (logArray) { for (int i = 0; i < logArray.size(); i++) { Log temp = (Log) logArray.elementAt(i); if (temp.getXId() == xId) { return i; } } } return -1; }
/* reserve an itinerary */ public boolean itinerary( int id, int customer, Vector flightNumbers, String location, boolean Car, boolean Room) throws RemoteException { int noFlight = flightNumbers.size(); boolean result = false; ; for (int i = 0; i < noFlight; i++) { result = reserveFlight(id, customer, Integer.parseInt(flightNumbers.get(i).toString())); if (!result) break; } return result; }
private void writeDataToLog(int xId, String key, RMItem value) { System.out.println("entering writedatatolog"); synchronized (logArray) { Log temp; int indx; if ((indx = logContains(xId)) != -1) { temp = (Log) logArray.elementAt(indx); temp.put(key, value); } else { temp = new Log(xId, new RMHashtable()); temp.put(key, value); logArray.add(temp); } } }
private RMItem readDataFromLog(int id, String key, int xId) { synchronized (logArray) { int indx; if ((indx = logContains(xId)) != -1) { Log temp = (Log) logArray.elementAt(indx); return (RMItem) temp.get(key); } } return null; }
public void abort(int transactionId) throws RemoteException, InvalidTransactionException { int indx = logContains(transactionId); Log temp; if (indx > -1) { temp = (Log) logArray.elementAt(indx); } else { System.out.println("nothing in array"); return; } for (Enumeration e = temp.getKeys(); e.hasMoreElements(); ) { System.out.println("For loop"); String key = (String) (e.nextElement()); RMItem obj = temp.get(key); if (obj.getType() == 0) { Flight flight = (Flight) obj; if (flight.getCount() == -1) { System.out.println("entering count=-1 block"); removeData(transactionId, key); } else { System.out.println("entering other block"); writeData(transactionId, key, flight); } } else if (obj.getType() == 1) { Customer cust = (Customer) obj; if (cust.getID() == -1) { System.out.println("entering remove data for customer"); removeData(transactionId, key); } else { System.out.println("entering write data for customer"); writeData(transactionId, key, obj); } } } }
protected boolean removeDataFromLog(int xId) { int indx = logContains(xId); if (indx >= 0) logArray.remove(indx); return true; }