Skip to content

Commit bf777c7

Browse files
authored
Merge pull request #16 from wldt/release_0.3.0
Release 0.3.0
2 parents 8b4501d + 417f9c7 commit bf777c7

99 files changed

Lines changed: 7646 additions & 4965 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 76 additions & 66 deletions
Large diffs are not rendered by default.

build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file was generated by the Gradle 'init' task.
33
*/
44
group = "io.github.wldt"
5-
version = "0.2.1"
5+
version = "0.3.0"
66
description = "The core library to build White Label Digital Twins"
77
java.sourceCompatibility = JavaVersion.VERSION_1_8
88

@@ -14,14 +14,14 @@ plugins {
1414

1515
repositories {
1616
mavenCentral()
17-
17+
mavenLocal()
1818
}
1919

2020
dependencies {
2121
api("org.apache.commons:commons-lang3:3.9")
22-
api("ch.qos.logback:logback-classic:1.4.6")
22+
api("ch.qos.logback:logback-classic:1.4.12")
2323
api("javax.inject:javax.inject:1")
24-
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.8.1")
24+
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.1")
2525
}
2626

2727
java {

images/wldt_structure.jpg

1.28 MB
Loading

src/main/java/it/wldt/adapter/digital/DigitalAdapter.java

Lines changed: 107 additions & 394 deletions
Large diffs are not rendered by default.

src/main/java/it/wldt/adapter/physical/ConfigurablePhysicalAdapter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package it.wldt.adapter.physical;
22

3+
import it.wldt.exception.WldtWorkerException;
4+
35
/**
46
* Authors:
57
* Marco Picone, Ph.D. (picone.m@gmail.com)
@@ -13,7 +15,11 @@ public abstract class ConfigurablePhysicalAdapter<C> extends PhysicalAdapter {
1315

1416
private C configuration;
1517

16-
public ConfigurablePhysicalAdapter(String id, C configuration){
18+
private ConfigurablePhysicalAdapter() {
19+
super("");
20+
}
21+
22+
public ConfigurablePhysicalAdapter(String id, C configuration) {
1723
super(id);
1824
this.configuration = configuration;
1925
}

src/main/java/it/wldt/adapter/physical/PhysicalAdapter.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import it.wldt.core.event.WldtEventBus;
55
import it.wldt.core.event.WldtEventFilter;
66
import it.wldt.core.event.WldtEventListener;
7-
import it.wldt.core.worker.WldtWorker;
7+
import it.wldt.core.engine.DigitalTwinWorker;
88
import it.wldt.exception.EventBusException;
99
import it.wldt.exception.PhysicalAdapterException;
1010
import it.wldt.exception.WldtRuntimeException;
@@ -33,7 +33,7 @@
3333
* same time on the Digital Twin with the aim to handle different interaction with the physical layer according to the
3434
* nature of the twin and the associated physical device.
3535
*/
36-
public abstract class PhysicalAdapter extends WldtWorker implements WldtEventListener {
36+
public abstract class PhysicalAdapter extends DigitalTwinWorker implements WldtEventListener {
3737

3838
private static final Logger logger = LoggerFactory.getLogger(ConfigurablePhysicalAdapter.class);
3939

@@ -45,7 +45,12 @@ public abstract class PhysicalAdapter extends WldtWorker implements WldtEventLis
4545

4646
private PhysicalAssetDescription adapterPhysicalAssetDescription;
4747

48-
public PhysicalAdapter(String id){
48+
private PhysicalAdapter(){
49+
50+
}
51+
52+
public PhysicalAdapter(String id) {
53+
super();
4954
this.id = id;
5055
}
5156

@@ -101,19 +106,19 @@ public void setPhysicalAdapterListener(PhysicalAdapterListener physicalAdapterLi
101106
public abstract void onAdapterStop();
102107

103108
protected void publishPhysicalAssetPropertyWldtEvent(PhysicalAssetPropertyWldtEvent<?> targetPhysicalPropertyEventMessage) throws EventBusException {
104-
WldtEventBus.getInstance().publishEvent(getId(), targetPhysicalPropertyEventMessage);
109+
WldtEventBus.getInstance().publishEvent(this.digitalTwinId, getId(), targetPhysicalPropertyEventMessage);
105110
}
106111

107112
protected void publishPhysicalAssetEventWldtEvent(PhysicalAssetEventWldtEvent<?> targetPhysicalAssetEventWldtEvent) throws EventBusException {
108-
WldtEventBus.getInstance().publishEvent(getId(), targetPhysicalAssetEventWldtEvent);
113+
WldtEventBus.getInstance().publishEvent(this.digitalTwinId, getId(), targetPhysicalAssetEventWldtEvent);
109114
}
110115

111116
protected void publishPhysicalAssetRelationshipCreatedWldtEvent(PhysicalAssetRelationshipInstanceCreatedWldtEvent<?> targetPhysicalAssetRelationshipWldtEvent) throws EventBusException {
112-
WldtEventBus.getInstance().publishEvent(getId(), targetPhysicalAssetRelationshipWldtEvent);
117+
WldtEventBus.getInstance().publishEvent(this.digitalTwinId, getId(), targetPhysicalAssetRelationshipWldtEvent);
113118
}
114119

115120
protected void publishPhysicalAssetRelationshipDeletedWldtEvent(PhysicalAssetRelationshipInstanceDeletedWldtEvent<?> targetPhysicalAssetRelationshipWldtEvent) throws EventBusException {
116-
WldtEventBus.getInstance().publishEvent(getId(), targetPhysicalAssetRelationshipWldtEvent);
121+
WldtEventBus.getInstance().publishEvent(this.digitalTwinId, getId(), targetPhysicalAssetRelationshipWldtEvent);
117122
}
118123

119124
public PhysicalAssetDescription getPhysicalAssetDescription() {
@@ -212,7 +217,7 @@ protected void updatePhysicalAssetDescription(PhysicalAssetDescription physicalA
212217
this.physicalActionEventsFilter = new WldtEventFilter();
213218
else {
214219
//Clean existing subscriptions and the local event filter
215-
WldtEventBus.getInstance().unSubscribe(this.id, this.physicalActionEventsFilter, this);
220+
WldtEventBus.getInstance().unSubscribe(this.digitalTwinId, this.id, this.physicalActionEventsFilter, this);
216221
this.physicalActionEventsFilter.clear();
217222
}
218223

@@ -221,7 +226,7 @@ protected void updatePhysicalAssetDescription(PhysicalAssetDescription physicalA
221226
this.physicalActionEventsFilter.add(PhysicalAssetActionWldtEvent
222227
.buildEventType(PhysicalAssetActionWldtEvent.EVENT_BASIC_TYPE, physicalAssetAction.getKey()));
223228

224-
WldtEventBus.getInstance().subscribe(this.id, this.physicalActionEventsFilter, this);
229+
WldtEventBus.getInstance().subscribe(this.digitalTwinId, this.id, this.physicalActionEventsFilter, this);
225230

226231
}
227232
else
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package it.wldt.augmentation;
2+
3+
/**
4+
* @author Marco Picone, Ph.D. - picone.m@gmail.com
5+
*/
6+
public abstract class AugmentationFunction<T> implements Runnable {
7+
8+
private String id;
9+
10+
private AugmentationFunctionListener<T> listener;
11+
12+
private AugmentationFunction(){
13+
14+
}
15+
16+
public AugmentationFunction(String id, AugmentationFunctionListener<T> listener) {
17+
this.id = id;
18+
this.listener = listener;
19+
}
20+
21+
@Override
22+
public void run() {
23+
try{
24+
25+
T result = execute();
26+
if(this.listener != null)
27+
this.listener.onFunctionResult(result);
28+
29+
}catch (Exception e){
30+
if(this.listener != null)
31+
this.listener.onFunctionError(e.getLocalizedMessage());
32+
//TODO Else + Log
33+
34+
}
35+
}
36+
37+
public abstract T execute();
38+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package it.wldt.augmentation;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.concurrent.ExecutorService;
6+
import java.util.concurrent.Executors;
7+
8+
/**
9+
* @author Marco Picone, Ph.D. - picone.m@gmail.com
10+
*/
11+
public class AugmentationFunctionExecutor {
12+
13+
private static final int AUGMENTATION_FUNCTION_THREAD_SIZE = 5;
14+
15+
private ExecutorService functionExecutorService = null;
16+
17+
private static AugmentationFunctionExecutor instance;
18+
19+
private List<AugmentationFunction<?>> augmentationFunctionList = null;
20+
21+
private AugmentationFunctionExecutor(){
22+
this.functionExecutorService = Executors.newFixedThreadPool(AUGMENTATION_FUNCTION_THREAD_SIZE);
23+
this.augmentationFunctionList = new ArrayList<>();
24+
}
25+
26+
public static AugmentationFunctionExecutor getInstance(){
27+
if(instance == null)
28+
instance = new AugmentationFunctionExecutor();
29+
30+
return instance;
31+
}
32+
33+
public void addFunction(AugmentationFunction<?> augmentationFunction){
34+
this.augmentationFunctionList.add(augmentationFunction);
35+
}
36+
37+
public void deleteFunction(String functionId){
38+
//TODO Implement
39+
}
40+
41+
public void execute(){
42+
this.augmentationFunctionList.forEach(function -> {
43+
this.functionExecutorService.execute(function);
44+
});
45+
46+
this.functionExecutorService.shutdown();
47+
}
48+
49+
}

0 commit comments

Comments
 (0)