ParkNPark.middletier
Class ClientManagerImpl

java.lang.Object
  extended by org.omg.PortableServer.Servant
      extended by ParkNPark.interfaces.ClientManagerPOA
          extended by ParkNPark.middletier.ClientManagerImpl
All Implemented Interfaces:
InvokeHandler, ClientManagerOperations

public class ClientManagerImpl
extends ClientManagerPOA

Server object that will manage communication between the client and the database.


Field Summary
protected  PreparedStatement checkDuplicate
          Statements used for duplicate message detection
protected  String clientHostname
          Client's hostname
protected  int clientID
          Client's ID used for fault-tolerance
protected  Connection conn
          Connection to the database
protected  DatabaseManager databaseManager
          Our database manager instance
protected static int INTEGER_SIZE
          Size of an intger variable
protected  byte[] integerPadding
          Byte array used to pad integer variables
protected  int level
          Level that client is in
protected  Logger logger
          Our Logger instance
protected  int lot
          Lot that client is in
protected static int MAX_ATTEMPTS
          Maximum number of attempts when trying to execute commends on database
protected  PaddedVoid paddedVoid
          PaddedVoid instance for padded void returns
protected static boolean PRINT_LEVELS_STATUS
           
protected static boolean PRINT_LOTS_STATUS
          Flags used to print out the status of lots and levels
protected  int replySize
          Size of replies
protected  int seq
          Client's current operation sequence number used for fault-tolerance
protected  PreparedStatement updateSequence
           
 
Constructor Summary
ClientManagerImpl(DatabaseManager databaseManager, int clientID, String clientHostname, Logger logger, int replySize)
          Create a client manager for an existing client that will hold information specific to the client.
ClientManagerImpl(DatabaseManager databaseManager, String clientHostname, Logger logger, int replySize)
          Create a client manager for a new client that will hold information specific to the client.
 
Method Summary
protected  boolean alreadyCompleted(int seq)
          Checks if the current client request has already been completed.
 void closeClientManager()
          Closes the client manager and frees server resources associated with it, including the client manager's activation in the server's CORBA portable object adapter
 PaddedIntegerSeq enterLot(int seq, int lot)
          Moves the client's car into the lot with the given lot number and returns an array of level numbers that have available spaces
 PaddedVoid exitLot(int seq)
          Removes the client's car from the lot that it is currently in
 PaddedInteger getClientID()
          Returns the client's ID, which can be used in the client manager factory's getExistingClientManager() method
 PaddedInteger getCurrentLevel()
          Returns the car's current level number
 PaddedIntegerSeq getLots()
          Returns an array of valid lot numbers in the system, sorted by the lot number in ascending order
 PaddedInteger getMaxLevel()
          Returns the top level number of the car's current parking lot
 PaddedInteger getMinLevel()
          Returns the bottom level number of the car's current parking lot
 PaddedIntegerSeq getOtherLotAvailability(int lot)
          Returns an array of other lots that have availability, sorted by lot distance such that closer lots are listed first
 PaddedInteger moveDownLevel(int seq)
          Moves the car from its present level to the level beneath it
 PaddedInteger moveUpLevel(int seq)
          Moves the car from its present level to the level above it
protected  PaddedInteger padInteger(int value)
          Pad the integer in order to make it comply with the reply size of the analysis
protected  PaddedIntegerSeq padIntegerArray(int[] value)
          Pad the integer array in order to make it comply with the reply size of the analysis
protected  PaddedVoid padVoid()
          Pad the void in order to make it comply with the reply size of the analysis
protected  void printLevelsStatus(String message, int seq)
          Print the status of all the levels in the current lot
protected  void printLotsStatus(String message, int seq)
          Print the status of all the lots
protected  void setupDatabaseConn()
          Set up the database connection
protected  void setupProbes(String clientHostname, Logger logger, int replySize)
          Setup probes for real-time analysis
protected  void updateClientData(int seq, int lot, int level)
          Updates the client table, which is used for duplicate detection.
 
Methods inherited from class ParkNPark.interfaces.ClientManagerPOA
_all_interfaces, _invoke, _this, _this
 
Methods inherited from class org.omg.PortableServer.Servant
_default_POA, _get_delegate, _get_interface_def, _is_a, _non_existent, _object_id, _orb, _poa, _set_delegate, _this_object, _this_object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_ATTEMPTS

protected static final int MAX_ATTEMPTS
Maximum number of attempts when trying to execute commends on database

See Also:
Constant Field Values

INTEGER_SIZE

protected static int INTEGER_SIZE
Size of an intger variable


integerPadding

protected byte[] integerPadding
Byte array used to pad integer variables


paddedVoid

protected PaddedVoid paddedVoid
PaddedVoid instance for padded void returns


PRINT_LOTS_STATUS

protected static final boolean PRINT_LOTS_STATUS
Flags used to print out the status of lots and levels

See Also:
Constant Field Values

PRINT_LEVELS_STATUS

protected static final boolean PRINT_LEVELS_STATUS
See Also:
Constant Field Values

databaseManager

protected DatabaseManager databaseManager
Our database manager instance


clientID

protected int clientID
Client's ID used for fault-tolerance


seq

protected int seq
Client's current operation sequence number used for fault-tolerance


lot

protected int lot
Lot that client is in


level

protected int level
Level that client is in


conn

protected Connection conn
Connection to the database


checkDuplicate

protected PreparedStatement checkDuplicate
Statements used for duplicate message detection


updateSequence

protected PreparedStatement updateSequence

clientHostname

protected String clientHostname
Client's hostname


replySize

protected int replySize
Size of replies


logger

protected Logger logger
Our Logger instance

Constructor Detail

ClientManagerImpl

public ClientManagerImpl(DatabaseManager databaseManager,
                         int clientID,
                         String clientHostname,
                         Logger logger,
                         int replySize)
                  throws ServiceUnavailableException,
                         InvalidClientException
Create a client manager for an existing client that will hold information specific to the client.

Parameters:
databaseManager - The database manager to use in this client manager
clientID - The ID of the client to restore this ClientManager instance from
clientHostname - The hostname of the client
logger - The Logger object to log performance data to
replySize - The size of the method return values to use for the current test
Throws:
ServiceUnavailableException - Thrown when a database exception prevented the client manager from being created successfully
InvalidClientException - Thrown when the given client ID does not exist in the database

ClientManagerImpl

public ClientManagerImpl(DatabaseManager databaseManager,
                         String clientHostname,
                         Logger logger,
                         int replySize)
                  throws ServiceUnavailableException
Create a client manager for a new client that will hold information specific to the client.

Parameters:
databaseManager - The database manager to use in this client manager
clientHostname - The hostname of the client
logger - The Logger object to log performance data to
replySize - The size of the method return values to use for the current test
Throws:
ServiceUnavailableException - Thrown when a database exception prevented the client manager from being created successfully
Method Detail

setupDatabaseConn

protected void setupDatabaseConn()
                          throws ServiceUnavailableException
Set up the database connection

Throws:
ServiceUnavailableException - Thrown if a problem came up while connecting to the database server or setting it up after connecting

setupProbes

protected void setupProbes(String clientHostname,
                           Logger logger,
                           int replySize)
Setup probes for real-time analysis

Parameters:
clientHostname -
numClients -
interRequestTime -
replySize -
serverHostname -

closeClientManager

public void closeClientManager()
                        throws ServiceUnavailableException
Closes the client manager and frees server resources associated with it, including the client manager's activation in the server's CORBA portable object adapter

Throws:
ServiceUnavailableException - Thrown if the database cannot be contacted or if some other reason prevents the system from closing the client manager. The client manager remains open if this exception gets thrown

enterLot

public PaddedIntegerSeq enterLot(int seq,
                                 int lot)
                          throws AlreadyInLotException,
                                 LotNotFoundException,
                                 LotFullException,
                                 ServiceUnavailableException
Moves the client's car into the lot with the given lot number and returns an array of level numbers that have available spaces

Parameters:
seq - The latest sequence number of the client
lot - The lot number to enter
Returns:
An array of level numbers that have available spaces
Throws:
AlreadyInLotException - Thrown when the client's car is already in a lot
LotNotFoundException - Thrown if the given lot number is not known to the system
LotFullException - Thrown if the given lot is full
ServiceUnavailableException - Thrown if the database cannot be contacted or if some other reason prevents the car from entering the lot

exitLot

public PaddedVoid exitLot(int seq)
                   throws NotInLotException,
                          NotOnExitLevelException,
                          ServiceUnavailableException
Removes the client's car from the lot that it is currently in

Parameters:
seq - The latest sequence number of the client
Throws:
NotInLotException - Thrown if the car is not in a lot
NotOnExitLevelException - Thrown if the car is in a lot but is not on a permitted exit level
ServiceUnavailableException - Thrown if the database cannot be contacted or if some other reason prevents the car from exiting the lot

getClientID

public PaddedInteger getClientID()
                          throws ServiceUnavailableException
Returns the client's ID, which can be used in the client manager factory's getExistingClientManager() method

Returns:
The client's ID
Throws:
ServiceUnavailableException - Thrown when the log is closed and the server is shutting down

getCurrentLevel

public PaddedInteger getCurrentLevel()
                              throws NotInLotException,
                                     ServiceUnavailableException
Returns the car's current level number

Returns:
The car's current level number
Throws:
NotInLotException - Thrown if the car is not in a lot
ServiceUnavailableException - Thrown if the database cannot be contacted or if some other reason prevents the system from returning the car's current level

getLots

public PaddedIntegerSeq getLots()
                         throws ServiceUnavailableException
Returns an array of valid lot numbers in the system, sorted by the lot number in ascending order

Returns:
An array of valid lot numbers in the system
Throws:
ServiceUnavailableException - Thrown if the database cannot be contacted or if some other reason prevents the system from discovering the its defined lots

getMaxLevel

public PaddedInteger getMaxLevel()
                          throws NotInLotException,
                                 ServiceUnavailableException
Returns the top level number of the car's current parking lot

Returns:
The top level number of the car's current parking lot
Throws:
NotInLotException - Thrown if the car is not in a lot
ServiceUnavailableException - Thrown if the database cannot be contacted or if some other reason prevents the system from returning the current lot's highest level

getMinLevel

public PaddedInteger getMinLevel()
                          throws NotInLotException,
                                 ServiceUnavailableException
Returns the bottom level number of the car's current parking lot

Returns:
The bottom level number of the car's current parking lot
Throws:
NotInLotException - Thrown if the car is not in a lot
ServiceUnavailableException - Thrown if the database cannot be contacted or if some other reason prevents the system from returning the current lot's lowest level

getOtherLotAvailability

public PaddedIntegerSeq getOtherLotAvailability(int lot)
                                         throws LotNotFoundException,
                                                ServiceUnavailableException
Returns an array of other lots that have availability, sorted by lot distance such that closer lots are listed first

Parameters:
lot - The lot to get lot distances from
Returns:
An array of other lots that have availability
Throws:
LotNotFoundException - Thrown if the given lot number is not known to the system
ServiceUnavailableException - Thrown if the database cannot be contacted or if some other reason prevents the system from discovering the availability of other lots

moveDownLevel

public PaddedInteger moveDownLevel(int seq)
                            throws NotInLotException,
                                   AtBottomLevelException,
                                   ServiceUnavailableException
Moves the car from its present level to the level beneath it

Parameters:
seq - The latest sequence number of the client
Returns:
The level number that the client's car is now on
Throws:
NotInLotException - Thrown if the car is not in a lot
AtTopLevelException - Thrown if the car is already on the lowest level
ServiceUnavailableException - Thrown if the database cannot be contacted or if some other reason prevents the car from moving to the lower level
AtBottomLevelException

moveUpLevel

public PaddedInteger moveUpLevel(int seq)
                          throws NotInLotException,
                                 AtTopLevelException,
                                 ServiceUnavailableException
Moves the car from its present level to the level above it

Parameters:
seq - The latest sequence number of the client
Returns:
The level number that the client's car is now on
Throws:
NotInLotException - Thrown if the car is not in a lot
AtTopLevelException - Thrown if the car is already on the highest level
ServiceUnavailableException - Thrown if the database cannot be contacted or if some other reason prevents the car from moving to the next highest level

alreadyCompleted

protected boolean alreadyCompleted(int seq)
                            throws ServiceUnavailableException
Checks if the current client request has already been completed.

Parameters:
seq -
Returns:
Throws:
ServiceUnavailableException

updateClientData

protected void updateClientData(int seq,
                                int lot,
                                int level)
                         throws ServiceUnavailableException
Updates the client table, which is used for duplicate detection.

Parameters:
seq -
lot -
level -
Throws:
ServiceUnavailableException

printLotsStatus

protected void printLotsStatus(String message,
                               int seq)
Print the status of all the lots

Parameters:
message - The message to display with the status
seq - The client request sequence number

printLevelsStatus

protected void printLevelsStatus(String message,
                                 int seq)
Print the status of all the levels in the current lot

Parameters:
message - The message to display with the status
seq - The client request sequence number

padIntegerArray

protected PaddedIntegerSeq padIntegerArray(int[] value)
Pad the integer array in order to make it comply with the reply size of the analysis

Parameters:
value -
Returns:
padded value

padInteger

protected PaddedInteger padInteger(int value)
Pad the integer in order to make it comply with the reply size of the analysis

Parameters:
value -
Returns:
padded value

padVoid

protected PaddedVoid padVoid()
Pad the void in order to make it comply with the reply size of the analysis

Returns:
padded void