Skip to content

Commit 2115652

Browse files
committed
Minor changes and comments improved.
1 parent d1edaba commit 2115652

15 files changed

Lines changed: 204 additions & 70 deletions

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,4 +1989,12 @@ public class TestDigitalTwin {
19891989
}
19901990
}
19911991
}
1992-
````
1992+
````
1993+
## Storage Layer
1994+
1995+
The storage layer is a fundamental component of the WLDT library that allows the storage of the Digital Twin's state
1996+
and the related events (both from physical and digital spaces). The package associated to the Storage Layer are the following:
1997+
1998+
- ```it.wldt.storage```: Contains the main interfaces and classes to manage the storage layer.
1999+
- ```it.wldt.storage.model```: Contains the main classes and data structure to manage the storage layer data model.
2000+
- ```it.wldt.storage.query```: Contains the main classes and data structure to query the storage layer from other WLDT components (e.g., Digital Adapters).

src/main/java/it/wldt/core/engine/DigitalTwin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public class DigitalTwin implements ShadowingModelListener, PhysicalAdapterListe
4040

4141
private static final String EVENT_PUBLISHER_ID = "dt_core";
4242

43-
4443
// Internal TAG fo Logs
4544
private static final String TAG = "[WLDT-DigitalTwin]";
4645

@@ -134,6 +133,9 @@ public class DigitalTwin implements ShadowingModelListener, PhysicalAdapterListe
134133
*/
135134
private String digitalTwinId;
136135

136+
/**
137+
* Object used to synchronize the state of the Digital Twin
138+
*/
137139
private Object syncStateObject = new Object();
138140

139141
/**
@@ -229,6 +231,8 @@ private void init(ShadowingFunction shadowingFunction) throws ModelException, Wl
229231
//Set ShadowingListener, Init Model Engine & Add to the List of Workers
230232
this.shadowingFunction = shadowingFunction;
231233
this.shadowingFunction.setShadowingModelListener(this);
234+
235+
// Initialize the Digital Twin Model with digital twin ID, state manager, and shadowing function
232236
this.modelEngine = new ModelEngine(this.digitalTwinId, this.digitalTwinStateManager, this.shadowingFunction);
233237

234238
//Save the Model Engine as Digital Twin Life Cycle Listener

src/main/java/it/wldt/core/event/EventManager.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@
99
import org.slf4j.LoggerFactory;
1010
import java.util.HashMap;
1111

12+
/**
13+
* Author: Marco Picone (picone.m@gmail.com)
14+
* Date: 01/08/2024
15+
* Project: WLDT Framework
16+
* Event Manager class used centralize and simplify the event management in the WLDT Framework.
17+
* The Event Manager class provides a set of static methods to publish events associated to a target digital twin
18+
* and publisher (e.g., the physical adapter of the twin).
19+
*/
1220
public class EventManager {
1321

1422
private static final Logger logger = LoggerFactory.getLogger(EventManager.class);
1523

1624
/**
17-
*
18-
* @param digitalTwinId
19-
* @param publisherId
20-
* @param event
21-
* @throws EventBusException
25+
* Publishes an Event associated to a target digital twin and publisher
26+
* @param digitalTwinId Digital Twin Id
27+
* @param publisherId Publisher Id
28+
* @param event Event to be published
29+
* @throws EventBusException EventBus Exception in case of error
2230
*/
2331
private static void publishEvent(String digitalTwinId,
2432
String publisherId,
@@ -28,11 +36,12 @@ private static void publishEvent(String digitalTwinId,
2836
}
2937

3038
/**
31-
*
32-
* @param digitalTwinId
33-
* @param publisherId
34-
* @param adapterId
35-
* @param physicalAssetDescription
39+
* Notifies that a new Physical Asset Description (PAD) is available from a Physical Adapter associated
40+
* to a Digital Twin. The notification generates a Physical Asset Description Available Event.
41+
* @param digitalTwinId Digital Twin Id
42+
* @param publisherId Publisher Id
43+
* @param adapterId Adapter Id
44+
* @param physicalAssetDescription Physical Asset Description
3645
*/
3746
public static void notifyPhysicalAdapterPadAvailable(String digitalTwinId,
3847
String publisherId,
@@ -61,11 +70,11 @@ public static void notifyPhysicalAdapterPadAvailable(String digitalTwinId,
6170
}
6271

6372
/**
64-
* Publishes a Physical Asset Description Updated Event
65-
* @param digitalTwinId
66-
* @param publisherId
67-
* @param adapterId
68-
* @param physicalAssetDescription
73+
* Publishes a Physical Asset Description Updated Event associated to a target digital twin and publisher
74+
* @param digitalTwinId Digital Twin Id
75+
* @param publisherId Publisher Id
76+
* @param adapterId Adapter Id
77+
* @param physicalAssetDescription Physical Asset Description
6978
*/
7079
public static void notifyPhysicalAdapterPadUpdated(String digitalTwinId,
7180
String publisherId,
@@ -94,10 +103,10 @@ public static void notifyPhysicalAdapterPadUpdated(String digitalTwinId,
94103
}
95104

96105
/**
97-
* Publishes a Life Cycle Event
98-
* @param digitalTwinId
99-
* @param publisherId
100-
* @param lifeCycleState
106+
* Publishes a Life Cycle Event associated to a target digital twin and publisher
107+
* @param digitalTwinId Digital Twin Id
108+
* @param publisherId Publisher Id
109+
* @param lifeCycleState Life Cycle State
101110
*/
102111
public static void publishLifeCycleEvent(String digitalTwinId,
103112
String publisherId,

src/main/java/it/wldt/core/event/WldtEventBus.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,20 @@ private WldtEventBus(){
2929
this.subscriberMap = new HashMap<>();
3030
}
3131

32+
/**
33+
* Get the current instance of the WLDT Event Bus
34+
* @return the current instance of the WLDT Event Bus
35+
*/
3236
public static WldtEventBus getInstance(){
3337
if(instance == null)
3438
instance = new WldtEventBus();
3539
return instance;
3640
}
3741

42+
/**
43+
* Set the Event Logger for the current EventBus instance
44+
* @param eventLogger the Event Logger to set
45+
*/
3846
public void setEventLogger(IWldtEventLogger eventLogger){
3947
this.eventLogger = eventLogger;
4048
}
@@ -51,6 +59,13 @@ private Optional<SubscriptionDescriptor> getSubscriptionForDigitalTwin(String di
5159
return Optional.empty();
5260
}
5361

62+
/**
63+
* Publish a new event on the event bus
64+
* @param digitalTwinId the digital twin id
65+
* @param publisherId the publisher id
66+
* @param wldtEvent the event to publish
67+
* @throws EventBusException in case of error contains the exception with the error message
68+
*/
5469
public void publishEvent(String digitalTwinId, String publisherId, WldtEvent<?> wldtEvent) throws EventBusException {
5570

5671
if(this.subscriberMap == null)
@@ -97,6 +112,11 @@ public void publishEvent(String digitalTwinId, String publisherId, WldtEvent<?>
97112
}
98113
}
99114

115+
/**
116+
* Check if the provided event type is a WildCard Type
117+
* @param filterEventType the event type to check
118+
* @return true if the event type is a WildCard Type, false otherwise
119+
*/
100120
private boolean isWildCardType(String filterEventType){
101121
try{
102122
if(filterEventType != null){
@@ -115,6 +135,12 @@ private boolean isWildCardType(String filterEventType){
115135
}
116136
}
117137

138+
/**
139+
* Check if the provided event type match the WildCard Type
140+
* @param eventType the event type to check
141+
* @param filterType the filter type to check
142+
* @return true if the event type is a WildCard Type, false otherwise
143+
*/
118144
public boolean matchWildCardType(String eventType, String filterType){
119145
// If the filter type is a wild card filter
120146
if(isWildCardType(filterType)){
@@ -126,6 +152,14 @@ public boolean matchWildCardType(String eventType, String filterType){
126152
return false;
127153
}
128154

155+
/**
156+
* Subscribe a new client to the event bus
157+
* @param digitalTwinId the digital twin id
158+
* @param subscriberId the subscriber id
159+
* @param wldtEventFilter the event filter
160+
* @param wldtEventListener the event listener
161+
* @throws EventBusException in case of error contains the exception with the error message
162+
*/
129163
public void subscribe(String digitalTwinId, String subscriberId, WldtEventFilter wldtEventFilter, WldtEventListener wldtEventListener) throws EventBusException{
130164

131165
if(this.subscriberMap == null)
@@ -162,6 +196,14 @@ public void subscribe(String digitalTwinId, String subscriberId, WldtEventFilter
162196
}
163197
}
164198

199+
/**
200+
* Unsubscribe a client from the event bus
201+
* @param digitalTwinId the digital twin id
202+
* @param subscriberId the subscriber id
203+
* @param wldtEventFilter the event filter
204+
* @param wldtEventListener the event listener
205+
* @throws EventBusException in case of error contains the exception with the error message
206+
*/
165207
public void unSubscribe(String digitalTwinId, String subscriberId, WldtEventFilter wldtEventFilter, WldtEventListener wldtEventListener) throws EventBusException{
166208

167209
if(this.subscriberMap == null)

src/main/java/it/wldt/core/event/WldtEventTypes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package it.wldt.core.event;
22

3+
/**
4+
* Author: Marco Picone (picone.m@gmail.com)
5+
* Date: 01/08/2024
6+
* This class contains all the event types used in the WLDT Framework
7+
*/
38
public class WldtEventTypes {
49

510
public static final String MULTI_LEVEL_WILDCARD_VALUE = "*";

src/main/java/it/wldt/core/event/observer/IWldtEventObserverListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import it.wldt.core.event.WldtEvent;
44

5+
/**
6+
* Interface for the WldtEventObserverListener allowing to listen to the events of the WldtEventObserver
7+
*/
58
public interface IWldtEventObserverListener {
69

710
public void onEventSubscribed(String eventType);

src/main/java/it/wldt/core/event/observer/WldtEventObserver.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@
88
import java.util.Arrays;
99

1010
/**
11-
*
11+
* Author: Marco Picone (picone.m@gmail.com)
12+
* Date: 01/08/2024
13+
* Wldt Event Observer Class
14+
* This class is used to observe specific events generated by the Digital Twin Model and the Physical Adapters
15+
* Main mapped events and filters are:
16+
* - State Events: State Update and State Event Notifications
17+
* - Physical Asset Events: Physical Property Variation, Physical Event Notification, Physical Relationship Instance Creation and Deletion
18+
* - Physical Asset Action Events: Physical Action Trigger
19+
* - Digital Action Events: Digital Action Event
20+
* - Physical Asset Description Events: Physical Asset Description Available and Updated
21+
* - Life Cycle Events: Digital Twin Life Cycle Events
22+
* - Query Request Events: Storage Query Request Events
1223
*/
1324
public class WldtEventObserver implements WldtEventListener {
1425

@@ -39,6 +50,13 @@ public class WldtEventObserver implements WldtEventListener {
3950
private WldtEventObserver() {
4051
}
4152

53+
/**
54+
* Wldt Event Observer Constructor
55+
* @param digitalTwinId Digital Twin Id
56+
* @param observerId Observer Id
57+
* @param observerListener Observer Listener
58+
* @throws WldtRuntimeException Wldt Runtime Exception
59+
*/
4260
public WldtEventObserver(String digitalTwinId, String observerId, IWldtEventObserverListener observerListener) throws WldtRuntimeException {
4361

4462
this.digitalTwinId = digitalTwinId;
@@ -66,6 +84,12 @@ public WldtEventObserver(String digitalTwinId, String observerId, IWldtEventObse
6684
this.observerListener = observerListener;
6785
}
6886

87+
/**
88+
* Trigger the observation of events generated from the Digital Twin Model related to State Variations and Event
89+
* Notifications
90+
* @param eventTypeList List of Event Types to Observe
91+
* @throws EventBusException Event Bus Exception
92+
*/
6993
private void observeEventsWithFilter(WldtEventFilter targetFilter, String... eventTypeList){
7094
try{
7195
if(eventTypeList == null || eventTypeList.length == 0)
@@ -88,6 +112,12 @@ private void observeEventsWithFilter(WldtEventFilter targetFilter, String... eve
88112
}
89113
}
90114

115+
/**
116+
* Cancel the observation of events generated from the Digital Twin Model related to State Variations and Event
117+
* Notifications
118+
* @param targetFilter Filter to Cancel
119+
* @throws EventBusException Event Bus Exception
120+
*/
91121
public void unObserveEventsWithFilter(WldtEventFilter targetFilter) throws EventBusException {
92122
try{
93123
if (targetFilter != null && !targetFilter.isEmpty()) {

0 commit comments

Comments
 (0)