tp
Interface RM

All Superinterfaces:
Remote
All Known Implementing Classes:
MyRM

public interface RM
extends Remote

Resource Manager Interface


Method Summary
 void abort(Transaction xid)
          abort transaction
 boolean add(Transaction xid, RID resource, int qty, int price)
          add qty items described by resource.
 void commit(Transaction xid)
          commit transaction
 boolean delete(Transaction xid, RID resource)
          Drop resource from this RM.
 boolean delete(Transaction xid, RID resource, int qty)
          Remove exactly qty unreserved resource from this RM.
 String getName()
          get the name of this RM
 Customer[] listCustomers(Transaction context)
          list of customers who reserve resources managed by this RM
 String[] listResources(Transaction context, RID.Type type)
          list of resources
 int query(Transaction xid, RID resource)
          query: equivalent to queryCars, queryFlights, queryRooms
 int queryPrice(Transaction xid, RID resource)
          query: equivalent to queryCarsPrice, queryFlightsPrice, queryRoomsPrice
 String queryReserved(Transaction context, Customer customer)
          Get the bill for the customer return a string representation of reservations
 int queryReservedPrice(Transaction context, Customer customer)
          Get the total amount of money the customer owes in this RM.
 boolean reserve(Transaction context, Customer customer, RID resource)
          reserve a resource i on behalf of customer c
 void selfDestruct(int diskWritesToWait)
          Exit (simulate a failure) after a specified number of disk writes.
 void unreserve(Transaction context, Customer customer)
          drop all reserved resources for customer customer
 

Method Detail

getName

String getName()
               throws RemoteException
get the name of this RM

Returns:
the name of this RM
Throws:
RemoteException

commit

void commit(Transaction xid)
            throws InvalidTransactionException,
                   TransactionAbortedException,
                   RemoteException
commit transaction

Parameters:
xid - transaction identifier
Throws:
InvalidTransactionException
TransactionAbortedException
RemoteException

abort

void abort(Transaction xid)
           throws RemoteException
abort transaction

Parameters:
xid - transaction identifier
Throws:
RemoteException

add

boolean add(Transaction xid,
            RID resource,
            int qty,
            int price)
            throws TransactionAbortedException,
                   InvalidTransactionException,
                   RemoteException
add qty items described by resource. If resource does not exist in the RM, create a new one.

Parameters:
xid - transaction identifier
resource - resource identifier
qty - quantity (seats, cars, rooms)
price - price per unit
Returns:
true on success. false otherwise
Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
WC.addSeats(Transaction, String, int, int), WC.addCars(Transaction, String, int, int), WC.addRooms(Transaction, String, int, int)

delete

boolean delete(Transaction xid,
               RID resource)
               throws TransactionAbortedException,
                      InvalidTransactionException,
                      RemoteException
Drop resource from this RM. All reservations on resource must be dropped as well.

Parameters:
xid - transaction identifier
resource - resource identifier
Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
WC.deleteFlight(Transaction, String)

delete

boolean delete(Transaction xid,
               RID resource,
               int qty)
               throws TransactionAbortedException,
                      InvalidTransactionException,
                      RemoteException
Remove exactly qty unreserved resource from this RM.

Parameters:
xid - transaction identifier
resource - resource identifier
qty - number of resource to remove. -1 removes all remaining
Returns:
true on successful deletion. If there is no such resource, return true. false otherwise. If there are not enough qty to remove, return false.
Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
WC.deleteSeats(Transaction, String, int), WC.deleteCars(Transaction, String, int), WC.deleteRooms(Transaction, String, int)

query

int query(Transaction xid,
          RID resource)
          throws TransactionAbortedException,
                 InvalidTransactionException,
                 RemoteException
query: equivalent to queryCars, queryFlights, queryRooms

Parameters:
xid - transaction identifier
resource - resource identifier
Returns:
available quantity
Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
WC.queryCar(Transaction, String), WC.queryRoom(Transaction, String), WC.queryFlight(Transaction, String)

queryPrice

int queryPrice(Transaction xid,
               RID resource)
               throws TransactionAbortedException,
                      InvalidTransactionException,
                      RemoteException
query: equivalent to queryCarsPrice, queryFlightsPrice, queryRoomsPrice

Parameters:
xid - transaction identifier
resource - resource identifier
Returns:
price per unit for requested item resource
Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
WC.queryCarPrice(Transaction, String), WC.queryRoomPrice(Transaction, String), WC.queryFlightPrice(Transaction, String)

queryReserved

String queryReserved(Transaction context,
                     Customer customer)
                     throws TransactionAbortedException,
                            InvalidTransactionException,
                            RemoteException
Get the bill for the customer return a string representation of reservations

Parameters:
context - the transaction ID
customer - the customer ID
Returns:
a string representation of reservations
Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
WC.queryItinerary(Transaction, Customer)

queryReservedPrice

int queryReservedPrice(Transaction context,
                       Customer customer)
                       throws TransactionAbortedException,
                              InvalidTransactionException,
                              RemoteException
Get the total amount of money the customer owes in this RM.

Parameters:
context - the transaction ID
customer - the customer ID
Returns:
total price of all reservations
Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
WC.queryItineraryPrice(Transaction, Customer)

reserve

boolean reserve(Transaction context,
                Customer customer,
                RID resource)
                throws TransactionAbortedException,
                       InvalidTransactionException,
                       RemoteException
reserve a resource i on behalf of customer c

Parameters:
context - the transaction ID
customer - the customer ID
resource - resource to reserve
Returns:
true on successful reservation. false otherwise.
Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
WC.reserveItinerary(Customer, String[], String, boolean, boolean)

unreserve

void unreserve(Transaction context,
               Customer customer)
               throws TransactionAbortedException,
                      InvalidTransactionException,
                      RemoteException
drop all reserved resources for customer customer

Parameters:
context - the transaction ID
customer - the customer ID
Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
WC.cancelItinerary(Customer)

listResources

String[] listResources(Transaction context,
                       RID.Type type)
                       throws TransactionAbortedException,
                              InvalidTransactionException,
                              RemoteException
list of resources

Parameters:
context -
type - listing resource type
Returns:
array of comma separated strings of available resource information. The format of each string is following:

resource name ',' available quantity ',' price

Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
WC.listCars(Transaction), WC.listFlights(Transaction), WC.listRooms(Transaction)

listCustomers

Customer[] listCustomers(Transaction context)
                         throws TransactionAbortedException,
                                InvalidTransactionException,
                                RemoteException
list of customers who reserve resources managed by this RM

Parameters:
context - the transaction ID
Returns:
list of customers
Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
WC.listCustomers(Transaction)

selfDestruct

void selfDestruct(int diskWritesToWait)
                  throws RemoteException
Exit (simulate a failure) after a specified number of disk writes. Support for this method requires a wrapper around the system's write system call that decrements the counter set by this method. This counter should be set to zero by default, which makes the wrapper doing nothing. If the counter is non-zero, the wrapper should decrement it, see if it is zero, and if so call exit(). This method is not part of a transaction. It is intended to simulate an RM failure.

Parameters:
diskWritesToWait - number of disk writes to wait until terminate
Throws:
RemoteException