Class DummyComponentManager
- java.lang.Object
-
- io.openems.edge.common.test.DummyComponentManager
-
- All Implemented Interfaces:
ClockProvider
,ComponentManager
,OpenemsComponent
,JsonApi
public class DummyComponentManager extends java.lang.Object implements ComponentManager
Simulates a ComponentManager for the OpenEMS Component test framework.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.openems.edge.common.component.ComponentManager
ComponentManager.ChannelId
-
-
Field Summary
-
Fields inherited from interface io.openems.edge.common.component.ComponentManager
SINGLETON_COMPONENT_ID, SINGLETON_SERVICE_PID
-
-
Constructor Summary
Constructors Constructor Description DummyComponentManager()
DummyComponentManager(java.time.Clock clock)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Channel<?>
_channel(java.lang.String channelName)
Deprecated.DummyComponentManager
addComponent(OpenemsComponent component)
Specific for this Dummy implementation.java.lang.String
alias()
Returns a human-readable name of this Component..java.util.Collection<Channel<?>>
channels()
Returns all Channels.java.util.List<OpenemsComponent>
getAllComponents()
Gets all OpenEMS-Components.java.time.Clock
getClock()
Gets the OpenEMS Clock - either the real system clock or a mocked clock for simulations.<T extends OpenemsComponent>
TgetComponent(java.lang.String componentId)
Gets a OpenEMS-Component by its Component-ID.org.osgi.service.component.ComponentContext
getComponentContext()
Returns the ComponentContext.EdgeConfig
getEdgeConfig()
Gets the complete configuration of this OpenEMS Edge.java.util.List<OpenemsComponent>
getEnabledComponents()
Gets all enabled OpenEMS-Components.<T extends OpenemsComponent>
java.util.List<T>getEnabledComponentsOfType(java.lang.Class<T> clazz)
Gets all enabled OpenEMS-Components of the given Type.<T extends OpenemsComponent>
TgetPossiblyDisabledComponent(java.lang.String componentId)
Gets a OpenEMS-Component by its Component-ID.java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess>
handleJsonrpcRequest(User user, JsonrpcRequest request)
Handles a JSON-RPC Request.java.lang.String
id()
Returns a unique ID for this OpenEMS component.boolean
isEnabled()
Returns whether this component is enabled.void
setConfigJson(com.google.gson.JsonObject json)
Sets aEdgeConfig
json.void
setConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin configurationAdmin)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.openems.edge.common.component.ComponentManager
_setConfigNotActivated, _setDefaultConfigurationFailed, _setDuplicatedComponentId, _setWasOutOfMemory, getChannel, getConfigNotActivated, getConfigNotActivatedChannel, getDefaultConfigurationFailed, getDefaultConfigurationFailedChannel, getDuplicatedComponentId, getDuplicatedComponentIdChannel, getWasOutOfMemory, getWasOutOfMemoryChannel
-
Methods inherited from interface io.openems.edge.common.component.OpenemsComponent
_getChannelAs, channel, channel, debugLog, getState, getStateChannel, hasFaults, serviceFactoryPid, servicePid
-
-
-
-
Method Detail
-
getEnabledComponents
public java.util.List<OpenemsComponent> getEnabledComponents()
Description copied from interface:ComponentManager
Gets all enabled OpenEMS-Components.Be aware that via this method usage of the Component service is not tracked by the bundle's use count (See
BundleContext.getService(org.osgi.framework.ServiceReference)
). Make sure to use the references as shortly as possible.- Specified by:
getEnabledComponents
in interfaceComponentManager
- Returns:
- a List of OpenEMS-Components
-
getAllComponents
public java.util.List<OpenemsComponent> getAllComponents()
Description copied from interface:ComponentManager
Gets all OpenEMS-Components.Be aware that via this method usage of the Component service is not tracked by the bundle's use count (See
BundleContext.getService(org.osgi.framework.ServiceReference)
). Make sure to use the references as shortly as possible.- Specified by:
getAllComponents
in interfaceComponentManager
- Returns:
- a List of OpenEMS-Components
-
getEnabledComponentsOfType
public <T extends OpenemsComponent> java.util.List<T> getEnabledComponentsOfType(java.lang.Class<T> clazz)
Description copied from interface:ComponentManager
Gets all enabled OpenEMS-Components of the given Type.Be aware that via this method usage of the Component service is not tracked by the bundle's use count (See
BundleContext.getService(org.osgi.framework.ServiceReference)
). Make sure to use the references as shortly as possible.- Specified by:
getEnabledComponentsOfType
in interfaceComponentManager
- Type Parameters:
T
- the given Type, subclass ofOpenemsComponent
- Parameters:
clazz
- the given Type, subclass ofOpenemsComponent
- Returns:
- a List of OpenEMS-Components
-
getComponent
public <T extends OpenemsComponent> T getComponent(java.lang.String componentId) throws OpenemsError.OpenemsNamedException
Description copied from interface:ComponentManager
Gets a OpenEMS-Component by its Component-ID. The Component is guaranteed to be enabled.Be aware that via this method usage of the Component service is not tracked by the bundle's use count (See
BundleContext.getService(org.osgi.framework.ServiceReference)
). Make sure to use the references as shortly as possible.- Specified by:
getComponent
in interfaceComponentManager
- Type Parameters:
T
- the typed Component- Parameters:
componentId
- the Component-ID (e.g. "_sum")- Returns:
- the OpenEMS-Component
- Throws:
OpenemsError.OpenemsNamedException
- if the Component was not found
-
getPossiblyDisabledComponent
public <T extends OpenemsComponent> T getPossiblyDisabledComponent(java.lang.String componentId) throws OpenemsError.OpenemsNamedException
Description copied from interface:ComponentManager
Gets a OpenEMS-Component by its Component-ID. Be careful, that the Component might not be 'enabled'. If in doubt, useComponentManager.getComponent(String)
instead.Be aware that via this method usage of the Component service is not tracked by the bundle's use count (See
BundleContext.getService(org.osgi.framework.ServiceReference)
). Make sure to use the references as shortly as possible.- Specified by:
getPossiblyDisabledComponent
in interfaceComponentManager
- Type Parameters:
T
- the typed Component- Parameters:
componentId
- the Component-ID (e.g. "_sum")- Returns:
- the OpenEMS-Component
- Throws:
OpenemsError.OpenemsNamedException
- if the Component was not found
-
addComponent
public DummyComponentManager addComponent(OpenemsComponent component)
Specific for this Dummy implementation.- Parameters:
component
- the component that should be added- Returns:
- this
-
setConfigJson
public void setConfigJson(com.google.gson.JsonObject json)
Sets aEdgeConfig
json.- Parameters:
json
- theEdgeConfig
json
-
getEdgeConfig
public EdgeConfig getEdgeConfig()
Description copied from interface:ComponentManager
Gets the complete configuration of this OpenEMS Edge.Internally updates the cache if necessary and publishes a CONFIG_UPDATE event on update.
- Specified by:
getEdgeConfig
in interfaceComponentManager
- Returns:
- the
EdgeConfig
object
-
id
public java.lang.String id()
Description copied from interface:OpenemsComponent
Returns a unique ID for this OpenEMS component.- Specified by:
id
in interfaceOpenemsComponent
- Returns:
- the unique ID
-
alias
public java.lang.String alias()
Description copied from interface:OpenemsComponent
Returns a human-readable name of this Component..- Specified by:
alias
in interfaceOpenemsComponent
- Returns:
- the human-readable name
-
isEnabled
public boolean isEnabled()
Description copied from interface:OpenemsComponent
Returns whether this component is enabled.- Specified by:
isEnabled
in interfaceOpenemsComponent
- Returns:
- true if the component is enabled
-
getComponentContext
public org.osgi.service.component.ComponentContext getComponentContext()
Description copied from interface:OpenemsComponent
Returns the ComponentContext.- Specified by:
getComponentContext
in interfaceOpenemsComponent
- Returns:
- the OSGi ComponentContext
-
_channel
@Deprecated public Channel<?> _channel(java.lang.String channelName)
Deprecated.Description copied from interface:OpenemsComponent
Returns an undefined Channel defined by its ChannelId string representation.Note: It is preferred to use the typed channel()-method, that's why it is marked as @Deprecated.
- Specified by:
_channel
in interfaceOpenemsComponent
- Parameters:
channelName
- the Channel-ID as a string- Returns:
- the Channel or null
-
channels
public java.util.Collection<Channel<?>> channels()
Description copied from interface:OpenemsComponent
Returns all Channels.- Specified by:
channels
in interfaceOpenemsComponent
- Returns:
- a Collection of Channels
-
handleJsonrpcRequest
public java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess> handleJsonrpcRequest(User user, JsonrpcRequest request) throws OpenemsError.OpenemsNamedException
Description copied from interface:JsonApi
Handles a JSON-RPC Request.- Specified by:
handleJsonrpcRequest
in interfaceJsonApi
- Parameters:
user
- the authenticatedUser
request
- the JSON-RPC Request- Returns:
- a Future JSON-RPC Success Response; null response results in a OpenemsError.JSONRPC_UNHANDLED_METHOD
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getClock
public java.time.Clock getClock()
Description copied from interface:ComponentManager
Gets the OpenEMS Clock - either the real system clock or a mocked clock for simulations.- Specified by:
getClock
in interfaceClockProvider
- Specified by:
getClock
in interfaceComponentManager
- Returns:
- the Clock
-
setConfigurationAdmin
public void setConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin configurationAdmin)
-
-