Class AsynchronousStateManager

java.lang.Object
com.nt.udc.util.state.StateManager
com.nt.udc.util.state.AsynchronousStateManager

public class AsynchronousStateManager extends StateManager
The StateManager is responsible for holding a set of StateDirectorySaveable or StateBufferSaveable Objects, and saving/restoring those Objects when told to. Specifically, the AsynchronousStateManager should be used when saving states in a multi-threaded environment. Likewise, all Objects saved/restored/frozen through use of this StateManager must support an asynchronous series of method calls and acknowledgements. When told, the StateManager will save to/restore from a buffer file. The StateManager treats all managed Objects equally - meaning, all of the Objects must NOT be order-dependant in saving/restoring their states. If Object's have dependencies on one another, they must be resolved in another manner.
  • Constructor Details

    • AsynchronousStateManager

      public AsynchronousStateManager(LoggerIfc logger, File scratchDir)
      Creates the default StateManager
      Parameters:
      logger - Activity logger
      scratchDir - Directory which to store state data
    • AsynchronousStateManager

      public AsynchronousStateManager(LoggerIfc logger, File scratchDir, String stateBufferFileName)
      Creates the StateManager with a buffer file.
      Parameters:
      logger - Activity logger
      scratchDir - Directory which to store state data.
      stateBufferFileName - Buffer File name
  • Method Details

    • shutdown

      public void shutdown()
      Shuts down the StateManager, and cleans up any remaining state-related files.
      Overrides:
      shutdown in class StateManager
    • setMergeDelay

      public void setMergeDelay(int delay)
      Sets the delay time for the periodic directory merge.
      Parameters:
      delay - Time(ms) of the delay
    • setStateBufferFileName

      public void setStateBufferFileName(String stateBufferFileName)
      Sets the current state buffer file.
      Overrides:
      setStateBufferFileName in class StateManager
      Parameters:
      stateBufferFileName - Buffer file, containing the states.
    • manageState

      public void manageState(StateBufferSaveable state)
      Adds a single StateBufferSaveable object to be managed.
      Overrides:
      manageState in class StateManager
      Parameters:
      stateDirObj - State object to manage
    • manageState

      public void manageState(StateDirectorySaveable state)
      Adds a single StateDirectorySaveable object to be managed.
      Overrides:
      manageState in class StateManager
      Parameters:
      stateDirObj - State object to manage
    • manageStates

      public void manageStates(StateBufferSaveable[] states)
      Adds an array of StateBufferSaveable objects for managing.
      Overrides:
      manageStates in class StateManager
      Parameters:
      states - Array of state objects
    • manageStates

      public void manageStates(StateDirectorySaveable[] states)
      Adds an array of StateDirectorySaveable objects for managing.
      Overrides:
      manageStates in class StateManager
      Parameters:
      states - Array of state objects
    • manageActiveObject

      public void manageActiveObject(StateFreezable activeObject)
      Manages a single active Object. This Object will be told to freeze before all state saving routines occur. Note that using this method implies that there are **NO** order dependencies related to the given Object.
      Overrides:
      manageActiveObject in class StateManager
      Parameters:
      activeObject - Object to be frozen during state save
    • saveState

      public void saveState(Callback callback) throws StateException
      This method requests a save state from the StateSaver.
      Specified by:
      saveState in class StateManager
      Throws:
      StateException
    • saveState

      public void saveState() throws StateException
      This method is not supported in Asynchronous mode.
      Specified by:
      saveState in class StateManager
      Throws:
      StateException
    • restoreState

      public void restoreState() throws StateException
      Restores the state of all the objects currently being managed.
      Specified by:
      restoreState in class StateManager
      Throws:
      StateException
    • getType

      public StateManagementType getType()
      Returns that this StateManager supports asynchronous state mode.
      Specified by:
      getType in class StateManager
      Returns:
      StateManagementType, that this is asynchronous mode