package JavaTransaction; import java.rmi.*; /** * Distributed Transaction System in Java. * * failure reporting is done using two pieces, exceptions and boolean * return values. Exceptions are used for systemy things - like * transactions that were forced to abort, or don't exist. Return * values are used for operations that would affect the consistency * of the database, like the deletion of more cars than the database * knows about. * If there is a boolean return value and you're not sure how it * would be used in your implementation, ignore it. I used boolean * return values in the interface generously to allow flexibility in * implementation. But don't forget to return true when the operation * has succeeded. */ public interface ResourceManager extends Remote { /** * Start transaction. * * @return a unique transaction ID. */ public int start() throws RemoteException; // returns Xid /** * Commit transaction. * * @return success. */ public boolean commit(int transactionId) throws RemoteException, TransactionAbortedException, InvalidTransactionException; /** * Abort transaction. * * @return nothing, but this may change. */ public void abort(int transactionId) throws RemoteException, InvalidTransactionException; // administrative interface /** * Add seats to a flight. In general this will be used to create a new * flight, but it should be possible to add seats to an existing flight. * Adding to an existing flight should overwrite the current price of the * available seats. * * @return success. */ public boolean addFlight(int Xid, int flightNum, int flightPrice, int flightSeats) throws RemoteException, TransactionAbortedException, InvalidTransactionException; /** * Delete the entire flight. * deleteflight implies whole deletion of the flight. * all seats, all reservations. It's undecided what will happen * if a customer has a reservation on this flight, but one possibility * is to delete the customer as well. The other possibility is to * return failure. * * @return success. */ public boolean deleteFlight(int Xid, int flightNum) throws RemoteException, TransactionAbortedException, InvalidTransactionException; /** Add rooms to a location. * This should look a lot like addFlight, only keyed on a string location * instead of a flight number. */ public boolean addRooms(int Xid, String location, int numRooms, int price) throws RemoteException, TransactionAbortedException, InvalidTransactionException; /** Delete Rooms from a location. * This subtracts from the available room count without allocating the * rooms to a customer. It should fail if it would make the count of * available rooms negative. * * @return success */ public boolean deleteRooms(int Xid, String location, int numRooms) throws RemoteException, TransactionAbortedException, InvalidTransactionException; /** Addition and deletion of cars. * Cars have the same semantics as hotels. */ public boolean addCars(int Xid, String location, int numCars, int price) throws RemoteException, TransactionAbortedException, InvalidTransactionException; public boolean deleteCars(int Xid, String location, int numCars) throws RemoteException, TransactionAbortedException, InvalidTransactionException; // technical/testing interface /** Shutdown gracefully. * When this RM restarts, it should not attempt to recover its state if * the client called shutdown to terminate it. * @return success */ public boolean shutdown() throws RemoteException; /** Call exit after a specified number of disk writes. * Support for this method requires a wrapper around the system's * write to disk command that decrements the counter set by this method. * This counter should default to 0, which implies that the wrapper * will do nothing. If the count is non-zero, the wrapper should decrement * the counter, see if it becomes zero, and if so, call exit(), otherwise * continue the write. * * This method is not part of a transaction. * * @return success */ public boolean selfDestruct(int diskWritesToWait) throws RemoteException; // query interface. /* queryFlight returns the number of empty seats. */ public int queryFlight(int Xid, int flightNumber) throws RemoteException, TransactionAbortedException, InvalidTransactionException; public int queryFlightPrice(int Xid, int flightNumber) throws RemoteException, TransactionAbortedException, InvalidTransactionException; /* return the number of rooms available at a location */ public int queryRooms(int Xid, String location) throws RemoteException, TransactionAbortedException, InvalidTransactionException; public int queryRoomsPrice(int Xid, String location) throws RemoteException, TransactionAbortedException, InvalidTransactionException; /* return the number of cars available at a location */ public int queryCars(int Xid, String location) throws RemoteException, TransactionAbortedException, InvalidTransactionException; public int queryCarsPrice(int Xid, String location) throws RemoteException, TransactionAbortedException, InvalidTransactionException; /* return a bill */ public String queryCustomerInfo(int customer) throws RemoteException, TransactionAbortedException, InvalidTransactionException; // customer functions /* new customer just returns a unique customer identifier */ public int newCustomer(int Xid) throws RemoteException, TransactionAbortedException, InvalidTransactionException; /* deleteCustomer removes the customer and associated reservations */ public boolean deleteCustomer(int Xid,int customer) throws RemoteException, TransactionAbortedException, InvalidTransactionException; public boolean reserveFlight(int Xid, int customer, int flightNumber) throws RemoteException, TransactionAbortedException, InvalidTransactionException; public boolean reserveCar(int Xid, int customer, String location) throws RemoteException, TransactionAbortedException, InvalidTransactionException; public boolean reserveRoom(int Xid, int customer, String location) throws RemoteException, TransactionAbortedException, InvalidTransactionException; }