]> git.basschouten.com Git - openhab-addons.git/blob
22dcb158eb41390cf2a9ffda43451dc85be628cb
[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. {@link DeviceConsumptionSensorJob} and
23  * {@link DeviceOutputValueSensorJob}.
24  * <p>
25  * In addition priorities can be assigned to jobs, but the following list shows the maximum evaluation of a
26  * {@link SensorJob} per priority.
27  * </p>
28  * <ul>
29  * <li>low priority: read cycles before execution is set in {@link Config}</li>
30  * <li>medium priority: read cycles before execution is set in {@link Config}</li>
31  * <li>high priority: read cycles before execution 0</li>
32  * </ul>
33  *
34  * @author Michael Ochel - Initial contribution
35  * @author Matthias Siegele - Initial contribution
36  *
37  */
38 public class SensorJobExecutor extends AbstractSensorJobExecutor {
39
40     private final Logger logger = LoggerFactory.getLogger(SensorJobExecutor.class);
41
42     private final long mediumFactor = super.config.getSensorReadingWaitTime() * super.config.getMediumPriorityFactor();
43     private final long lowFactor = super.config.getSensorReadingWaitTime() * super.config.getLowPriorityFactor();
44
45     /**
46      * Creates a new {@link SensorJobExecutor}.
47      *
48      * @param connectionManager must not be null
49      */
50     public SensorJobExecutor(ConnectionManager connectionManager) {
51         super(connectionManager);
52     }
53
54     @Override
55     public void addHighPriorityJob(SensorJob sensorJob) {
56         if (sensorJob == null) {
57             return;
58         }
59         addSensorJobToCircuitScheduler(sensorJob);
60         logger.debug("Add SensorJob from device with dSID {} and high-priority to SensorJobExecutor",
61                 sensorJob.getDSID());
62     }
63
64     @Override
65     public void addMediumPriorityJob(SensorJob sensorJob) {
66         if (sensorJob == null) {
67             return;
68         }
69         sensorJob.setInitalisationTime(sensorJob.getInitalisationTime() + this.mediumFactor);
70         addSensorJobToCircuitScheduler(sensorJob);
71         logger.debug("Add SensorJob from device with dSID {} and medium-priority to SensorJobExecutor",
72                 sensorJob.getDSID());
73     }
74
75     @Override
76     public void addLowPriorityJob(SensorJob sensorJob) {
77         if (sensorJob == null) {
78             return;
79         }
80         sensorJob.setInitalisationTime(sensorJob.getInitalisationTime() + this.lowFactor);
81         addSensorJobToCircuitScheduler(sensorJob);
82         logger.debug("Add SensorJob from device with dSID {} and low-priority to SensorJobExecutor",
83                 sensorJob.getDSID());
84     }
85 }