Class InMemoryStorageProvider

java.lang.Object
org.jobrunr.storage.AbstractStorageProvider
org.jobrunr.storage.InMemoryStorageProvider
All Implemented Interfaces:
AutoCloseable, StorageProvider

public class InMemoryStorageProvider extends AbstractStorageProvider
  • Constructor Details

    • InMemoryStorageProvider

      public InMemoryStorageProvider()
    • InMemoryStorageProvider

      public InMemoryStorageProvider(RateLimiter rateLimiter)
  • Method Details

    • setJobMapper

      public void setJobMapper(JobMapper jobMapper)
    • setUpStorageProvider

      public void setUpStorageProvider(StorageProviderUtils.DatabaseOptions databaseOptions)
      Description copied from interface: StorageProvider
      This method allows to reinitialize the StorageProvider. It can be used if you are using Flyway or Liquibase to setup your database manually.

      By default, this method is automatically called on construction of the StorageProvider

      Parameters:
      databaseOptions - defines whether to set up the StorageProvider or validate whether the StorageProvider is set up correctly.
    • announceBackgroundJobServer

      public void announceBackgroundJobServer(BackgroundJobServerStatus serverStatus)
    • signalBackgroundJobServerAlive

      public boolean signalBackgroundJobServerAlive(BackgroundJobServerStatus serverStatus)
    • signalBackgroundJobServerStopped

      public void signalBackgroundJobServerStopped(BackgroundJobServerStatus serverStatus)
    • getBackgroundJobServers

      public List<BackgroundJobServerStatus> getBackgroundJobServers()
    • getLongestRunningBackgroundJobServerId

      public UUID getLongestRunningBackgroundJobServerId()
    • removeTimedOutBackgroundJobServers

      public int removeTimedOutBackgroundJobServers(Instant heartbeatOlderThan)
    • getJobById

      public Job getJobById(UUID id)
      Description copied from interface: StorageProvider
      Returns the Job with the given id or throws a JobNotFoundException if the job does not exist
      Parameters:
      id - the id of the Job to fetch
      Returns:
      the requested Job
    • countJobs

      public long countJobs(StateName state)
      Description copied from interface: StorageProvider
      Counts all the jobs matching the given StateName.
      Parameters:
      state - the StateName to test each Job against
      Returns:
      the amount of jobs matching the given StateName.
    • getJobList

      public List<Job> getJobList(StateName state, Instant updatedBefore, AmountRequest amountRequest)
      Description copied from interface: StorageProvider
      Returns all the jobs matching the given StateName, Instant and AmountRequest.
      Parameters:
      state - the StateName to test each Job against
      updatedBefore - the Instant to test each Job updatedAt against
      amountRequest - the amount and the order in which to return the jobs.
      Returns:
      a list of jobs matching the parameters.
    • getJobList

      public List<Job> getJobList(StateName state, AmountRequest amountRequest)
      Description copied from interface: StorageProvider
      Returns all the jobs matching the given StateName and AmountRequest.
      Parameters:
      state - the StateName to test each Job against
      amountRequest - the amount and the order in which to return the jobs.
      Returns:
      a list of jobs matching the parameters.
    • getCarbonAwareJobList

      public List<Job> getCarbonAwareJobList(Instant deadlineBefore, AmountRequest amountRequest)
      Description copied from interface: StorageProvider
      Returns all carbon aware jobs with a deadline before the given Instant.
      Parameters:
      deadlineBefore - the Instant to test each carbon aware Job against
      amountRequest - the amount and the order in which to return the jobs.
      Returns:
      a list of carbon aware jobs.
    • getScheduledJobs

      public List<Job> getScheduledJobs(Instant scheduledBefore, AmountRequest amountRequest)
    • saveMetadata

      public void saveMetadata(JobRunrMetadata metadata)
    • getMetadata

      public List<JobRunrMetadata> getMetadata(String key)
    • getMetadata

      public JobRunrMetadata getMetadata(String key, String owner)
    • deleteMetadata

      public void deleteMetadata(String name)
    • deleteMetadata

      public void deleteMetadata(String name, String owner)
    • save

      public Job save(Job job)
      Description copied from interface: StorageProvider
      Save the Job and increases the version if saving succeeded.
      Parameters:
      job - the job to save
      Returns:
      the same job with an increased version
    • deletePermanently

      public int deletePermanently(UUID id)
      Description copied from interface: StorageProvider
      Deletes the Job with the given id and returns the amount of deleted jobs (either 0 or 1).
      Parameters:
      id - the id of the Job to delete
      Returns:
      1 if the job with the given id was deleted, 0 otherwise
    • save

      public List<Job> save(List<Job> jobs)
      Description copied from interface: StorageProvider
      Saves a list of Jobs and increases the version of each successfully saved Job.
      Parameters:
      jobs - the list of jobs to save
      Returns:
      the same list of jobs with an increased version
    • deleteJobsPermanently

      public int deleteJobsPermanently(StateName state, Instant updatedBefore)
    • getDistinctJobSignatures

      public Set<String> getDistinctJobSignatures(StateName... states)
    • getRecurringJobLatestScheduledInstant

      public Instant getRecurringJobLatestScheduledInstant(String recurringJobId, StateName... states)
      Description copied from interface: StorageProvider
      Returns the scheduled instant of the last Job, in one of the given states, created by the RecurringJob with the given recurringJobId.
      Parameters:
      recurringJobId - the id of the RecurringJob for which to get the latest scheduled instant
      states - the possible states for the Job (can be empty, then match against all possible states)
      Returns:
      the scheduled instant of the last created Job
    • saveRecurringJob

      public RecurringJob saveRecurringJob(RecurringJob recurringJob)
      Description copied from interface: StorageProvider
      Saves a RecurringJob to the database. If a RecurringJob with the same id exists, it will be overwritten
      Parameters:
      recurringJob - the RecurringJob to save
      Returns:
      the same RecurringJob
    • getRecurringJobs

      public RecurringJobsResult getRecurringJobs()
      Description copied from interface: StorageProvider
      Returns a list RecurringJobs.
      Returns:
      a list RecurringJobs.
    • recurringJobsUpdated

      public boolean recurringJobsUpdated(Long recurringJobsUpdatedHash)
    • deleteRecurringJob

      public int deleteRecurringJob(String id)
      Description copied from interface: StorageProvider
      Deletes the RecurringJob with the given id.
      Parameters:
      id - the id of the RecurringJob to delete
      Returns:
      1 if the RecurringJob with the given id was deleted, 0 otherwise
    • getJobStats

      public JobStats getJobStats()
      Description copied from interface: StorageProvider
      Returns the statistics of the jobs (amount enqueued, amount scheduled, ...) Important: in most cases, this results in a intensive query. JobRunr is designed to not call this method too often to limit database CPU utilization. If you need access to this info, please use a JobStatsChangeListener and register it using the StorageProvider.addJobStorageOnChangeListener(StorageProviderChangeListener).
      Returns:
      the JobStats
    • publishTotalAmountOfSucceededJobs

      public void publishTotalAmountOfSucceededJobs(int amount)
    • clear

      public void clear()
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface StorageProvider
      Overrides:
      close in class AbstractStorageProvider