tp.impl
Class MyWC

java.lang.Object
  extended by tp.impl.CSEP545ServiceObject
      extended by tp.impl.MyWC
All Implemented Interfaces:
Remote, CSEP545Service, WC

public class MyWC
extends CSEP545ServiceObject
implements WC

Your Workflow Controller. Rudimentary implementation is provided for your convenience.


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
MyWC()
           
 
Method Summary
 void abort(Transaction context)
          Abort a transaction
 boolean addCars(Transaction context, String location, int numCars, int price)
          Add cars to a location.
 boolean addRooms(Transaction context, String location, int numRooms, int price)
          Add rooms to a location.
 boolean addSeats(Transaction context, String flight, int flightSeats, int flightPrice)
          Add seats to a flight This method will be used to create a new flight but if the flight already exists, seats will be added and the price overwritten
 boolean cancelItinerary(Customer customer)
          Cancel an itinerary owned by customer
 void commit(Transaction context)
          Commit a transaction
 boolean deleteCars(Transaction context, String location, int numCars)
          Delete cars.
 boolean deleteFlight(Transaction context, String flight)
          Delete the entire flight.
 boolean deleteRooms(Transaction context, String location, int numRooms)
          Delete rooms.
 boolean deleteSeats(Transaction context, String flight, int numSeats)
          delete seats from a flight
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.
 String[] listCars(Transaction context)
          list existing cars
 Customer[] listCustomers(Transaction context)
          list existing customers that have itinerary
 String[] listFlights(Transaction context)
          list existing flights
 String[] listRooms(Transaction context)
          list existing rooms
 int queryCar(Transaction context, String location)
          Get the number of cars available.
 int queryCarPrice(Transaction context, String location)
          Get the cars price.
 int queryFlight(Transaction context, String flight)
          Get the number of seats available.
 int queryFlightPrice(Transaction context, String flight)
          Get the flight price.
 String queryItinerary(Transaction context, Customer customer)
          Get the bill for the customer
 int queryItineraryPrice(Transaction context, Customer customer)
          Get the total amount of money the customer owes
 int queryRoom(Transaction context, String location)
          Get the number of rooms available.
 int queryRoomPrice(Transaction context, String location)
          Get the room price.
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()
          IMPLEMENT THIS METHOD if you want to implement a different service architecture.
 boolean reserveItinerary(Customer customer, String[] flights, String location, boolean car, boolean room)
          Reserve an itinerary
 Transaction start()
          Start a transaction return a unique transaction ID
protected  void startUp()
          IMPLEMENT THIS METHOD If you use extra threads in your service, start them in this method.
 
Methods inherited from class tp.impl.CSEP545ServiceObject
getDataRoot, getServiceID, kill, lookupRemote, lookupRemote, lookupRemote, lookupRemote, main, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MyWC

public MyWC()
Method Detail

reserveItinerary

public boolean reserveItinerary(Customer customer,
                                String[] flights,
                                String location,
                                boolean car,
                                boolean room)
                         throws RemoteException
Description copied from interface: WC
Reserve an itinerary

Specified by:
reserveItinerary in interface WC
Parameters:
customer - the customer
flights - an integer array of flight numbers
location - travel location
car - true if car reservation is needed
room - true if a room reservation is needed
Returns:
true on success, false otherwise.
Throws:
RemoteException
See Also:
RM.reserve(Transaction, Customer, RID)

cancelItinerary

public boolean cancelItinerary(Customer customer)
                        throws RemoteException
Description copied from interface: WC
Cancel an itinerary owned by customer

Specified by:
cancelItinerary in interface WC
Parameters:
customer - the customer
Returns:
true on success, false otherwise.
Throws:
RemoteException
See Also:
RM.unreserve(Transaction, Customer)

queryItineraryPrice

public int queryItineraryPrice(Transaction context,
                               Customer customer)
                        throws RemoteException,
                               TransactionAbortedException,
                               InvalidTransactionException
Description copied from interface: WC
Get the total amount of money the customer owes

Specified by:
queryItineraryPrice in interface WC
Parameters:
context - the transaction ID
customer - the customer ID
Returns:
total price of reservations
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.queryReserved(Transaction, Customer)

queryItinerary

public String queryItinerary(Transaction context,
                             Customer customer)
                      throws RemoteException,
                             TransactionAbortedException,
                             InvalidTransactionException
Description copied from interface: WC
Get the bill for the customer

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

addSeats

public boolean addSeats(Transaction context,
                        String flight,
                        int flightSeats,
                        int flightPrice)
                 throws RemoteException,
                        TransactionAbortedException,
                        InvalidTransactionException
Description copied from interface: WC
Add seats to a flight This method will be used to create a new flight but if the flight already exists, seats will be added and the price overwritten

Specified by:
addSeats in interface WC
Parameters:
context - the transaction ID
flight - a flight number
flightSeats - the number of flight Seats
flightPrice - price per seat
Returns:
true on success, false otherwise.
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.add(Transaction, RID, int, int)

deleteSeats

public boolean deleteSeats(Transaction context,
                           String flight,
                           int numSeats)
                    throws RemoteException,
                           TransactionAbortedException,
                           InvalidTransactionException
Description copied from interface: WC
delete seats from a flight

Specified by:
deleteSeats in interface WC
Parameters:
context - the transaction ID
flight - a flight number
numSeats - the number of flight Seats
Returns:
true on success, false otherwise.
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.delete(Transaction,RID,int)

deleteFlight

public boolean deleteFlight(Transaction context,
                            String flight)
                     throws RemoteException,
                            TransactionAbortedException,
                            InvalidTransactionException
Description copied from interface: WC
Delete the entire flight. deleteFlight implies whole deletion of the flight, all seats, all reservations.

Specified by:
deleteFlight in interface WC
Parameters:
context - the transaction ID
flight - the flight number
Returns:
true on success, false otherwise.
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.delete(Transaction,RID)

addRooms

public boolean addRooms(Transaction context,
                        String location,
                        int numRooms,
                        int price)
                 throws RemoteException,
                        TransactionAbortedException,
                        InvalidTransactionException
Description copied from interface: WC
Add rooms to a location. This should look a lot like addFlight, only keyed on a string location instead of a flight number.

Specified by:
addRooms in interface WC
Parameters:
context - the transaction ID
location - the location to add rooms
numRooms - number of rooms to add
price - room price
Returns:
true on success, false otherwise.
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.add(Transaction, RID, int, int)

deleteRooms

public boolean deleteRooms(Transaction context,
                           String location,
                           int numRooms)
                    throws RemoteException,
                           TransactionAbortedException,
                           InvalidTransactionException
Description copied from interface: WC
Delete rooms.

Specified by:
deleteRooms in interface WC
Parameters:
context - the transaction ID
location - the location to add rooms
numRooms - the number of rooms to delete
Returns:
true on success, false otherwise.
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.delete(Transaction,RID,int)

addCars

public boolean addCars(Transaction context,
                       String location,
                       int numCars,
                       int price)
                throws RemoteException,
                       TransactionAbortedException,
                       InvalidTransactionException
Description copied from interface: WC
Add cars to a location. This should look a lot like addFlight, only keyed on a string location instead of a flight number.

Specified by:
addCars in interface WC
Parameters:
context - the transaction ID
location - the location to add cars
numCars - number of cars to add
price - rental price
Returns:
true on success, false otherwise.
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.add(Transaction, RID, int, int)

deleteCars

public boolean deleteCars(Transaction context,
                          String location,
                          int numCars)
                   throws RemoteException,
                          TransactionAbortedException,
                          InvalidTransactionException
Description copied from interface: WC
Delete cars.

Specified by:
deleteCars in interface WC
Parameters:
context - the transaction ID
location - the location to add cars
numCars - the number of cars to delete
Returns:
true on success, false otherwise.
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.delete(Transaction,RID,int)

queryFlight

public int queryFlight(Transaction context,
                       String flight)
                throws RemoteException,
                       TransactionAbortedException,
                       InvalidTransactionException
Description copied from interface: WC
Get the number of seats available. return the number of seats available

Specified by:
queryFlight in interface WC
Parameters:
context - the transaction ID
flight - the flight number
Returns:
the number of seats available. negative value if the flight does not exists
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.query(Transaction, RID)

queryFlightPrice

public int queryFlightPrice(Transaction context,
                            String flight)
                     throws RemoteException,
                            TransactionAbortedException,
                            InvalidTransactionException
Description copied from interface: WC
Get the flight price. return the price

Specified by:
queryFlightPrice in interface WC
Parameters:
context - the transaction ID
flight - the flight number
Returns:
the price. Negative value if the flight does not exists
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.queryPrice(Transaction, RID)

queryRoom

public int queryRoom(Transaction context,
                     String location)
              throws RemoteException,
                     TransactionAbortedException,
                     InvalidTransactionException
Description copied from interface: WC
Get the number of rooms available. return the number of rooms available

Specified by:
queryRoom in interface WC
Parameters:
context - the transaction ID
location - the rooms location
Returns:
the number of rooms available
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.query(Transaction, RID)

queryRoomPrice

public int queryRoomPrice(Transaction context,
                          String location)
                   throws RemoteException,
                          TransactionAbortedException,
                          InvalidTransactionException
Description copied from interface: WC
Get the room price.

Specified by:
queryRoomPrice in interface WC
Parameters:
context - the transaction ID
location - the rooms location
Returns:
the price
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.queryPrice(Transaction, RID)

queryCar

public int queryCar(Transaction context,
                    String location)
             throws RemoteException,
                    TransactionAbortedException,
                    InvalidTransactionException
Description copied from interface: WC
Get the number of cars available.

Specified by:
queryCar in interface WC
Parameters:
context - the transaction ID
location - the cars location
Returns:
the number of cars available
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.query(Transaction, RID)

queryCarPrice

public int queryCarPrice(Transaction context,
                         String location)
                  throws RemoteException,
                         TransactionAbortedException,
                         InvalidTransactionException
Description copied from interface: WC
Get the cars price.

Specified by:
queryCarPrice in interface WC
Parameters:
context - the transaction ID
location - the cars location
Returns:
the price
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
RM.queryPrice(Transaction, RID)

listFlights

public String[] listFlights(Transaction context)
                     throws RemoteException,
                            TransactionAbortedException,
                            InvalidTransactionException
Description copied from interface: WC
list existing flights

Specified by:
listFlights in interface WC
Parameters:
context - transaction id
Returns:
list of existing flights
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
WC.addSeats(Transaction, String, int, int), RM.listResources(Transaction, RID.Type)

listCars

public String[] listCars(Transaction context)
                  throws RemoteException,
                         TransactionAbortedException,
                         InvalidTransactionException
Description copied from interface: WC
list existing cars

Specified by:
listCars in interface WC
Parameters:
context - transaction id
Returns:
list of existing cars
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
WC.addCars(Transaction, String, int, int), RM.listResources(Transaction, RID.Type)

listRooms

public String[] listRooms(Transaction context)
                   throws RemoteException,
                          TransactionAbortedException,
                          InvalidTransactionException
Description copied from interface: WC
list existing rooms

Specified by:
listRooms in interface WC
Parameters:
context - transaction id
Returns:
list of existing rooms
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
WC.addRooms(Transaction, String, int, int), RM.listResources(Transaction, RID.Type)

listCustomers

public Customer[] listCustomers(Transaction context)
                         throws RemoteException,
                                TransactionAbortedException,
                                InvalidTransactionException
Description copied from interface: WC
list existing customers that have itinerary

Specified by:
listCustomers in interface WC
Parameters:
context - transaction id
Returns:
list of existing customers that have itineraries
Throws:
RemoteException
TransactionAbortedException
InvalidTransactionException
See Also:
WC.reserveItinerary(Customer, String[], String, boolean, boolean), RM.listCustomers(Transaction)

start

public Transaction start()
                  throws RemoteException
Description copied from interface: WC
Start a transaction return a unique transaction ID

Specified by:
start in interface WC
Returns:
a new transaction identifier
Throws:
RemoteException

commit

public void commit(Transaction context)
            throws RemoteException,
                   InvalidTransactionException,
                   TransactionAbortedException
Description copied from interface: WC
Commit a transaction

Specified by:
commit in interface WC
Parameters:
context - the transaction ID
Throws:
RemoteException
InvalidTransactionException
TransactionAbortedException

abort

public void abort(Transaction context)
           throws RemoteException,
                  InvalidTransactionException
Description copied from interface: WC
Abort a transaction

Specified by:
abort in interface WC
Parameters:
context - the transaction ID
Throws:
RemoteException
InvalidTransactionException

init

protected void init(String[] args)
             throws Exception
Description copied from class: CSEP545ServiceObject
IMPLEMENT THIS METHOD process command line parameters and setup any parameterized values. For example, setting self destruct counter should be done in this method.

Specified by:
init in class CSEP545ServiceObject
Parameters:
args - command line arguments except common arguments
Throws:
Exception

initStorage

protected void initStorage()
                    throws Exception
Description copied from class: CSEP545ServiceObject
IMPLEMENT THIS METHOD Initialize necessary data files. Invoked in two cases. For example, you can create database files for RM and commit log file for TM

Specified by:
initStorage in class CSEP545ServiceObject
Throws:
Exception

recovery

protected void recovery()
                 throws Exception
Description copied from class: CSEP545ServiceObject
IMPLEMENT THIS METHOD Run recovery algorithm and reconstruct the state of service before failure. This method is invoked when the data directory already exists. Note that if the service has been shutdown cleanly, calling this method should not affect the state.

Specified by:
recovery in class CSEP545ServiceObject
Throws:
Exception

startUp

protected void startUp()
                throws Exception
Description copied from class: CSEP545ServiceObject
IMPLEMENT THIS METHOD If you use extra threads in your service, start them in this method. For example, you can launch periodic deadlock-detector thread here. Or, any kinds of asynchronous taks such as timeout-retry, failure detector, etc.

Specified by:
startUp in class CSEP545ServiceObject
Throws:
Exception

readyToServe

protected void readyToServe()
                     throws Exception
Description copied from class: CSEP545ServiceObject
IMPLEMENT THIS METHOD Bootstrapping completed and the server is up and running.

Specified by:
readyToServe in class CSEP545ServiceObject
Throws:
Exception

refresh

public void refresh()
             throws RemoteException,
                    NotBoundException
IMPLEMENT THIS METHOD if you want to implement a different service architecture.

Specified by:
refresh in interface CSEP545Service
Throws:
RemoteException
NotBoundException