Skip to content

Package: AbstractSingleTopicPeriodicGenerator

AbstractSingleTopicPeriodicGenerator

nameinstructionbranchcomplexitylinemethod
AbstractSingleTopicPeriodicGenerator(ApplicationContext, GeneratorScheduler, String)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
close()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
tick(Instant)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Red Hat Inc and others.
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Red Hat Inc - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.kura.simulator.app.data;
14:
15: import java.time.Instant;
16:
17: import org.eclipse.kapua.kura.simulator.app.ApplicationContext;
18: import org.eclipse.kapua.kura.simulator.app.Handler;
19: import org.eclipse.kapua.kura.simulator.app.Sender;
20: import org.eclipse.kapua.kura.simulator.generator.GeneratorScheduler;
21: import org.eclipse.kapua.kura.simulator.topic.Topic;
22:
23: public abstract class AbstractSingleTopicPeriodicGenerator implements Handler {
24:
25: private final GeneratorScheduler.Handle handle;
26: private final ApplicationContext context;
27: private final Topic topic;
28:
29: public AbstractSingleTopicPeriodicGenerator(final ApplicationContext context, final GeneratorScheduler scheduler, final String dataTopic) {
30: this.context = context;
31: this.handle = scheduler.add(this::tick);
32: this.topic = Topic.data(dataTopic);
33: }
34:
35: @Override
36: public void close() throws Exception {
37: this.handle.remove();
38: }
39:
40: protected void tick(final Instant timestamp) {
41: update(timestamp, this.context.sender(this.topic));
42: }
43:
44: protected abstract void update(final Instant timestamp, final Sender sender);
45: }