ParkNPark.client
Class FaultTolerantClientManager.BackgroundThread

java.lang.Object
  extended by java.lang.Thread
      extended by ParkNPark.client.FaultTolerantClientManager.BackgroundThread
All Implemented Interfaces:
Runnable
Enclosing class:
FaultTolerantClientManager

protected class FaultTolerantClientManager.BackgroundThread
extends Thread

Background thread that performs the following actions in a loop continuously:

  1. Recover from a fault on the primary server if one was detected by either this thread or by the main thread
  2. Refresh the list of servers from the naming service
  3. Poke each server serially and, upon fault detection, remove that server from the list of servers. If that server was the primary server, then enter the fault recovery mode
  4. If the current primary server is no longer registered in the naming service, then enter the fault recovery mode
  5. Wait for the fault detection timeout time if no faults were detected in the current loop iteration
  6. This permits the server list to remain up-to-date, relevant, and accurate for quick failover. When a fault is detected, the affected server's entry is not used for at least five times the fault detection timeout to give the replication manager ample time to unregister its name if it really is down. This match is performed via IOR so that a faulty server that gets restarted can be used quickly after it becomes available


    Nested Class Summary
     
    Nested classes/interfaces inherited from class java.lang.Thread
    Thread.State, Thread.UncaughtExceptionHandler
     
    Field Summary
    protected  int detectionTimeout
              The fault detection timeout
    protected  boolean exit
              True when we should exit or false when we should not
    protected  SortedMap<Long,Server> faultyServers
              Map of fault detection times to their faulty servers
    protected  NameService nameService
              Our name server instance
    protected  int serverIndex
              The index of the current server in the list of servers
     
    Fields inherited from class java.lang.Thread
    MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
     
    Constructor Summary
    FaultTolerantClientManager.BackgroundThread(ORB orb, int detectionTimeout)
              Creates a new background thread instance
     
    Method Summary
     void beginExit()
              Tells this thread to gracefully shut down
    protected  boolean connectToAnyServer(LogEntry logEntry)
              Connects to any registered server, which is chosen randomly
    protected  boolean findPrimary()
              Finds the primary server in the List of servers and returns whether or not one was found
    protected  boolean initialConnection()
              Create the initial connection to a server and return whether or not it worked
    protected  void processFaultyServers()
              Maintains the faulty server list and removes them from the current set of servers.
     void run()
              Background thread's execution
     
    Methods inherited from class java.lang.Thread
    activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
     

    Field Detail

    nameService

    protected NameService nameService
    Our name server instance


    serverIndex

    protected int serverIndex
    The index of the current server in the list of servers


    detectionTimeout

    protected int detectionTimeout
    The fault detection timeout


    exit

    protected boolean exit
    True when we should exit or false when we should not


    faultyServers

    protected SortedMap<Long,Server> faultyServers
    Map of fault detection times to their faulty servers

    Constructor Detail

    FaultTolerantClientManager.BackgroundThread

    public FaultTolerantClientManager.BackgroundThread(ORB orb,
                                                       int detectionTimeout)
    Creates a new background thread instance

    Parameters:
    orb - The ORB to operate with
    detectionTimeout - The fault detection timeout to use
    Method Detail

    beginExit

    public void beginExit()
    Tells this thread to gracefully shut down


    run

    public void run()
    Background thread's execution

    Specified by:
    run in interface Runnable
    Overrides:
    run in class Thread

    processFaultyServers

    protected void processFaultyServers()
    Maintains the faulty server list and removes them from the current set of servers. Faulty servers that have been faulty for more than detectionTimeout * 5 milliseconds are removed from the faulty list


    initialConnection

    protected boolean initialConnection()
    Create the initial connection to a server and return whether or not it worked

    Returns:
    True if the initial connection exists or false if it does not exist

    findPrimary

    protected boolean findPrimary()
    Finds the primary server in the List of servers and returns whether or not one was found

    Returns:
    True if the primary server was found or false if it was not

    connectToAnyServer

    protected boolean connectToAnyServer(LogEntry logEntry)
    Connects to any registered server, which is chosen randomly

    Parameters:
    logEntry - The LogEntry object to write performance data to when not null
    Returns:
    True when a connection with a server was successfully established or false if a server connection could not be established