Package io.openems.common.worker
Class AbstractCycleWorker
- java.lang.Object
-
- io.openems.common.worker.AbstractWorker
-
- io.openems.common.worker.AbstractCycleWorker
-
- Direct Known Subclasses:
BoschBpts5HybridReadWorker
,DiscovergyWorker
,HardyBarthReadWorker
,ReadWorker
,Worker
public abstract class AbstractCycleWorker extends AbstractWorker
Defines a generic Worker Thread.The business logic of the Worker is inside the
forever()
method. It is executed after triggered theAbstractWorker.triggerNextRun()
method.This implementation is helpful to execute logic synchronized with the OpenEMS Edge Cycle. Be sure to call 'triggerNextCycle()' once per Cycle (using an OSGi EventHandler).
-
-
Field Summary
-
Fields inherited from class io.openems.common.worker.AbstractWorker
ALWAYS_WAIT_FOR_TRIGGER_NEXT_RUN, DO_NOT_WAIT, thread
-
-
Constructor Summary
Constructors Constructor Description AbstractCycleWorker()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
activate(java.lang.String name)
Initializes the worker and starts the worker thread.void
deactivate()
Stops the worker thread.protected abstract void
forever()
This method is called in a loop forever until the Thread gets interrupted.protected int
getCycleTime()
Gets the cycleTime of this worker in [ms].-
Methods inherited from class io.openems.common.worker.AbstractWorker
modified, triggerNextRun
-
-
-
-
Method Detail
-
activate
public void activate(java.lang.String name)
Description copied from class:AbstractWorker
Initializes the worker and starts the worker thread.- Overrides:
activate
in classAbstractWorker
- Parameters:
name
- the name of the worker thread
-
deactivate
public void deactivate()
Description copied from class:AbstractWorker
Stops the worker thread.- Overrides:
deactivate
in classAbstractWorker
-
getCycleTime
protected final int getCycleTime()
Description copied from class:AbstractWorker
Gets the cycleTime of this worker in [ms].- > 0 sets the minimum execution time of one Cycle
- = 0 never wait between two consecutive executions of forever()
- < 0 causes the Cycle to sleep forever until 'triggerNextRun()' is called
- Specified by:
getCycleTime
in classAbstractWorker
- Returns:
- the cycleTime
-
forever
protected abstract void forever() throws java.lang.Throwable
Description copied from class:AbstractWorker
This method is called in a loop forever until the Thread gets interrupted.- Specified by:
forever
in classAbstractWorker
- Throws:
java.lang.Throwable
-
-