TaxiProject05.model
Class RMIServer

java.lang.Object
  extended by TaxiProject05.model.RMIServer
All Implemented Interfaces:
java.rmi.Remote, ModelInterface, TaxiCommunicationListener

public class RMIServer
extends java.lang.Object
implements TaxiCommunicationListener, ModelInterface

Author:
kalle

Method Summary
 void abortDrive(java.lang.String regnr, int driveId)
          A drive is aborted, either if it's a booked drive where the customer didn't show up or if it's a started drive where the customer ran away.
 int addBooking(DriveScheduleEntry driveEntry)
          This is the actuall add booking method.
 void addCustomer(ContractCustomer customer)
           
 int addCustomer(java.lang.String name, java.lang.String phoneNr, Address address)
          When adding a customer to the register
 void addTaxi(java.lang.String regnr)
           
 int changeBooking(int driveID, java.util.Date startTime, Route route, Customer customer, int numPassengers)
          When you want to change a booking.
 void endedDrive(java.lang.String regnr, int driveId, double distance, Position endpos, java.util.Date startTime, java.util.Date endTime, double price, PaymentMethod paymentMethod, boolean isPayed)
          Event is raised when a taxi has finished a drive.
 java.util.Set<Address> FindAddress(java.lang.String address)
           
 Customer findCustomer(int customerNr)
          if you want to find a specific customer
 Drive findDrive(int driveID)
          Finds the wanted drive given a driveID
 AddressRegister getAddressRegister()
           
 java.util.Map<java.lang.Integer,ContractCustomer> getAllCustomers()
          A method which gets all the customers from the Customer register and returns them.
 java.util.Date getCurrentDate()
           
 Route getCurrentRoute(java.lang.String regNr)
           
 CustomerRegister getCustomerRegister()
           
 DriveSchedule getDriveSchedule()
           
static ModelInterface getInst()
           
 Position getPosition(java.lang.String regnr)
           
 java.util.LinkedList<DriveScheduleEntry> getSchedule(Taxi t)
           
 SimTime getSimeTime()
           
 TaxiStatus getStatus(java.lang.String regnr)
          Happens every time a Taxi changes status.
 java.util.List<Taxi> getTaxiList()
           
 TaxiRegister getTaxiRegister()
           
 void loggedIn(java.lang.String regnr, int driverId)
           
 void loggedOut(java.lang.String regnr)
          Event is sent when the taxi is parked.
static void main(java.lang.String[] args)
           
 boolean modifyCustomer(int customerNr, java.lang.String name, java.lang.String phoneNumber, Address address)
          When changing some data of the customer
 void removeCustomer(int customerNr)
          Removes the customer with the given customerNR
 void removeDrive(int driveID)
          Remove a drive given the driveID
 java.util.List<DriveScheduleEntry> requestSuitableTaxis(java.util.Date startTime, Route route, Customer customer, int numPassengers)
          This method finds all suiteble taxis for the given drive.
 void serve()
           
 void startedBookedDrive(java.lang.String regnr, int driveId, Position startpos, java.util.Date startTime)
          A customer is picked up on the street and a prebookd drive is started.
 int startedNewDrive(java.lang.String regnr, Route route, java.util.Date startTime, Customer customer, int numPassengers)
          Is ran when a taxi picks up a person on the street.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInst

public static ModelInterface getInst()

addBooking

public int addBooking(DriveScheduleEntry driveEntry)
This is the actuall add booking method. This is called when you add a booking

Specified by:
addBooking in interface ModelInterface
Parameters:
startTime - for the drive
route - the route for the drive
customer - the customer for the drive
numPassengers - for the drive
Returns:
the driver ID or -1 if no booking added

requestSuitableTaxis

public java.util.List<DriveScheduleEntry> requestSuitableTaxis(java.util.Date startTime,
                                                               Route route,
                                                               Customer customer,
                                                               int numPassengers)
This method finds all suiteble taxis for the given drive.

Specified by:
requestSuitableTaxis in interface ModelInterface
Parameters:
drive - The current
nowBooking - if the booking is within MinForBooking
Returns:
A list of DriveScheduleEntrys

loggedIn

public void loggedIn(java.lang.String regnr,
                     int driverId)
Specified by:
loggedIn in interface TaxiCommunicationListener

loggedOut

public void loggedOut(java.lang.String regnr)
Event is sent when the taxi is parked.

Specified by:
loggedOut in interface TaxiCommunicationListener
Parameters:
regnr - Identify the car.

startedNewDrive

public int startedNewDrive(java.lang.String regnr,
                           Route route,
                           java.util.Date startTime,
                           Customer customer,
                           int numPassengers)
Is ran when a taxi picks up a person on the street.

Specified by:
startedNewDrive in interface TaxiCommunicationListener
Parameters:
regnr - Idenifiys the car
startpos - The position of the pickup
startTime - The real starttime for the pickup.
customer - If it's a formely known customer this is set to that customer, or else it's null.
Returns:
The DriveId assigned by the system.

startedBookedDrive

public void startedBookedDrive(java.lang.String regnr,
                               int driveId,
                               Position startpos,
                               java.util.Date startTime)
A customer is picked up on the street and a prebookd drive is started.

Specified by:
startedBookedDrive in interface TaxiCommunicationListener
Parameters:
regnr - Idenifiys the car
driveId - The booked drive's id.
startpos - The position where it started
startTime - The taxi time when it started.

endedDrive

public void endedDrive(java.lang.String regnr,
                       int driveId,
                       double distance,
                       Position endpos,
                       java.util.Date startTime,
                       java.util.Date endTime,
                       double price,
                       PaymentMethod paymentMethod,
                       boolean isPayed)
Event is raised when a taxi has finished a drive. Submits drive and payment information.

Specified by:
endedDrive in interface TaxiCommunicationListener
Parameters:
regnr - Idenifiys the car
driveId - The id for the drive
distance - The distance that have been driven.
endpos - The final position.
driveTime - The time it took
price - The price to pay (calculated by the taxameter)
paymentMethod - The way of payment.
isPayed - If it's payed or not.

abortDrive

public void abortDrive(java.lang.String regnr,
                       int driveId)
A drive is aborted, either if it's a booked drive where the customer didn't show up or if it's a started drive where the customer ran away.

Specified by:
abortDrive in interface TaxiCommunicationListener
Parameters:
regnr - Id to the car.
driveId - The drive Id.

getStatus

public TaxiStatus getStatus(java.lang.String regnr)
Happens every time a Taxi changes status. This event fires every time the status of the taxi changes. It also fires even when an other type of event is fired even if that implies that the status is changed. It's fired AFTER the change has occured.

Specified by:
getStatus in interface ModelInterface
Parameters:
regnr - Car identification
oldStatus - The previous status
newStatus - The new set status (this will be the current status when the event is fired)

getPosition

public Position getPosition(java.lang.String regnr)
Specified by:
getPosition in interface ModelInterface

addTaxi

public void addTaxi(java.lang.String regnr)

findDrive

public Drive findDrive(int driveID)
Description copied from interface: ModelInterface
Finds the wanted drive given a driveID

Specified by:
findDrive in interface ModelInterface
Parameters:
driveID - The driveId for the wanted drive
Returns:
the drive if found or null

removeDrive

public void removeDrive(int driveID)
Description copied from interface: ModelInterface
Remove a drive given the driveID

Specified by:
removeDrive in interface ModelInterface
Parameters:
driveID - the driveId for the drive you want to remove

changeBooking

public int changeBooking(int driveID,
                         java.util.Date startTime,
                         Route route,
                         Customer customer,
                         int numPassengers)
Description copied from interface: ModelInterface
When you want to change a booking.

Specified by:
changeBooking in interface ModelInterface
Parameters:
driveID - the id for the drive
startTime - the new wanted startTime for the drive
route - The new route for the drive
customer - customer for the drive
numPassengers - new nrOf passangers for the drive
Returns:
the driveId or -1 if not changeble

addCustomer

public int addCustomer(java.lang.String name,
                       java.lang.String phoneNr,
                       Address address)
Description copied from interface: ModelInterface
When adding a customer to the register

Specified by:
addCustomer in interface ModelInterface
Parameters:
name - The name of the customer
phoneNr - the phoneNumber of the customer
address - The address connected to the customers invoices
Returns:
the new CustomerNumber

addCustomer

public void addCustomer(ContractCustomer customer)

findCustomer

public Customer findCustomer(int customerNr)
Description copied from interface: ModelInterface
if you want to find a specific customer

Specified by:
findCustomer in interface ModelInterface
Parameters:
customerNr - the customerNR
Returns:
the customer or null if the customer doesn't exists.

removeCustomer

public void removeCustomer(int customerNr)
Description copied from interface: ModelInterface
Removes the customer with the given customerNR

Specified by:
removeCustomer in interface ModelInterface
Parameters:
customerNr - the customerNr of the customer

modifyCustomer

public boolean modifyCustomer(int customerNr,
                              java.lang.String name,
                              java.lang.String phoneNumber,
                              Address address)
Description copied from interface: ModelInterface
When changing some data of the customer

Specified by:
modifyCustomer in interface ModelInterface
Parameters:
customerNr - the customerNR
name - The name of the customer
phoneNumber - the phoneNumber of the customer
address - The address connected to the customers invoices
Returns:
true if customer was modified else false

getTaxiRegister

public TaxiRegister getTaxiRegister()

getCustomerRegister

public CustomerRegister getCustomerRegister()

getDriveSchedule

public DriveSchedule getDriveSchedule()

getSimeTime

public SimTime getSimeTime()

main

public static void main(java.lang.String[] args)

serve

public void serve()

getAddressRegister

public AddressRegister getAddressRegister()

getTaxiList

public java.util.List<Taxi> getTaxiList()
                                 throws java.rmi.RemoteException
Specified by:
getTaxiList in interface ModelInterface
Throws:
java.rmi.RemoteException

getSchedule

public java.util.LinkedList<DriveScheduleEntry> getSchedule(Taxi t)
                                                     throws java.rmi.RemoteException
Specified by:
getSchedule in interface ModelInterface
Throws:
java.rmi.RemoteException

getCurrentDate

public java.util.Date getCurrentDate()
                              throws java.rmi.RemoteException
Specified by:
getCurrentDate in interface ModelInterface
Throws:
java.rmi.RemoteException

FindAddress

public java.util.Set<Address> FindAddress(java.lang.String address)
                                   throws java.rmi.RemoteException
Specified by:
FindAddress in interface ModelInterface
Throws:
java.rmi.RemoteException

getCurrentRoute

public Route getCurrentRoute(java.lang.String regNr)
                      throws java.rmi.RemoteException
Specified by:
getCurrentRoute in interface ModelInterface
Throws:
java.rmi.RemoteException

getAllCustomers

public java.util.Map<java.lang.Integer,ContractCustomer> getAllCustomers()
A method which gets all the customers from the Customer register and returns them.

Specified by:
getAllCustomers in interface ModelInterface
Returns:
Map