ParkNPark.client
Class FaultTolerantClientManager

java.lang.Object
  extended by ParkNPark.client.FaultTolerantClientManager
All Implemented Interfaces:
ClientManagerOperations

public class FaultTolerantClientManager
extends Object
implements ClientManagerOperations

Fault tolerant client manager that wraps a remote ClientManager and rolls over to a new primary server in the presence of failures. Note that this class is not multi-thread safe. Multiple threads should synchronize access or wrap this class with a thread-safe delegate.


Nested Class Summary
protected  class FaultTolerantClientManager.ReturnValueOrException
          Return value or an exception along with the return value or the exception object.
 
Field Summary
protected  int clientID
          The server-generated client ID
protected static Method closeClientManager
           
protected static Method enterLot
           
protected static Method exitLot
           
protected static Method getClientID
           
protected static Method getCurrentLevel
           
protected static Method getLots
           
protected static Method getMaxLevel
           
protected static Method getMinLevel
           
protected static Method getOtherLotAvailability
           
protected static PrintStream inputEater
          Shared static instance of the input eater output stream wrapped in a PrintStream
protected static Method moveDownLevel
           
protected static Method moveUpLevel
           
protected  NamingContextExt nameServer
          Our name server instance
protected  ORB orb
          Our object request broker
protected  NamingContext parkNParkContext
          Our naming service's ParkNPark context, which contains server registrations
protected  ClientManager primaryClientManager
          The primary client manager
protected  int seq
          The latest sequence number from the client
protected static String unexpectedException
          Message for unexpected exceptions that arise during remote method calls (non-IDL and non-CORBA exceptions)
 
Constructor Summary
FaultTolerantClientManager(ORB orb)
          Creates a new fault-tolerant client manager that automatically fails over to new primary servers on method call failures
 
Method Summary
protected  FaultTolerantClientManager.ReturnValueOrException callServer(Method method, Object... arguments)
          Calls the given method on the server with the given arguments and returns a ReturnValueOrException object to indicate a normal or exceptional result and contain the return value or the exception object.
 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
 int[] 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
 void exitLot(int seq)
          Removes the client's car from the lot that it is currently in
 int getClientID()
          Returns the client's ID, which can be used in the client manager factory's getExistingClientManager() method
 int getCurrentLevel()
          Returns the car's current level number
 int[] getLots()
          Returns an array of valid lot numbers in the system, sorted by the lot number in ascending order
 int getMaxLevel()
          Returns the top level number of the car's current parking lot
 int getMinLevel()
          Returns the bottom level number of the car's current parking lot
 int[] getOtherLotAvailability(int lot)
          Returns an array of other lots that have availability, sorted by lot distance such that closer lots are listed first
protected  boolean getPrimaryServer()
          Refreshes the primary server that is registered in the name service
 int moveDownLevel(int seq)
          Moves the car from its present level to the level beneath it
 int moveUpLevel(int seq)
          Moves the car from its present level to the level above it
protected  boolean refreshParkNParkContext()
          Refreshes the parkNParkContext name service object that we use to get server bindings on.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parkNParkContext

protected NamingContext parkNParkContext
Our naming service's ParkNPark context, which contains server registrations


primaryClientManager

protected ClientManager primaryClientManager
The primary client manager


nameServer

protected NamingContextExt nameServer
Our name server instance


seq

protected int seq
The latest sequence number from the client


clientID

protected int clientID
The server-generated client ID


orb

protected ORB orb
Our object request broker


getClientID

protected static final Method getClientID

enterLot

protected static final Method enterLot

exitLot

protected static final Method exitLot

getOtherLotAvailability

protected static final Method getOtherLotAvailability

getLots

protected static final Method getLots

moveUpLevel

protected static final Method moveUpLevel

moveDownLevel

protected static final Method moveDownLevel

getCurrentLevel

protected static final Method getCurrentLevel

getMaxLevel

protected static final Method getMaxLevel

getMinLevel

protected static final Method getMinLevel

closeClientManager

protected static final Method closeClientManager

unexpectedException

protected static final String unexpectedException
Message for unexpected exceptions that arise during remote method calls (non-IDL and non-CORBA exceptions)

See Also:
Constant Field Values

inputEater

protected static PrintStream inputEater
Shared static instance of the input eater output stream wrapped in a PrintStream

Constructor Detail

FaultTolerantClientManager

public FaultTolerantClientManager(ORB orb)
                           throws ServiceUnavailableException
Creates a new fault-tolerant client manager that automatically fails over to new primary servers on method call failures

Parameters:
orb - The object request broker instance to use
Throws:
ServiceUnavailableException - Thrown when a primary server could not be located or contacted
Method Detail

callServer

protected FaultTolerantClientManager.ReturnValueOrException callServer(Method method,
                                                                       Object... arguments)
Calls the given method on the server with the given arguments and returns a ReturnValueOrException object to indicate a normal or exceptional result and contain the return value or the exception object. If server communication or service unavailability exceptions arise, this method will automatically fail over to the new primary after that becomes available. Server communication and service unavailability exceptions are only returned if no primary server is registered

Parameters:
method - The method to call on our client manager on the primary server
arguments - The arguments to pass to the given method's parameters
Returns:
A ReturnValueOrException indicating a normal or exceptional result

getPrimaryServer

protected boolean getPrimaryServer()
Refreshes the primary server that is registered in the name service

Returns:
True if the primary server reference is refreshed or false if it could not be refreshed

refreshParkNParkContext

protected boolean refreshParkNParkContext()
Refreshes the parkNParkContext name service object that we use to get server bindings on. The name service is contacted from scratch in this method

Returns:
True if the parkNParkContext was refreshed or false if it was not

getClientID

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

Specified by:
getClientID in interface ClientManagerOperations
Returns:
The client's ID

enterLot

public int[] 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

Specified by:
enterLot in interface ClientManagerOperations
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 [Category: Baseline; Requirements: 1, 2, and 3]
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 void exitLot(int seq)
             throws NotInLotException,
                    NotOnExitLevelException,
                    ServiceUnavailableException
Removes the client's car from the lot that it is currently in

Specified by:
exitLot in interface ClientManagerOperations
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 [Category: Baseline; Requirement: 7]

getOtherLotAvailability

public int[] 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

Specified by:
getOtherLotAvailability in interface ClientManagerOperations
Parameters:
lot - The lot to get lot distances from
Returns:
An array of other lots that have availability [Category: Baseline; Requirement: 4]
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

getLots

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

Specified by:
getLots in interface ClientManagerOperations
Returns:
An array of valid lot numbers in the system [Category: Baseline; Requirement: 12]
Throws:
ServiceUnavailableException - Thrown if the database cannot be contacted or if some other reason prevents the system from discovering the its defined lots

moveUpLevel

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

Specified by:
moveUpLevel in interface ClientManagerOperations
Parameters:
seq - The latest sequence number of the client
Returns:
The level number that the client's car is now on [Category: Baseline; Requirement: 6]
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

moveDownLevel

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

Specified by:
moveDownLevel in interface ClientManagerOperations
Parameters:
seq - The latest sequence number of the client
Returns:
The level number that the client's car is now on [Category: Baseline; Requirement: 6]
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

getCurrentLevel

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

Specified by:
getCurrentLevel in interface ClientManagerOperations
Returns:
The car's current level number [Category: Baseline; Requirement: 6]
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

getMaxLevel

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

Specified by:
getMaxLevel in interface ClientManagerOperations
Returns:
The top level number of the car's current parking lot [Category: Baseline; Requirement: 6]
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 int getMinLevel()
                throws NotInLotException,
                       ServiceUnavailableException
Returns the bottom level number of the car's current parking lot

Specified by:
getMinLevel in interface ClientManagerOperations
Returns:
The bottom level number of the car's current parking lot [Category: Baseline; Requirement: 6]
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

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

Specified by:
closeClientManager in interface ClientManagerOperations
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