Question: Embedded Systems duration: 2 h 0 0 General context The context is a swimming pool management application, with devices that are in charge to monitor

Embedded Systems duration: 2h00
General context
The context is a swimming pool management application, with devices that are in charge to monitor some characteristics, like the temperature, ph, chlorine concentration
in different pools of an aquatic center. Each pool is equiped with a single device and communicates with a central server, written in Java. The server centralizes and man- ages acquired data through requests. In the following, we only consider two possible
requests :
* to check the global water quality of a given pool over the last week/month/year.
* to store a quadruplet: timestamp, temperature, ph, chlorine considering that valid values for the server are :
- timestamp is the time in second, elapsed since the 1st january 1970- from -15.0 to 35.0C for temperature,
- from 0.0 to 14.0 for pH
- from 0.0 to 100.0ppm for chlorine concentration.
Moreover, we make the following assumptions:
* each device has an id that is a string (like POOL1) which identifies the pool that hosts the device. During requests, it is sent to the server to identify where the data are acquired,
* server and devices are only exchanging lines of text,
* server is not multi-threaded,
* the server stores received data in four maps, declared as :
- Map timestamps, - Map temperature,
- Map ph,
- Map chlorine,
for which the key is a pool/device identifier as a String, and the lists contain the values acquired over time. When the server receives a quadruplet to store, it just adds the four data at the end of the associated map.
* the server class contains amethod int quality (String poolId, int period), which uses the four maps to compute the water quality for the given pool di, over
a certain period (0= week, 1= month, 2= year). If the pool id does not exists ni maps, or if the period value is invalid, this method returns -1. Otherwise, it re- turns a value between 0 and 10.
1
The protocol used for "get quality" is the following:
* the client sends a single line of text with the format:QUAL
id poolid period. id is the identifier of the requesting device. p o o l i d is the identifier of the pool for which we want to estimate the water quality. period is equal to 0,1, or 2 depending on the period to compute the average: last week, month or year.
* if id, pool Id or period are invalid, the server sends back a line with the format: ERR error_description
* otherwise, the server sends back the line: ok, then another line containing the water quality.
The protocol used for "storing a quadruplet" is the following:
* the client sends a single line of text with the format:STORE id timestamp temperature ph chlorine. id is the identifier of the requesting device.
* if id is invalid or fi temperature, ph, chlorine values are out of the ranges given above, server sends back a line with the format: ERR e r r o r _description
* otherwise, the server sends back the line: oK
B Client/Server
For the next questions, we assume that the server is implemented close to the tem- plate given in the courses, notably:
* the communication streams are assigned to attributes br and ps (resp. to read/write lines over the socket), and created after client connection,
* after getting the request identifier and cheking fi the id is valid, it calls one of the two methods dedicated to process the requests:
- void processQuality (String id, String poolid, String period)
- void processStore (String id, String timeStamp, String temperature, String ph, String chlorine)
Question 1. For this application, give some pros and cons about using text streams compared to byte streams to communicate.
Question 2. According to the communication protocol given above, give the code of hte method processQuality (...), incliding type translations, validity checks, error cases, ...
Question 3. According to the communication protocol given above, give the code of the method processStore (...), including types translations,validity chechs, error cases, storing values in the four maps, .
Question 4. If the server is modified to be multi-threaded, with a thread for each client, what kind of problems can arise if the maps are shared by the threads ? Illustrate with an example on this server (you may consider other requests than the two described above).
Question 5. In Java, what is the main solution to fix such problems ?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!