Package io.openems.common.worker
Class AbstractWorker
java.lang.Object
io.openems.common.worker.AbstractWorker
- Direct Known Subclasses:
AbstractCycleWorker
,AbstractImmediateWorker
,AppInstallWorker
,AppSynchronizeWorker
,AppValidateWorker
,ClientReconnectorWorker
,ComponentManagerWorker
,CycleWorker
,DiskSpaceWorker
,NetworkConfigurationWorker
,ReadWorker
,UsbConfigurationWorker
Defines a generic Worker Thread.
The business logic of the Worker is inside the forever()
method. It
is executed by default every getCycleTime()
seconds. Additionally
execution can be triggered by calling the triggerNextRun()
method.
If Cycle-Time is negative (e.g. by using
ALWAYS_WAIT_FOR_TRIGGER_NEXT_RUN
) the forever() method is called
only after triggering it.
If Cycle-Time is zero (e.g. by using DO_NOT_WAIT
), the forever()
method is always called immediately without any delay.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Initializes the worker and starts the worker thread.void
Stops the worker thread.protected abstract void
forever()
This method is called in a loop forever until the Thread gets interrupted.protected abstract int
Gets the cycleTime of this worker in [ms].void
Modifies the worker thread.void
Allows the next execution of the forever() method.
-
Field Details
-
ALWAYS_WAIT_FOR_TRIGGER_NEXT_RUN
public static final int ALWAYS_WAIT_FOR_TRIGGER_NEXT_RUN- See Also:
-
DO_NOT_WAIT
public static final int DO_NOT_WAIT- See Also:
-
thread
-
-
Constructor Details
-
AbstractWorker
public AbstractWorker()
-
-
Method Details
-
activate
Initializes the worker and starts the worker thread.- Parameters:
name
- the name of the worker thread
-
modified
Modifies the worker thread.- Parameters:
name
- the name of the worker thread
-
deactivate
public void deactivate()Stops the worker thread. -
forever
This method is called in a loop forever until the Thread gets interrupted.- Throws:
Throwable
-
getCycleTime
protected abstract int getCycleTime()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
- Returns:
- the cycleTime
-
triggerNextRun
public void triggerNextRun()Allows the next execution of the forever() method.
-