|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object tp.impl.CSEP545ServiceObject tp.impl.MyRM
public class MyRM
Your Resource Manager. Rudimentary implementation is provided for your convenience.
CSEP545ServiceObject.main(String[])
.
-x
or --selfdestruct
numio
:
Set the self destruction timer on this RM. If this argument is given,
the RM MUST call System.exit() immediately after numio disk operations.
(default: 0. no self destruction)-t
or --timeout
s
:
Set deadlock detection timeout to s
seconds.
(default: LM.DEFAULT_DEADLOCK_TIMEOUT
)
CSEP545ServiceObject
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface tp.impl.CSEP545Service |
---|
CSEP545Service.Type |
Field Summary |
---|
Fields inherited from class tp.impl.CSEP545ServiceObject |
---|
dir, registry, svcid |
Constructor Summary | |
---|---|
MyRM()
|
Method Summary | |
---|---|
void |
abort(Transaction xid)
abort transaction |
boolean |
add(Transaction xid,
RID i,
int count,
int price)
add qty items described by resource . |
void |
commit(Transaction xid)
commit transaction |
boolean |
delete(Transaction xid,
RID rid)
Drop resource from this RM. |
boolean |
delete(Transaction xid,
RID i,
int count)
Remove exactly qty unreserved resource from this RM. |
String |
getName()
get the name of this RM |
protected void |
init(String[] args)
IMPLEMENT THIS METHOD process command line parameters and setup any parameterized values. |
protected void |
initStorage()
IMPLEMENT THIS METHOD Initialize necessary data files. |
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 rid)
query: equivalent to queryCars, queryFlights, queryRooms |
int |
queryPrice(Transaction xid,
RID i)
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. |
protected void |
readyToServe()
IMPLEMENT THIS METHOD Bootstrapping completed and the server is up and running. |
protected void |
recovery()
IMPLEMENT THIS METHOD Run recovery algorithm and reconstruct the state of service before failure. |
void |
refresh()
Refresh all remote references used by this service. |
boolean |
reserve(Transaction context,
Customer c,
RID i)
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 |
shutdown()
Gracefully shutdown target service. |
protected void |
startUp()
IMPLEMENT THIS METHOD If you use extra threads in your service, start them in this method. |
void |
unreserve(Transaction context,
Customer c)
drop all reserved resources for customer customer |
Methods inherited from class tp.impl.CSEP545ServiceObject |
---|
getDataRoot, getServiceID, kill, lookupRemote, lookupRemote, lookupRemote, lookupRemote, main |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MyRM()
Method Detail |
---|
public void commit(Transaction xid) throws InvalidTransactionException, TransactionAbortedException, RemoteException
RM
commit
in interface RM
xid
- transaction identifier
InvalidTransactionException
TransactionAbortedException
RemoteException
public void abort(Transaction xid) throws RemoteException
RM
abort
in interface RM
xid
- transaction identifier
RemoteException
public boolean add(Transaction xid, RID i, int count, int price) throws TransactionAbortedException, InvalidTransactionException, RemoteException
RM
qty
items described by resource
.
If resource
does not exist in the RM, create a new one.
add
in interface RM
xid
- transaction identifieri
- resource identifiercount
- quantity (seats, cars, rooms)price
- price per unit
true
on success. false
otherwise
TransactionAbortedException
InvalidTransactionException
RemoteException
WC.addSeats(Transaction, String, int, int)
,
WC.addCars(Transaction, String, int, int)
,
WC.addRooms(Transaction, String, int, int)
public boolean delete(Transaction xid, RID rid) throws TransactionAbortedException, InvalidTransactionException, RemoteException
RM
resource
from this RM.
All reservations on resource
must be dropped as well.
delete
in interface RM
xid
- transaction identifierrid
- resource identifier
TransactionAbortedException
InvalidTransactionException
RemoteException
WC.deleteFlight(Transaction, String)
public boolean delete(Transaction xid, RID i, int count) throws TransactionAbortedException, InvalidTransactionException, RemoteException
RM
qty
unreserved resource
from this RM.
delete
in interface RM
xid
- transaction identifieri
- resource identifiercount
- number of resource to remove. -1
removes all remaining
true
on successful deletion.
If there is no such resource
, return true
.
false
otherwise.
If there are not enough qty
to remove, return false
.
TransactionAbortedException
InvalidTransactionException
RemoteException
WC.deleteSeats(Transaction, String, int)
,
WC.deleteCars(Transaction, String, int)
,
WC.deleteRooms(Transaction, String, int)
public int query(Transaction xid, RID rid) throws TransactionAbortedException, InvalidTransactionException, RemoteException
RM
query
in interface RM
xid
- transaction identifierrid
- resource identifier
TransactionAbortedException
InvalidTransactionException
RemoteException
WC.queryCar(Transaction, String)
,
WC.queryRoom(Transaction, String)
,
WC.queryFlight(Transaction, String)
public int queryPrice(Transaction xid, RID i) throws TransactionAbortedException, InvalidTransactionException, RemoteException
RM
queryPrice
in interface RM
xid
- transaction identifieri
- resource identifier
resource
TransactionAbortedException
InvalidTransactionException
RemoteException
WC.queryCarPrice(Transaction, String)
,
WC.queryRoomPrice(Transaction, String)
,
WC.queryFlightPrice(Transaction, String)
public String queryReserved(Transaction context, Customer customer) throws TransactionAbortedException, InvalidTransactionException, RemoteException
RM
customer
return a string representation of reservations
queryReserved
in interface RM
context
- the transaction IDcustomer
- the customer ID
TransactionAbortedException
InvalidTransactionException
RemoteException
WC.queryItinerary(Transaction, Customer)
public int queryReservedPrice(Transaction context, Customer customer) throws TransactionAbortedException, InvalidTransactionException, RemoteException
RM
customer
owes
in this RM.
queryReservedPrice
in interface RM
context
- the transaction IDcustomer
- the customer ID
TransactionAbortedException
InvalidTransactionException
RemoteException
WC.queryItineraryPrice(Transaction, Customer)
public boolean reserve(Transaction context, Customer c, RID i) throws TransactionAbortedException, InvalidTransactionException, RemoteException
RM
i
on behalf of customer c
reserve
in interface RM
context
- the transaction IDc
- the customer IDi
- resource to reserve
true
on successful reservation. false
otherwise.
TransactionAbortedException
InvalidTransactionException
RemoteException
WC.reserveItinerary(Customer, String[], String, boolean, boolean)
public void unreserve(Transaction context, Customer c) throws TransactionAbortedException, InvalidTransactionException, RemoteException
RM
customer
unreserve
in interface RM
context
- the transaction IDc
- the customer ID
TransactionAbortedException
InvalidTransactionException
RemoteException
WC.cancelItinerary(Customer)
public String[] listResources(Transaction context, RID.Type type) throws TransactionAbortedException, InvalidTransactionException, RemoteException
RM
listResources
in interface RM
type
- listing resource type
resource name ',' available quantity ',' price
TransactionAbortedException
InvalidTransactionException
RemoteException
WC.listCars(Transaction)
,
WC.listFlights(Transaction)
,
WC.listRooms(Transaction)
public Customer[] listCustomers(Transaction context) throws TransactionAbortedException, InvalidTransactionException, RemoteException
RM
listCustomers
in interface RM
context
- the transaction ID
TransactionAbortedException
InvalidTransactionException
RemoteException
WC.listCustomers(Transaction)
public void shutdown() throws RemoteException
CSEP545Service
Registry.unbind(String)
shutdown
in interface CSEP545Service
shutdown
in class CSEP545ServiceObject
RemoteException
Registry.unbind(String)
public void selfDestruct(int diskWritesToWait) throws RemoteException
RM
selfDestruct
in interface RM
diskWritesToWait
- number of disk writes to wait until terminate
RemoteException
public String getName() throws RemoteException
RM
getName
in interface RM
RemoteException
protected void init(String[] args) throws Exception
CSEP545ServiceObject
init
in class CSEP545ServiceObject
args
- command line arguments except common arguments
Exception
selfDestruct(int)
hereprotected void initStorage() throws Exception
CSEP545ServiceObject
RM
and commit log file for TM
initStorage
in class CSEP545ServiceObject
Exception
protected void recovery() throws Exception
CSEP545ServiceObject
recovery
in class CSEP545ServiceObject
Exception
protected void startUp() throws Exception
CSEP545ServiceObject
startUp
in class CSEP545ServiceObject
Exception
protected void readyToServe() throws Exception
CSEP545ServiceObject
readyToServe
in class CSEP545ServiceObject
Exception
public void refresh() throws RemoteException, NotBoundException
CSEP545Service
refresh
in interface CSEP545Service
RemoteException
NotBoundException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |