Class ComponentManagerImpl
- java.lang.Object
-
- io.openems.edge.common.component.AbstractOpenemsComponent
-
- io.openems.edge.core.componentmanager.ComponentManagerImpl
-
- All Implemented Interfaces:
ClockProvider
,ComponentManager
,OpenemsComponent
,JsonApi
,org.osgi.service.cm.ConfigurationListener
public class ComponentManagerImpl extends AbstractOpenemsComponent implements ComponentManager, OpenemsComponent, JsonApi, org.osgi.service.cm.ConfigurationListener
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.openems.edge.common.component.ComponentManager
ComponentManager.ChannelId
-
Nested classes/interfaces inherited from interface io.openems.edge.common.component.OpenemsComponent
OpenemsComponent.ChannelId
-
-
Field Summary
Fields Modifier and Type Field Description protected org.osgi.framework.BundleContext
bundleContext
protected ClockProvider
clockProvider
protected org.osgi.service.cm.ConfigurationAdmin
cm
protected org.osgi.service.event.EventAdmin
eventAdmin
protected org.osgi.service.metatype.MetaTypeService
metaTypeService
protected org.osgi.service.component.runtime.ServiceComponentRuntime
serviceComponentRuntime
-
Fields inherited from interface io.openems.edge.common.component.ComponentManager
SINGLETON_COMPONENT_ID, SINGLETON_SERVICE_PID
-
-
Constructor Summary
Constructors Constructor Description ComponentManagerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configurationEvent(org.osgi.service.cm.ConfigurationEvent event)
protected void
deactivate()
Handles @Deactivate of implementations.java.lang.String
debugLog()
Gets some output that is suitable for a continuous Debug log.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.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.protected org.osgi.service.cm.Configuration
getExistingConfigForId(java.lang.String componentId)
Gets the ConfigAdmin Configuration for the OpenEMS Component with the given Component-ID.<T extends OpenemsComponent>
TgetPossiblyDisabledComponent(java.lang.String componentId)
Gets a OpenEMS-Component by its Component-ID.protected java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess>
handleChannelExportXlsxRequest(User user, ChannelExportXlsxRequest request)
Handles aChannelExportXlsxRequest
.java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess>
handleCreateComponentConfigRequest(User user, CreateComponentConfigRequest request)
Handles aCreateComponentConfigRequest
.java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess>
handleDeleteComponentConfigRequest(User user, DeleteComponentConfigRequest request)
Handles aDeleteComponentConfigRequest
.java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess>
handleJsonrpcRequest(User user, JsonrpcRequest request)
Handles a JSON-RPC Request.java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess>
handleUpdateComponentConfigRequest(User user, UpdateComponentConfigRequest request)
Handles aUpdateComponentConfigRequest
.protected void
logError(org.slf4j.Logger log, java.lang.String message)
Log an error message including the Component ID.protected void
logInfo(org.slf4j.Logger log, java.lang.String message)
Log an info message including the Component ID.protected void
logWarn(org.slf4j.Logger log, java.lang.String message)
Log a warn message including the Component ID.-
Methods inherited from class io.openems.edge.common.component.AbstractOpenemsComponent
_channel, activate, activate, addChannel, addChannels, addChannels, alias, channels, getComponentContext, id, isEnabled, logDebug, modified, removeChannel
-
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
_channel, _getChannelAs, alias, channel, channel, channels, getComponentContext, getState, getStateChannel, hasFaults, id, isEnabled, serviceFactoryPid, servicePid
-
-
-
-
Field Detail
-
bundleContext
protected org.osgi.framework.BundleContext bundleContext
-
clockProvider
protected volatile ClockProvider clockProvider
-
metaTypeService
protected org.osgi.service.metatype.MetaTypeService metaTypeService
-
cm
protected org.osgi.service.cm.ConfigurationAdmin cm
-
eventAdmin
protected org.osgi.service.event.EventAdmin eventAdmin
-
serviceComponentRuntime
protected org.osgi.service.component.runtime.ServiceComponentRuntime serviceComponentRuntime
-
-
Method Detail
-
deactivate
protected void deactivate()
Description copied from class:AbstractOpenemsComponent
Handles @Deactivate of implementations. Prints log output.- Overrides:
deactivate
in classAbstractOpenemsComponent
-
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
-
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
-
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
-
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
-
debugLog
public java.lang.String debugLog()
Description copied from interface:OpenemsComponent
Gets some output that is suitable for a continuous Debug log. Returns 'null' by default which causes no output.- Specified by:
debugLog
in interfaceOpenemsComponent
- Returns:
- the debug log output
-
logInfo
protected void logInfo(org.slf4j.Logger log, java.lang.String message)
Description copied from class:AbstractOpenemsComponent
Log an info message including the Component ID.- Overrides:
logInfo
in classAbstractOpenemsComponent
- Parameters:
log
- the Logger instancemessage
- the message
-
logWarn
protected void logWarn(org.slf4j.Logger log, java.lang.String message)
Description copied from class:AbstractOpenemsComponent
Log a warn message including the Component ID.- Overrides:
logWarn
in classAbstractOpenemsComponent
- Parameters:
log
- the Logger instancemessage
- the message
-
logError
protected void logError(org.slf4j.Logger log, java.lang.String message)
Description copied from class:AbstractOpenemsComponent
Log an error message including the Component ID.- Overrides:
logError
in classAbstractOpenemsComponent
- Parameters:
log
- the Logger instancemessage
- the message
-
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
-
handleCreateComponentConfigRequest
public java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess> handleCreateComponentConfigRequest(User user, CreateComponentConfigRequest request) throws OpenemsError.OpenemsNamedException
Handles aCreateComponentConfigRequest
.- Parameters:
user
- theUser
request
- theCreateComponentConfigRequest
- Returns:
- the Future JSON-RPC Response
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
handleUpdateComponentConfigRequest
public java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess> handleUpdateComponentConfigRequest(User user, UpdateComponentConfigRequest request) throws OpenemsError.OpenemsNamedException
Handles aUpdateComponentConfigRequest
.- Parameters:
user
- theUser
request
- theUpdateComponentConfigRequest
- Returns:
- the Future JSON-RPC Response
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
handleDeleteComponentConfigRequest
public java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess> handleDeleteComponentConfigRequest(User user, DeleteComponentConfigRequest request) throws OpenemsError.OpenemsNamedException
Handles aDeleteComponentConfigRequest
.- Parameters:
user
- theUser
request
- theDeleteComponentConfigRequest
- Returns:
- the Future JSON-RPC Response
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
handleChannelExportXlsxRequest
protected java.util.concurrent.CompletableFuture<JsonrpcResponseSuccess> handleChannelExportXlsxRequest(User user, ChannelExportXlsxRequest request) throws OpenemsError.OpenemsNamedException
Handles aChannelExportXlsxRequest
.- Parameters:
user
- theUser
request
- theChannelExportXlsxRequest
- Returns:
- the Future JSON-RPC Response
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getExistingConfigForId
protected org.osgi.service.cm.Configuration getExistingConfigForId(java.lang.String componentId) throws OpenemsError.OpenemsNamedException
Gets the ConfigAdmin Configuration for the OpenEMS Component with the given Component-ID.- Parameters:
componentId
- the Component-ID- Returns:
- the Configuration
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
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
-
configurationEvent
public void configurationEvent(org.osgi.service.cm.ConfigurationEvent event)
- Specified by:
configurationEvent
in interfaceorg.osgi.service.cm.ConfigurationListener
-
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
-
-