/
ComponentManager.java
267 lines (239 loc) · 7.81 KB
/
ComponentManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package io.openems.edge.common.component;
import java.time.Clock;
import java.util.List;
import io.openems.common.OpenemsConstants;
import io.openems.common.channel.Level;
import io.openems.common.exceptions.OpenemsError;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.types.ChannelAddress;
import io.openems.common.types.EdgeConfig;
import io.openems.edge.common.channel.Channel;
import io.openems.edge.common.channel.Doc;
import io.openems.edge.common.channel.StateChannel;
import io.openems.edge.common.channel.value.Value;
import io.openems.edge.common.jsonapi.JsonApi;
/**
* A Service that provides access to OpenEMS-Components.
*/
public interface ComponentManager extends OpenemsComponent, JsonApi, ClockProvider {
public enum ChannelId implements io.openems.edge.common.channel.ChannelId {
CONFIG_NOT_ACTIVATED(Doc.of(Level.FAULT) //
.text("A configured OpenEMS Component was not activated")), //
DUPLICATED_COMPONENT_ID(Doc.of(Level.FAULT) //
.text("Configuration has duplicated Component-IDs")), //
WAS_OUT_OF_MEMORY(Doc.of(Level.INFO) //
.text("OutOfMemory had happened. Found heap dump files.")),
DEFAULT_CONFIGURATION_FAILED(Doc.of(Level.FAULT) //
.text("Applying the default configuration failed.")),;
private final Doc doc;
private ChannelId(Doc doc) {
this.doc = doc;
}
public Doc doc() {
return this.doc;
}
}
/**
* Gets the Channel for {@link ChannelId#CONFIG_NOT_ACTIVATED}.
*
* @return the Channel
*/
public default StateChannel getConfigNotActivatedChannel() {
return this.channel(ChannelId.CONFIG_NOT_ACTIVATED);
}
/**
* Gets the Config Not Activated Warning State. See
* {@link ChannelId#CONFIG_NOT_ACTIVATED}.
*
* @return the Channel {@link Value}
*/
public default Value<Boolean> getConfigNotActivated() {
return this.getConfigNotActivatedChannel().value();
}
/**
* Internal method to set the 'nextValue' on
* {@link ChannelId#CONFIG_NOT_ACTIVATED} Channel.
*
* @param value the next value
*/
public default void _setConfigNotActivated(Boolean value) {
this.getConfigNotActivatedChannel().setNextValue(value);
}
/**
* Gets the Channel for {@link ChannelId#DUPLICATED_COMPONENT_ID}.
*
* @return the Channel
*/
public default StateChannel getDuplicatedComponentIdChannel() {
return this.channel(ChannelId.DUPLICATED_COMPONENT_ID);
}
/**
* Gets the Duplicated Component-ID Fault State. See
* {@link ChannelId#DUPLICATED_COMPONENT_ID}.
*
* @return the Channel {@link Value}
*/
public default Value<Boolean> getDuplicatedComponentId() {
return this.getDuplicatedComponentIdChannel().value();
}
/**
* Internal method to set the 'nextValue' on
* {@link ChannelId#DUPLICATED_COMPONENT_ID} Channel.
*
* @param value the next value
*/
public default void _setDuplicatedComponentId(Boolean value) {
this.getDuplicatedComponentIdChannel().setNextValue(value);
}
/**
* Gets the Channel for {@link ChannelId#WAS_OUT_OF_MEMORY}.
*
* @return the Channel
*/
public default StateChannel getWasOutOfMemoryChannel() {
return this.channel(ChannelId.WAS_OUT_OF_MEMORY);
}
/**
* Gets the Was Out of Memory Fault State. See
* {@link ChannelId#WAS_OUT_OF_MEMORY}.
*
* @return the Channel {@link Value}
*/
public default Value<Boolean> getWasOutOfMemory() {
return this.getWasOutOfMemoryChannel().value();
}
/**
* Internal method to set the 'nextValue' on {@link ChannelId#WAS_OUT_OF_MEMORY}
* Channel.
*
* @param value the next value
*/
public default void _setWasOutOfMemory(boolean value) {
this.getWasOutOfMemoryChannel().setNextValue(value);
}
/**
* Gets the Channel for {@link ChannelId#DEFAULT_CONFIGURATION_FAILED}.
*
* @return the Channel
*/
public default StateChannel getDefaultConfigurationFailedChannel() {
return this.channel(ChannelId.DEFAULT_CONFIGURATION_FAILED);
}
/**
* Gets the Default Configuration Failed State. See
* {@link ChannelId#DEFAULT_CONFIGURATION_FAILED}.
*
* @return the Channel {@link Value}
*/
public default Value<Boolean> getDefaultConfigurationFailed() {
return this.getDefaultConfigurationFailedChannel().value();
}
/**
* Internal method to set the 'nextValue' on
* {@link ChannelId#DEFAULT_CONFIGURATION_FAILED} Channel.
*
* @param value the next value
*/
public default void _setDefaultConfigurationFailed(boolean value) {
this.getDefaultConfigurationFailedChannel().setNextValue(value);
}
/**
* Gets the OpenEMS Clock - either the real system clock or a mocked clock for
* simulations.
*
* @return the Clock
*/
public Clock getClock();
/**
* Gets all enabled OpenEMS-Components.
*
* @return a List of OpenEMS-Components
* @throws IllegalArgumentException if the Component was not found
*/
public List<OpenemsComponent> getEnabledComponents();
/**
* Gets all enabled OpenEMS-Components of the given Type.
*
* @param <T> the given Type, subclass of {@link OpenemsComponent}
* @param clazz the given Type, subclass of {@link OpenemsComponent}
* @return a List of OpenEMS-Components
*/
public <T extends OpenemsComponent> List<T> getEnabledComponentsOfType(Class<T> clazz);
/**
* Gets all OpenEMS-Components.
*
* @return a List of OpenEMS-Components
* @throws IllegalArgumentException if the Component was not found
*/
public List<OpenemsComponent> getAllComponents();
/**
* Gets a OpenEMS-Component by its Component-ID. The Component is guaranteed to
* be enabled.
*
* @param componentId the Component-ID (e.g. "_sum")
* @param <T> the typed Component
* @return the OpenEMS-Component
* @throws OpenemsNamedException if the Component was not found
*/
@SuppressWarnings("unchecked")
public default <T extends OpenemsComponent> T getComponent(String componentId) throws OpenemsNamedException {
if (componentId.equals(OpenemsConstants.COMPONENT_MANAGER_ID)) {
return (T) this;
}
List<OpenemsComponent> components = this.getEnabledComponents();
for (OpenemsComponent component : components) {
if (component.id().equals(componentId)) {
return (T) component;
}
}
throw OpenemsError.EDGE_NO_COMPONENT_WITH_ID.exception(componentId);
}
/**
* Gets a OpenEMS-Component by its Component-ID. Be careful, that the Component
* might not be 'enabled'. If in doubt, use {@link #getComponent(String)}
* instead.
*
* @param componentId the Component-ID (e.g. "_sum")
* @param <T> the typed Component
* @return the OpenEMS-Component
* @throws OpenemsNamedException if the Component was not found
*/
@SuppressWarnings("unchecked")
public default <T extends OpenemsComponent> T getPossiblyDisabledComponent(String componentId)
throws OpenemsNamedException {
if (componentId == OpenemsConstants.COMPONENT_MANAGER_ID) {
return (T) this;
}
List<OpenemsComponent> components = this.getAllComponents();
for (OpenemsComponent component : components) {
if (component.id().equals(componentId)) {
return (T) component;
}
}
throw OpenemsError.EDGE_NO_COMPONENT_WITH_ID.exception(componentId);
}
/**
* Gets a Channel by its Channel-Address.
*
* @param channelAddress the Channel-Address
* @param <T> the typed Channel
* @return the Channel
* @throws IllegalArgumentException if the Channel is not available
* @throws OpenemsNamedException on error
*/
public default <T extends Channel<?>> T getChannel(ChannelAddress channelAddress)
throws IllegalArgumentException, OpenemsNamedException {
OpenemsComponent component = this.getComponent(channelAddress.getComponentId());
return component.channel(channelAddress.getChannelId());
}
/**
* Gets the complete configuration of this OpenEMS Edge.
*
* <p>
* Internally updates the cache if necessary and publishes a CONFIG_UPDATE event
* on update.
*
* @return the {@link EdgeConfig} object
*/
public EdgeConfig getEdgeConfig();
}