Client Applications
Cognibase operates on a client-server architecture, with the Object Server managing the central state of objects, and various client applications connecting to it to replicate and interact with this object state. This architecture enables a wide range of applications to seamlessly work with Cognibase, ranging from console and desktop applications to mobile apps and web backends.
Overview
Cognibase Client Components enable developers to build robust and interactive applications that interact with the Object Server (SOM). The core of a Cognibase Client Application is the Client Object Manager (COM), which offers a comprehensive Software Development Kit (SDK) for a wide array of functionalities.
Key Features
- State Replication: Client applications maintain a local replica of the object state, ensuring high performance and reduced latency.
- Real-Time Updates: Changes made to the object state on the server are immediately propagated to all connected clients.
- Concurrency Control: Cognibase ensures that concurrent modifications from different clients are resolved consistently.
- Security: Communication between clients and the Object Server is secured, and access control mechanisms ensure that only authorized clients can connect.
- UI Thread Synchronization: Cognibase's GUI framework-specific adaptation libraries, help reduce boilerplate code when binding to UI controls.
UI Thread Synchronization
The COM is responsible to keep an always consistent internal state of object instances by continuously receiving transactions from the SOM. After updating its internal state, it fires .NET events in various levels: client, class type, live collection, reference instances and instance. The COM fires not only Cognibase specific events, like DataItemSaved
event, but also standard .NET events. Specifically the DataItem implements the INotifyPropertyChanged
, IDataErrorInfo
and INotifyDataErrorInfo
interfaces and the collections and reference lists implement INotifyCollectionChanged
, IList
, BindingList
and INotifyPropertyChanged
interfaces. All of these offer standard .NET events like PropertyChanged
, CollectionChanged
or ListChanged
that typical GUI frameworks like WPF, Avalonia, MAUI, WinUI and WinForms use to react to bound object changes. So, Cognibase exploits these capabilities to offer an easy way to developers to build real-time User Interfaces.
However, to typically exploit these capabilities someone has to handle the thread affinity of the UI elements. Thread affinity in GUI frameworks means that specific objects, often related to the user interface, are "bound" to a particular thread. In most cases, this is the main thread of the application. These objects are only allowed to be accessed or modified from the thread to which they have affinity, ensuring synchronized access and preventing race conditions. Attempting to update a UI control from a background thread will result in an exception, such as InvalidOperationException
.
Cognibase offers a per framework library that handles the invoking of events on the correct thread, typically the main thread, when it detects that the bound object for those events is probable a UI element or generally object bound to a thread. For example, in WinForms if it detects that a BindingSource
object is bound to a DataItemCollection
and it has to fire an event, then it invokes this event's event handlers in the GUI thread by using the WindowsFormsSynchronizationContext
. This process is transparent to the developer and is not required to write any code for this, reducing the boilerplate code.