Class JobSchedulerStoreImpl

All Implemented Interfaces:
BrokerServiceAware, Lockable, JobSchedulerStore, org.apache.activemq.Service

public class JobSchedulerStoreImpl extends AbstractKahaDBStore implements JobSchedulerStore
  • Constructor Details

    • JobSchedulerStoreImpl

      public JobSchedulerStoreImpl()
  • Method Details

    • getJobScheduler

      public JobScheduler getJobScheduler(String name) throws Exception
      Specified by:
      getJobScheduler in interface JobSchedulerStore
      Throws:
      Exception
    • removeJobScheduler

      public boolean removeJobScheduler(String name) throws Exception
      Specified by:
      removeJobScheduler in interface JobSchedulerStore
      Throws:
      Exception
    • setLegacyStoreArchiveDirectory

      public void setLegacyStoreArchiveDirectory(File directory)
      Sets the directory where the legacy scheduler store files are archived before an update attempt is made. Both the legacy index files and the journal files are moved to this folder prior to an upgrade attempt.
      Parameters:
      directory - The directory to move the legacy Scheduler Store files to.
    • getLegacyStoreArchiveDirectory

      public File getLegacyStoreArchiveDirectory()
      Gets the directory where the legacy Scheduler Store files will be archived if the broker is started and an existing Job Scheduler Store from an old version is detected.
      Returns:
      the directory where scheduler store legacy files are archived on upgrade.
    • load

      public void load() throws IOException
      Description copied from class: AbstractKahaDBStore
      Loads the store from disk. Based on configuration this method can either load an existing store or it can purge an existing store and start in a clean state.
      Specified by:
      load in class AbstractKahaDBStore
      Throws:
      IOException - if an error occurs during the load.
    • unload

      public void unload() throws IOException
      Description copied from class: AbstractKahaDBStore
      Unload the state of the Store to disk and shuts down all resources assigned to this KahaDB store implementation.
      Specified by:
      unload in class AbstractKahaDBStore
      Throws:
      IOException - if an error occurs during the store unload.
    • checkpointUpdate

      protected void checkpointUpdate(Transaction tx, boolean cleanup) throws IOException
      Description copied from class: AbstractKahaDBStore
      Perform the checkpoint update operation. If the cleanup flag is true then the operation should also purge any unused Journal log files. This method must always be called with the checkpoint and index write locks held.
      Specified by:
      checkpointUpdate in class AbstractKahaDBStore
      Parameters:
      tx - The TX under which to perform the checkpoint update.
      cleanup - Should the checkpoint also do unused Journal file cleanup.
      Throws:
      IOException - if an error occurs while performing the checkpoint.
    • incrementJournalCount

      protected void incrementJournalCount(Transaction tx, Location location) throws IOException
      Adds a reference for the journal log file pointed to by the given Location value. To prevent log files in the journal that still contain valid data that needs to be kept in order to allow for recovery the logs must have active references. Each Job scheduler should ensure that the logs are accurately referenced.
      Parameters:
      tx - The TX under which the update is to be performed.
      location - The location value to update the reference count of.
      Throws:
      IOException - if an error occurs while updating the journal references table.
    • decrementJournalCount

      protected void decrementJournalCount(Transaction tx, Location location) throws IOException
      Removes one reference for the Journal log file indicated in the given Location value. The references are used to track which log files cannot be GC'd. When the reference count on a log file reaches zero the file id is removed from the tracker and the log will be removed on the next check point update.
      Parameters:
      tx - The TX under which the update is to be performed.
      location - The location value to update the reference count of.
      Throws:
      IOException - if an error occurs while updating the journal references table.
    • decrementJournalCount

      protected void decrementJournalCount(Transaction tx, HashMap<Integer,Integer> decrementsByFileIds) throws IOException
      Removes multiple references for the Journal log file indicated in the given Location map. The references are used to track which log files cannot be GC'd. When the reference count on a log file reaches zero the file id is removed from the tracker and the log will be removed on the next check point update.
      Parameters:
      tx - The TX under which the update is to be performed.
      decrementsByFileIds - Map indicating how many decrements per fileId.
      Throws:
      IOException - if an error occurs while updating the journal references table.
    • referenceRemovedLocation

      protected void referenceRemovedLocation(Transaction tx, Location location, org.apache.activemq.store.kahadb.scheduler.JobLocation removedJob) throws IOException
      Updates the Job removal tracking index with the location of a remove command and the original JobLocation entry. The JobLocation holds the locations in the logs where the add and update commands for a job stored. The log file containing the remove command can only be discarded after both the add and latest update log files have also been discarded.
      Parameters:
      tx - The TX under which the update is to be performed.
      location - The location value to reference a remove command.
      removedJob - The original JobLocation instance that holds the add and update locations
      Throws:
      IOException - if an error occurs while updating the remove location tracker.
    • referenceRemovedLocation

      protected void referenceRemovedLocation(Transaction tx, Location location, List<Integer> removedJobsFileId) throws IOException
      Updates the Job removal tracking index with the location of a remove command and the original JobLocation entry. The JobLocation holds the locations in the logs where the add and update commands for a job stored. The log file containing the remove command can only be discarded after both the add and latest update log files have also been discarded.
      Parameters:
      tx - The TX under which the update is to be performed.
      location - The location value to reference a remove command.
      removedJobsFileId - List of the original JobLocation instances that holds the add and update locations
      Throws:
      IOException - if an error occurs while updating the remove location tracker.
    • getPayload

      protected ByteSequence getPayload(Location location) throws IOException
      Retrieve the scheduled Job's byte blob from the journal.
      Parameters:
      location - The location of the KahaAddScheduledJobCommand that originated the Job.
      Returns:
      a ByteSequence containing the payload of the scheduled Job.
      Throws:
      IOException - if an error occurs while reading the payload value.
    • readLockIndex

      public void readLockIndex()
    • readUnlockIndex

      public void readUnlockIndex()
    • writeLockIndex

      public void writeLockIndex()
    • writeUnlockIndex

      public void writeUnlockIndex()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPageFileName

      protected String getPageFileName()
      Specified by:
      getPageFileName in class AbstractKahaDBStore
      Returns:
      the name to give this store's PageFile instance.
    • getDefaultDataDirectory

      protected File getDefaultDataDirectory()
      Specified by:
      getDefaultDataDirectory in class AbstractKahaDBStore
      Returns:
      the location of the data directory if no set by configuration.
    • doRecover

      protected void doRecover(JournalCommand<?> data, Location location, Location inDoubtlocation) throws IOException
      Called during index recovery to rebuild the index from the last known good location. For entries that occur before the last known good position we just ignore then and move on.
      Parameters:
      data - the command read from the Journal which should be used to update the index.
      location - the location in the index where the command was read.
      inDoubtlocation - the location in the index known to be the last time the index was valid.
      Throws:
      IOException - if an error occurs while recovering the index.
    • process

      protected void process(JournalCommand<?> data, Location location) throws IOException
      Called during recovery to allow the store to rebuild from scratch.
      Specified by:
      process in class AbstractKahaDBStore
      Parameters:
      data - The command to process, which was read from the Journal.
      location - The location of the command in the Journal.
      Throws:
      IOException - if an error occurs during command processing.
    • processLocation

      protected void processLocation(Location location)