## 3 System Framework Overview
### Middleware Layer
#### 3.2.2 Context Management  
The context manager is responsible for managing requests from the context acquisition module, where contextual information is being obtained, as well as for correlating the contexts with the services which are specified by the service providers in order to identify the most suitable services and control actions for the relating context. This module is the core of the context-aware middleware cloud and encloses several various distributed engines that interact with each other, binding their operations as illustrated in Figure 9.  
At first, the Context Retrieval Engine of the context management module is responsible for triggering requests to periodical retrieve contextual information via the context aggregator and distribute it to the corresponding components of the system. In addition, all system components can initiate context requests from the context-aware middleware cloud simply by using a web service running in the cloud server with an ID and an attribute context set. The proposed framework employs two of the most used distribution mechanisms [45]:  
Figure 8: Screenshot of XML code listing concerning the generated context-aware modeling structure. * Subscribe/Publish or Notification; All system components interested in certain contextual information can subscribe to the context-aware middleware cloud and be notified each time that occurs an update of their interest. * Polling; All system components can make at any time, active queries for contextual information of their interest. Depending on the applied modeling techniques, various query methods may be employed. After the infiltration of duplicate and rejected contextual data, the retrieval engine recovers the related information and responds by returning the most relevant and accurate of it. Additionally, the necessity for more accurate and certain information leads to the demand for context inference. Although the greater part of the context inference is performed inside the context acquisition module, this engine operates as a context transformer effecting on changes of specific information. The context inference engine receives specific contextual data asserted in the ontology-based context modeling structure in terms of OWL as sets of facts and, incorporating appropriate axioms and inference rules based on second-order logic, extracts high-level contextual information as logical consequences of the data in the given ontology. The context inference task is sequentially looping through three steps (matching, selecting, and executing the rules). Since the rules execution often results in new individual or sets of facts which are being added to the knowledge base, the loop is triggered to be continued until no new rules can be further matched. In other words, the task of context inference is to extract high-level contextual information associated with some fundamental processes such as the validation of context values, the removal of outliers, the completion of missing values, the checking of context inconsistencies and the application of calculations for obtaining some new values. For instance, environment temperature expressed in the Fahrenheit climax (\({}^{\circ}\)F) can be transformed to the Celsius climax (\({}^{\circ}\)C) by applying the corresponding mathematical transformation function or the exact location of a place can be found by the provided longitude and latitude information. The most significant operation of the context management module is the mapping of contextual data to one or more respective services to identify the appropriate actions for accomplishing these services. This engine is assigned with the task of finding the best possible matches between context and probable services as well as of combining these matches along with proper actions, through the implementation of suitable matching criteria and algorithms.