5. Runtime Environment (RTE) & Synchronization
The RTE handles the communication between frontend and backend.
5.1 The Manager
The Manager (e.g., CarrentalManager) is a singleton available in both Backend (Java) and Frontend (TS). It holds the state of all loaded domain objects.
- Identity Map: Ensures that for a given ID, only one object instance exists in memory.
- CRUD:
getById(id),getAll(),create(),delete().
5.2 The Command System
Synchronization is based on the Command Pattern.
- Action: User clicks a button ->
user.setName("Alice"). - Command Creation: The setter
setNamecreates aUser_SetNameCommand(id, "Alice"). - Execution (Local): The command is executed locally (optimistic update).
- Transmission: The command is serialized to JSON and sent via WebSocket to the backend.
- Execution (Backend):
- The backend receives the JSON.
- Deserializes it to the Java Command class.
- Executes
doAction(): Updates the backend object and persists it to the DB.
- Broadcast: The backend sends the command JSON to all other connected clients.
- Execution (Remote): Other clients receive the JSON, deserialize it, and execute it locally.
5.3 The Observer Pattern
The frontend uses an Observer pattern to automatically update the UI.
- Registration: When a GUI component uses a domain object (e.g.,
@GemText(value=user.name)), the generated code automatically registers an observer onuser. - Notification: When
user.setName(...)is called (locally or via sync), the observer is triggered. - Update: The Angular Change Detection is triggered, and the UI updates.
Manual Observation: You can manually register observers in your HWC:
GUIUtils.registerObserverToDomainObject(user, () -> {
// Callback when user changes
});
< Previous: Frontend Logic | Back to Index | Next: Styling >