Package org.lsst.ccs

Class PersistencyService

java.lang.Object
org.lsst.ccs.PersistencyService
All Implemented Interfaces:
HasLifecycle, ServiceLifecycle

public final class PersistencyService extends Object implements ServiceLifecycle, HasLifecycle
This objects is responsible for keeping track of fields annotated with Persist and to write them into a local file at subsystem shutdown or at regular time intervals.
Author:
LSST CCS Team
  • Method Details

    • afterInit

      public void afterInit()
      Specified by:
      afterInit in interface ServiceLifecycle
    • setPersistencyFileName

      public void setPersistencyFileName(String fileName)
    • preStart

      public void preStart()
      Description copied from interface: ServiceLifecycle
      Called from the enclosing Subsystem when org.lsst.ccs.Subsystem#start() has been called.

      The preceding lifecycle step is HasLifecycle.postInit()

      The following lifecycle step is HasLifecycle.start() At the time it is called :

      • the PhaseState is INITIALIZING
      • connection with the messaging layer is effective, the enclosing subsystem has started StatusHeartBeat publication
      Specified by:
      preStart in interface ServiceLifecycle
    • preShutdown

      public void preShutdown()
      Specified by:
      preShutdown in interface ServiceLifecycle
    • shutdown

      public void shutdown()
      Description copied from interface: HasLifecycle
      Called from the enclosing Subsystem when org.lsst.ccs.Subsystem#shutdown() has been called. At the time it is called PhaseState is CLOSING. It should be overridden to free non hardware related resources.
      Specified by:
      shutdown in interface HasLifecycle
    • setAutomatic

      public void setAutomatic(boolean loadAtStartup, boolean persistAtShutdown)
      Customize the behavior of the local persistence service. This method can only when the Agent is initializing, otherwise it throws an exception.
      Parameters:
      loadAtStartup - true if the persistence file should be loaded automatically at startup
      persistAtShutdown - true if the persistence file should be written autmatically at shutdown
    • persistNow

      @Command(description="writes persistent data in local file", category=SYSTEM) public boolean persistNow()
      Persists the annotated fields values in a local file. REVIEW : how do we make sure that modifications made to the fields are visible ? Does it matter ?
      Returns:
      true if the persistence was successful, false otherwise.
    • load

      @Command(description="loads persistent data from local file", category=SYSTEM) public boolean load()
      Reads the persisted data local file and applies the contained value to the Persist annotated fields. Inconsistent data are silently ignored
      Returns:
      true if the local persistent file has been set correctly, false otherwise.
    • isLocalPersistenceFilePresent

      @Command(description="returns true if a local persistence file is present, false otherwise.", category=SYSTEM) public boolean isLocalPersistenceFilePresent()
      Tells whether a local persistence file exists on the local filesystem for that agent.
      Returns:
      true if such a file exists, false otherwise.