Search in sources :

Example 1 with PersistenceStrategy

use of org.openhab.core.persistence.strategy.PersistenceStrategy in project openhab-core by openhab.

the class PersistenceManagerImpl method createTimers.

/**
 * Creates new {@link ScheduledCompletableFuture}s in the group <code>dbId</code> for the given collection of
 * {@link PersistenceStrategy strategies}.
 *
 * @param dbId the database id used by the persistence service
 * @param strategies a collection of strategies
 */
private void createTimers(final String dbId, List<PersistenceStrategy> strategies) {
    for (PersistenceStrategy strategy : strategies) {
        if (strategy instanceof PersistenceCronStrategy) {
            PersistenceCronStrategy cronStrategy = (PersistenceCronStrategy) strategy;
            String cronExpression = cronStrategy.getCronExpression();
            final PersistItemsJob job = new PersistItemsJob(this, dbId, cronStrategy.getName());
            ScheduledCompletableFuture<?> schedule = scheduler.schedule(job, cronExpression);
            if (persistenceJobs.containsKey(dbId)) {
                persistenceJobs.get(dbId).add(schedule);
            } else {
                final Set<ScheduledCompletableFuture<?>> jobs = new HashSet<>();
                jobs.add(schedule);
                persistenceJobs.put(dbId, jobs);
            }
            logger.debug("Scheduled strategy {} with cron expression {}", cronStrategy.getName(), cronExpression);
        }
    }
}
Also used : PersistenceCronStrategy(org.openhab.core.persistence.strategy.PersistenceCronStrategy) PersistenceStrategy(org.openhab.core.persistence.strategy.PersistenceStrategy) ScheduledCompletableFuture(org.openhab.core.scheduler.ScheduledCompletableFuture) HashSet(java.util.HashSet)

Example 2 with PersistenceStrategy

use of org.openhab.core.persistence.strategy.PersistenceStrategy in project openhab-core by openhab.

the class PersistenceManagerImpl method getDefaultConfig.

@Nullable
private PersistenceServiceConfiguration getDefaultConfig(PersistenceService persistenceService) {
    List<PersistenceStrategy> strategies = persistenceService.getDefaultStrategies();
    List<PersistenceItemConfiguration> configs = List.of(new PersistenceItemConfiguration(List.of(new PersistenceAllConfig()), null, strategies, null));
    return new PersistenceServiceConfiguration(configs, strategies, strategies);
}
Also used : PersistenceStrategy(org.openhab.core.persistence.strategy.PersistenceStrategy) PersistenceServiceConfiguration(org.openhab.core.persistence.PersistenceServiceConfiguration) PersistenceItemConfiguration(org.openhab.core.persistence.PersistenceItemConfiguration) PersistenceAllConfig(org.openhab.core.persistence.config.PersistenceAllConfig) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

PersistenceStrategy (org.openhab.core.persistence.strategy.PersistenceStrategy)2 HashSet (java.util.HashSet)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 PersistenceItemConfiguration (org.openhab.core.persistence.PersistenceItemConfiguration)1 PersistenceServiceConfiguration (org.openhab.core.persistence.PersistenceServiceConfiguration)1 PersistenceAllConfig (org.openhab.core.persistence.config.PersistenceAllConfig)1 PersistenceCronStrategy (org.openhab.core.persistence.strategy.PersistenceCronStrategy)1 ScheduledCompletableFuture (org.openhab.core.scheduler.ScheduledCompletableFuture)1