# E-MQTT: End-to-End Synchronous and Asynchronous Communication Mechanisms in MQTT Protocol
## 4 Implementation  
The communication framework (CM) [55] serves as an application-level communication framework employed in the development of distributed systems. The CM offers a range of options and communication services that are adaptable to the specific requisites of applications, rendering it more versatile. As a service of the CM, we have implemented E-MQTT, building upon the foundation of MQTT version 3.1.1. E-MQTT has been implemented and assessed utilizing the Java Development Kit (JDK) 20 within the integrated development environment (IDE) Eclipse (2023-03 version). Figure 12 shows a snapshot of the Eclipse IDE housing the E-MQTT implementation. The source codes of the whole CM are available at the Github repository ([[https://github.com/ccslab/CM.git](https://github.com/ccslab/CM.git)]([https://github.com/ccslab/CM.git](https://github.com/ccslab/CM.git)) (accessed on 14 November 2023)) and, specifically, the E-MQTT codes can be found at [[https://github.com/ccslab/CM/tree/emqtt/CM/src/kr/ac/konkuk/ccslab/cm](https://github.com/ccslab/CM/tree/emqtt/CM/src/kr/ac/konkuk/ccslab/cm)]([https://github.com/ccslab/CM/tree/emqtt/CM/src/kr/ac/konkuk/ccslab/cm](https://github.com/ccslab/CM/tree/emqtt/CM/src/kr/ac/konkuk/ccslab/cm)) (accessed on 14 November 2023). To get more information on how to configure and run CM applications that contain E-MQTT functionalities, the quick start guide document can be found at our web page ([[https://sites.google.com/site/kucsclab/research/cm](https://sites.google.com/site/kucsclab/research/cm)]([https://sites.google.com/site/kucsclab/research/cm](https://sites.google.com/site/kucsclab/research/cm)) (accessed on 14 November 2023)). In both the PUBLISH and SUBSCRIBE packets, a publisher as well as a subscriber possess the capacity to specify QoS 3, thereby establishing a distinction from the existing range of QoS levels spanning 0 through 2. Notably, the QoS field has also been incorporated into the PUBREC, PUBREL, and PUBCOM packets. When a node receives PUBLISH, PUBREC, PUBREL, and PUBCOMP packets, their course of action aligns with the existing MQTT protocol if the QoS level is 2. Conversely, if the QoS level is 3, the proposed E-MQTT is followed. Figure 13 portrays a class diagram delineating the structure of E-MQTT within the CM. Within this diagram, the principal classes encompass _CMMqttManager_ and _CMMqttEventHandler_. _CMMqttManager_ is responsible for processing MQTT-related requests originating from a CM client (publisher or subscriber) application. In cases where the publisher requests the PUBLISH service, _CMMqttManager_ verifies all the required parameters. The mandatory parameters encompass the topic and the application message, mandating input  
Figure 11: Flowcharts showing the subscriber-side execution flow of E-MQTT. values from the publisher client. Optional parameters encompass QoS, DUP, and retain flags, along with the minimum number of responses. Should these optional parameters be omitted by the publisher, the default value of 0 is automatically assigned. If the minimum number of response messages is set as equal to or greater than 1, E-MQTT starts the synchronous mode by registering the response (PUBREC) event type in an event synchronization object, of which the class is _CMEventSynchronizer_. The synchronization object is shared by both the _CMMqttManager_ and _CMMqttEventHandler_ classes to synchronize them. The _CMMqttManager_ thread then gets a lock on the synchronization object and waits for the response message by calling the _wait_() method of the synchronization object. Figure 12: E-MQTT implementation environment. Figure 13: Class diagram of E-MQTT. The _CMMqttEventHandler_ class has a crucial role in the confirmation and processing of incoming MQTT packets. Because the CM uses different threads for the _CMMqttManager_ and _CMMqttEventHandler_ classes, the _CMMqttEventHandler_ class receives messages asynchronously and independently from the task of the _CMMqttManager_ class.