# Sensorial Network Framework Embedded in Ubiquitous Mobile Devices
## 3 Sensorial Network Framework Embedded in Ubiquitous Mobile Devices
### Implementation
#### 3.5.2 Backend Application  
There are many ways to implement the backend application. The one that was chosen in this study is based on the spring framework and is convenient, easy to use and extremely fast in developing applications in Java. In essence, the spring framework constitutes a step forward from old conventional rules to new and reasonable simplification for developers through comprehensive solutions. When web-based services are considered through the spring framework [39] for the backend, the string boot has to be mentioned, as it combines all classical web containers based on XML configuration files. However, for the proposed solution, it is a static and ineffective old approach, and Java annotation-based configurations in a minimalistic form, as outlined in the following code, are therefore preferred. The key principal of the backend server concerns the request and response handling through a Hyper Text Transfer Protocol (HTTP), where knowledge of how a HTTP works comes in handy. The suggested implementation is based on the spring framework, which brings to developers' attention the business logic of the application, rather than the reinvention of the wheel. To better understand the business logic of the application, the backend implementation is outlined in Figure 9 on the basis of the request and response process flow principal. The parts of the spring framework are represented in blue. The parts of the internal implementation are represented in yellow.  
Figure 8: Application logic: Coupling of activities and reaction of activities to events.  
At first, the request is received on a server via the Dispatcher Servlet, which immediately dispatches the task to HandlerMapping for the selection of the appropriate controller. It uses mapping, defined in the controller, and returns the selected handler and controller back to the DispatcherServlet. Afterwards, the task is sent to the HandlerAdapter, which calls the business logic of the controller. The business logic, with a persistent data layer, is processed, and the result is sent to the model, which returns the logical name of the view to the HandlerAdapter. The DispatcherServlet dispatches the task of resolving the view corresponding to the view name to the ViewResolver and returns the view mapped to the view name. The DispatcherServlet sends the rendering process to the returned view, which renders the model data and returns the response.  
MongoDB was used as the main database engine, as its high quality has been proven in many cases. MongoDB is a document-based database, where documents are similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents. It supports a dynamic schema definition, which can change in real time, without data constraints. Moreover, it provides a high-performance data persistence, where the index supports faster queries, together with a high availability, provided via a replication facility, called replica sets. Additionally, it has automatic scaling, where horizontal scalability is part of the core MondoDB functionality, with automatic shading of distribution data across a cluster of machines. Once the database engine is installed on a server, and it runs in a separate process, listening to default port 27017, it is possible to start to use Java database clients to connect to a local host. For the purpose of interaction, a database engine was used, with database client implementation, based on the spring framework, via spring-data-mongodb. The interface is defined in the following source code, which enables coupling data manipulation operations by annotations. An improved database was considered for the sake of indexing and obtaining a more effective data layout [40].