Skip to content

Commit f63446d

Browse files
feat: create operating block observer artifact
1 parent dbbc524 commit f63446d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2023. Smart Operating Block
3+
*
4+
* Use of this source code is governed by an MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
package artifact.environment;
10+
11+
import application.controller.manager.EventManager;
12+
import cartago.Artifact;
13+
import cartago.INTERNAL_OPERATION;
14+
import cartago.OPERATION;
15+
import infrastructure.events.KafkaClient;
16+
17+
/**
18+
* CArtAgO artifact that is responsible to observe the operating block and expose its data.
19+
*/
20+
public class OperatingBlockObserverArtifact extends Artifact {
21+
private boolean working;
22+
private EventManager eventManager;
23+
/**
24+
* Initialize the operating block observer artifact.
25+
*/
26+
void init() {
27+
this.working = false;
28+
this.eventManager = KafkaClient.getInstance();
29+
}
30+
31+
/**
32+
* Start the Operating Block Observer.
33+
*/
34+
@OPERATION
35+
void start() {
36+
if (!working) {
37+
working = true;
38+
execInternalOp("poll");
39+
}
40+
}
41+
42+
/**
43+
* Internal artifact's operation used to polling for new events with the event manager.
44+
*/
45+
@INTERNAL_OPERATION
46+
void poll() {
47+
this.eventManager.poll(event -> {
48+
signal("event", event.getKey()); // tobe deleted
49+
});
50+
}
51+
}

0 commit comments

Comments
 (0)