|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttransaction.ResourceManagerImpl
public class ResourceManagerImpl
Field Summary |
---|
Fields inherited from interface transaction.IResourceManager |
---|
RMI_NAME_CAR_RM, RMI_NAME_FLIGHT_RM, RMI_NAME_HOTEL_RM |
Constructor Summary | |
---|---|
ResourceManagerImpl()
|
Method Summary | |
---|---|
void |
abort(int xid)
Abort transaction. |
boolean |
addResource(int xid,
java.lang.String rid,
int num,
int price)
Add a new resource (e.g. hotel) to the database. |
int |
begin()
|
boolean |
beginDistributed(int globalXID)
Begin a new distributed transaction. |
boolean |
commit(int xid)
Commit transaction. |
void |
dieAfterPointerSwitch()
Closes ResourceManager by calling System.exit(-1) right after switching the pointer to the shadow copy file. |
void |
dieBeforePointerSwitch()
Closes ResourceManager by calling System.exit(-1) right before switching the pointer to the shadow copy file. |
void |
dieNow()
immediately closes the ResourceManager by calling System.exit(-1) |
boolean |
newCustomer(int xid,
java.lang.String custName)
Add a new customer to database. |
boolean |
prepare(int globalXID)
This method is part of the 2PC protocol for atomic committment of distributed transactions. |
int |
queryCustomerBill(int xid,
java.lang.String custName)
Query the bill of a customer. |
int |
queryResourceAvailability(int xid,
java.lang.String rid)
Query the availability of a resource. |
int |
queryResourcePrice(int xid,
java.lang.String rid)
Query the price of a resource. |
boolean |
reserveResource(int xid,
java.lang.String rid,
java.lang.String custName)
Reserve a resource for a given customer. |
boolean |
shutdown()
Shutdown gracefully. |
void |
start(java.lang.String workingdir,
java.lang.String rmiName)
|
boolean |
updateResource(int xid,
java.lang.String rid,
int num,
int price)
Update the attributes (total capacity and price) of a resource. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ResourceManagerImpl() throws java.io.IOException
java.io.IOException
Method Detail |
---|
public void start(java.lang.String workingdir, java.lang.String rmiName) throws java.rmi.RemoteException
start
in interface IResourceManager
java.rmi.RemoteException
public void abort(int xid) throws InvalidTransactionException
IResourceManager
abort
in interface IResourceManager
xid
- id of transaction to be aborted.
InvalidTransactionException
- if transaction id is invalid.public int begin() throws ShutdownException
begin
in interface IResourceManager
ShutdownException
- thrown if no new transactions can be accepted
due to shutdown of the resource managerpublic boolean beginDistributed(int globalXID) throws ShutdownException, java.rmi.RemoteException, InvalidTransactionException
IResourceManager
beginDistributed
in interface IResourceManager
globalXID
- the id of the distributed transaction which
will be the parent of this local subtransaction. Use this id to
enlist this RM at the transaction manager.
ShutdownException
- thrown if no new transactions can be accepted
due to shutdown of the resource manager
InvalidTransactionException
- if a distributed transaction with
this globalXID has already been started at this RM
java.rmi.RemoteException
public boolean prepare(int globalXID) throws InvalidTransactionException, java.rmi.RemoteException
IResourceManager
prepare
in interface IResourceManager
globalXID
- the transaction ID of the distributed transaction
which needs to be prepared for commitment
InvalidTransactionException
java.rmi.RemoteException
public boolean commit(int xid) throws TransactionAbortedException, InvalidTransactionException
IResourceManager
commit
in interface IResourceManager
xid
- id of transaction to be committed.
TransactionAbortedException
- if transaction was aborted.
InvalidTransactionException
- if transaction id is invalid.public boolean shutdown()
IResourceManager
shutdown
in interface IResourceManager
public boolean newCustomer(int xid, java.lang.String custName) throws TransactionAbortedException, InvalidTransactionException
newCustomer
in interface IResourceManager
xid
- id of transaction.custName
- name of customer.
java.rmi.RemoteException
- on communications failure.
TransactionAbortedException
- if transaction was aborted.
InvalidTransactionException
- if transaction id is invalid.public int queryCustomerBill(int xid, java.lang.String custName) throws TransactionAbortedException, InvalidTransactionException
IResourceManager
queryCustomerBill
in interface IResourceManager
xid
- the id of the transaction requesting this operationcustName
- the unique customer name whose bill should be calculated
TransactionAbortedException
- if transaction was aborted.
InvalidTransactionException
- if transaction id is invalid.public boolean addResource(int xid, java.lang.String rid, int num, int price) throws TransactionAbortedException, InvalidTransactionException
IResourceManager
addResource
in interface IResourceManager
xid
- the id of the transaction requesting this operationrid
- the unique identifier of the resource which is to be added (e.g. HotelA)num
- the total capacity of this resourceprice
- the price a customer needs to pay for reserving this resource
TransactionAbortedException
- if transaction was aborted.
InvalidTransactionException
- if transaction id is invalid.public boolean updateResource(int xid, java.lang.String rid, int num, int price) throws TransactionAbortedException, InvalidTransactionException
IResourceManager
updateResource
in interface IResourceManager
xid
- the id of the transaction requesting this operationrid
- the unique identifier of the resource which is to be added (e.g. HotelA)num
- a number indicating the change in total capacity, negative numbers decrease
capacity, positive values increase capacityprice
- the price a customer needs to pay for reserving this resource
TransactionAbortedException
- if transaction was aborted.
InvalidTransactionException
- if transaction id is invalid.public int queryResourceAvailability(int xid, java.lang.String rid) throws TransactionAbortedException, InvalidTransactionException
IResourceManager
queryResourceAvailability
in interface IResourceManager
xid
- the id of the transaction requesting this operationrid
- the unique identifier of the resource
TransactionAbortedException
- if transaction was aborted.
InvalidTransactionException
- if transaction id is invalid.public int queryResourcePrice(int xid, java.lang.String rid) throws TransactionAbortedException, InvalidTransactionException
IResourceManager
queryResourcePrice
in interface IResourceManager
xid
- the id of the transaction requesting this operationrid
- the unique identifier of the resource
TransactionAbortedException
- if transaction was aborted.
InvalidTransactionException
- if transaction id is invalid.public boolean reserveResource(int xid, java.lang.String rid, java.lang.String custName) throws TransactionAbortedException, InvalidTransactionException
IResourceManager
reserveResource
in interface IResourceManager
xid
- the id of the transaction requesting this operationrid
- the unique identifier of the resourcecustName
- the unique name of the customer
TransactionAbortedException
- if transaction was aborted.
InvalidTransactionException
- if transaction id is invalid.public void dieNow()
IResourceManager
dieNow
in interface IResourceManager
public void dieBeforePointerSwitch()
IResourceManager
dieBeforePointerSwitch
in interface IResourceManager
public void dieAfterPointerSwitch()
IResourceManager
dieAfterPointerSwitch
in interface IResourceManager
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |