Class ApiWorker
- java.lang.Object
-
- io.openems.edge.controller.api.common.ApiWorker
-
public class ApiWorker extends java.lang.Object
Takes care of continuously writing channels till a timeout. This class is used in all Api-Controllers.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_TIMEOUT_SECONDS
-
Constructor Summary
Constructors Constructor Description ApiWorker(OpenemsComponent parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addValue(WriteChannel<?> channel, WriteObject writeObject)
Adds a value to the write-pipeline.java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess>
handleSetChannelValueRequest(ComponentManager componentManager, User user, SetChannelValueRequest request)
Adds a value via JSON-RPCSetChannelValueRequest
.void
run()
Sets the channels.void
setLogChannel(StringReadChannel logChannel)
Sets the Channel that should be used to log debug information about writes to channels.void
setTimeoutSeconds(int timeoutSeconds)
Sets the timeout in seconds.
-
-
-
Field Detail
-
DEFAULT_TIMEOUT_SECONDS
public static final int DEFAULT_TIMEOUT_SECONDS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ApiWorker
public ApiWorker(OpenemsComponent parent)
-
-
Method Detail
-
setLogChannel
public void setLogChannel(StringReadChannel logChannel)
Sets the Channel that should be used to log debug information about writes to channels.- Parameters:
logChannel
- aStringReadChannel
-
addValue
public void addValue(WriteChannel<?> channel, WriteObject writeObject)
Adds a value to the write-pipeline. The values are then set in the next execution ofrun()
, until the timeout is reached.- Parameters:
channel
- theWriteChannel
writeObject
- theWriteObject
-
handleSetChannelValueRequest
public java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess> handleSetChannelValueRequest(ComponentManager componentManager, User user, SetChannelValueRequest request) throws java.lang.IllegalArgumentException, OpenemsError.OpenemsNamedException
Adds a value via JSON-RPCSetChannelValueRequest
.- Parameters:
componentManager
- theComponentManager
user
- the authenticatedUser
request
- the Request- Returns:
- success
- Throws:
OpenemsError.OpenemsNamedException
- on errorjava.lang.IllegalArgumentException
- on error
-
setTimeoutSeconds
public void setTimeoutSeconds(int timeoutSeconds)
Sets the timeout in seconds. Default is 60, which means that for 60 seconds in each cycle a value is rewritten to the WriteChannel. If set to '0', timeout is deactivated.- Parameters:
timeoutSeconds
- the timeout for this ApiWorker
-
run
public void run() throws OpenemsError.OpenemsNamedException
Sets the channels. This method is called by the run() method of the Controller- Throws:
OpenemsError.OpenemsNamedException
- on error
-
-