Class AbstractReadChannel<D extends AbstractDoc<T>,T>
java.lang.Object
io.openems.edge.common.channel.internal.AbstractReadChannel<D,T>
- All Implemented Interfaces:
Channel<T>
- Direct Known Subclasses:
BooleanReadChannel
,DoubleReadChannel
,EnumReadChannel
,FloatReadChannel
,IntegerReadChannel
,LongReadChannel
,ShortReadChannel
,StringReadChannel
public abstract class AbstractReadChannel<D extends AbstractDoc<T>,T>
extends Object
implements Channel<T>
-
Field Summary
FieldsFields inherited from interface io.openems.edge.common.channel.Channel
MAX_AGE_OF_PAST_VALUES
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractReadChannel
(OpenemsType type, OpenemsComponent parent, ChannelId channelId, D channelDoc) -
Method Summary
Modifier and TypeMethodDescriptionvoid
_setNextValue
(T value) Deprecated.address()
Gets the address of this Channel.Gets the ChannelDoc of this Channel.Gets the ChannelId of this Channel.void
Deactivates the Channel and makes sure all callbacks are released for garbe collection to avoid memory-leaks.Gets the OpenemsComponent this Channel belongs to.<SOURCE> SOURCE
Gets the meta information object.Gets the 'next value'.protected List<ThrowingConsumer<T,
OpenemsError.OpenemsNamedException>> Gets the past values for this Channel.getType()
Gets the type of this Channel, e.g.void
Switches to the next process image, i.e.BiConsumer<Value<T>,
Value<T>> Add an onChange callback.onSetNextValue
(Consumer<Value<T>> callback) Add an onSetNextValue callback.Add an onUpdate callback.void
removeOnChangeCallback
(BiConsumer<?, ?> callback) Removes an onChange callback.void
removeOnSetNextValueCallback
(Consumer<?> callback) Removes an onSetNextValue callback.void
removeOnUpdateCallback
(Consumer<Value<?>> callback) Removes an onUpdate callback.<SOURCE> void
setMetaInfo
(SOURCE source) Sets an object that holds meta information about the Channel, e.g.toString()
value()
Gets the currently active value, wrapped in a @{link Value}.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.openems.edge.common.channel.Channel
setNextValue
-
Field Details
-
parent
-
-
Constructor Details
-
AbstractReadChannel
protected AbstractReadChannel(OpenemsType type, OpenemsComponent parent, ChannelId channelId, D channelDoc)
-
-
Method Details
-
deactivate
public void deactivate()Description copied from interface:Channel
Deactivates the Channel and makes sure all callbacks are released for garbe collection to avoid memory-leaks.- Specified by:
deactivate
in interfaceChannel<D extends AbstractDoc<T>>
-
channelDoc
Description copied from interface:Channel
Gets the ChannelDoc of this Channel.- Specified by:
channelDoc
in interfaceChannel<D extends AbstractDoc<T>>
- Returns:
- the ChannelDoc
-
channelId
Description copied from interface:Channel
Gets the ChannelId of this Channel.- Specified by:
channelId
in interfaceChannel<D extends AbstractDoc<T>>
- Returns:
- the ChannelId
-
getComponent
Description copied from interface:Channel
Gets the OpenemsComponent this Channel belongs to.- Specified by:
getComponent
in interfaceChannel<D extends AbstractDoc<T>>
- Returns:
- the OpenemsComponent
-
nextProcessImage
public void nextProcessImage()Description copied from interface:Channel
Switches to the next process image, i.e. copies the "next"-value into "current"-value.- Specified by:
nextProcessImage
in interfaceChannel<D extends AbstractDoc<T>>
-
address
Description copied from interface:Channel
Gets the address of this Channel.- Specified by:
address
in interfaceChannel<D extends AbstractDoc<T>>
- Returns:
- the
ChannelAddress
-
getType
Description copied from interface:Channel
Gets the type of this Channel, e.g. INTEGER, BOOLEAN,..- Specified by:
getType
in interfaceChannel<D extends AbstractDoc<T>>
- Returns:
- the
OpenemsType
-
_setNextValue
Deprecated.Sets the next value. Internal method. Do not call directly.If the
Unit
of the Channel is cumulated and 'value' is null, it is silently ignored. Cumulated values must be steadily increasing and should never get reset to null. SeeUnit
.- Specified by:
_setNextValue
in interfaceChannel<D extends AbstractDoc<T>>
- Parameters:
value
- the next value
-
getNextValue
Description copied from interface:Channel
Gets the 'next value'.Note that usually you should prefer the value() method.
- Specified by:
getNextValue
in interfaceChannel<D extends AbstractDoc<T>>
- Returns:
- the 'next value', never null
-
value
Description copied from interface:Channel
Gets the currently active value, wrapped in a @{link Value}.- Specified by:
value
in interfaceChannel<D extends AbstractDoc<T>>
- Returns:
- the active value, never null
- Throws:
IllegalArgumentException
- if value cannot be accessed, e.g. because the Channel is Write-Only.
-
toString
-
onUpdate
Description copied from interface:Channel
Add an onUpdate callback. It is called, after the active value was updated by nextProcessImage().- Specified by:
onUpdate
in interfaceChannel<D extends AbstractDoc<T>>
- Parameters:
callback
- the callback- Returns:
- the same callback for fluent coding
-
removeOnUpdateCallback
Description copied from interface:Channel
Removes an onUpdate callback.- Specified by:
removeOnUpdateCallback
in interfaceChannel<D extends AbstractDoc<T>>
- Parameters:
callback
- the callbackConsumer
- See Also:
-
onSetNextValue
Description copied from interface:Channel
Add an onSetNextValue callback. It is called, after a new NextValue was set. Note that usually you should prefer the onUpdate() callback.Remember to remove the callback using
Channel.removeOnSetNextValueCallback(Consumer)
once it is not needed anymore, e.g. on deactivate().- Specified by:
onSetNextValue
in interfaceChannel<D extends AbstractDoc<T>>
- Parameters:
callback
- the callbackConsumer
- Returns:
- the callback to enable fluent programming
- See Also:
-
removeOnSetNextValueCallback
Description copied from interface:Channel
Removes an onSetNextValue callback.- Specified by:
removeOnSetNextValueCallback
in interfaceChannel<D extends AbstractDoc<T>>
- Parameters:
callback
- the callbackConsumer
- See Also:
-
onChange
Description copied from interface:Channel
Add an onChange callback. It is called, after a new, different active value was set by nextProcessImage().- Specified by:
onChange
in interfaceChannel<D extends AbstractDoc<T>>
- Parameters:
callback
- old value and new value- Returns:
- the same callback for fluent coding
-
removeOnChangeCallback
Description copied from interface:Channel
Removes an onChange callback.- Specified by:
removeOnChangeCallback
in interfaceChannel<D extends AbstractDoc<T>>
- Parameters:
callback
- the callbackBiConsumer
- See Also:
-
getOnSetNextWrites
-
getPastValues
Gets the past values for this Channel.- Specified by:
getPastValues
in interfaceChannel<D extends AbstractDoc<T>>
- Returns:
- a map of recording time and historic value at that time
-
setMetaInfo
Description copied from interface:Channel
Sets an object that holds meta information about the Channel, e.g. a read source or write target of this Channel, like a Modbus Register or REST-Api endpoint address. Defaults to null.- Specified by:
setMetaInfo
in interfaceChannel<D extends AbstractDoc<T>>
- Type Parameters:
SOURCE
- the type of the meta info- Parameters:
source
- the meta info object- Throws:
IllegalArgumentException
- if there is already a different meta-info registered with the Channel
-
getMetaInfo
public <SOURCE> SOURCE getMetaInfo()Description copied from interface:Channel
Gets the meta information object. Defaults to null.- Specified by:
getMetaInfo
in interfaceChannel<D extends AbstractDoc<T>>
- Type Parameters:
SOURCE
- the type of the meta info attachment- Returns:
- the meta info object
-