]> git.basschouten.com Git - openhab-addons.git/blob
31a70b45ac95ef685e461806361b06c660bd202e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.digitalstrom.internal.lib.sensorjobexecutor;
14
15 import org.openhab.binding.digitalstrom.internal.lib.manager.ConnectionManager;
16 import org.openhab.binding.digitalstrom.internal.lib.sensorjobexecutor.sensorjob.SensorJob;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * The {@link SensorJobExecutor} is the implementation of the {@link AbstractSensorJobExecutor} to execute
22  * digitalSTROM-Device {@link SensorJob}'s e.g.
23  * {@link org.openhab.binding.digitalstrom.internal.lib.sensorjobexecutor.sensorjob.impl.DeviceConsumptionSensorJob} and
24  * {@link org.openhab.binding.digitalstrom.internal.lib.sensorjobexecutor.sensorjob.impl.DeviceOutputValueSensorJob}.
25  * <p>
26  * In addition priorities can be assigned to jobs, but the following list shows the maximum evaluation of a
27  * {@link SensorJob} per priority.
28  * </p>
29  * <ul>
30  * <li>low priority: read cycles before execution is set in
31  * {@link org.openhab.binding.digitalstrom.internal.lib.config.Config}</li>
32  * <li>medium priority: read cycles before execution is set in
33  * {@link org.openhab.binding.digitalstrom.internal.lib.config.Config}</li>
34  * <li>high priority: read cycles before execution 0</li>
35  * </ul>
36  *
37  * @author Michael Ochel - Initial contribution
38  * @author Matthias Siegele - Initial contribution
39  *
40  */
41 public class SensorJobExecutor extends AbstractSensorJobExecutor {
42
43     private final Logger logger = LoggerFactory.getLogger(SensorJobExecutor.class);
44
45     private final long mediumFactor = super.config.getSensorReadingWaitTime() * super.config.getMediumPriorityFactor();
46     private final long lowFactor = super.config.getSensorReadingWaitTime() * super.config.getLowPriorityFactor();
47
48     /**
49      * Creates a new {@link SensorJobExecutor}.
50      *
51      * @param connectionManager must not be null
52      */
53     public SensorJobExecutor(ConnectionManager connectionManager) {
54         super(connectionManager);
55     }
56
57     @Override
58     public void addHighPriorityJob(SensorJob sensorJob) {
59         if (sensorJob == null) {
60             return;
61         }
62         addSensorJobToCircuitScheduler(sensorJob);
63         logger.debug("Add SensorJob from device with dSID {} and high-priority to SensorJobExecutor",
64                 sensorJob.getDSID());
65     }
66
67     @Override
68     public void addMediumPriorityJob(SensorJob sensorJob) {
69         if (sensorJob == null) {
70             return;
71         }
72         sensorJob.setInitalisationTime(sensorJob.getInitalisationTime() + this.mediumFactor);
73         addSensorJobToCircuitScheduler(sensorJob);
74         logger.debug("Add SensorJob from device with dSID {} and medium-priority to SensorJobExecutor",
75                 sensorJob.getDSID());
76     }
77
78     @Override
79     public void addLowPriorityJob(SensorJob sensorJob) {
80         if (sensorJob == null) {
81             return;
82         }
83         sensorJob.setInitalisationTime(sensorJob.getInitalisationTime() + this.lowFactor);
84         addSensorJobToCircuitScheduler(sensorJob);
85         logger.debug("Add SensorJob from device with dSID {} and low-priority to SensorJobExecutor",
86                 sensorJob.getDSID());
87     }
88 }