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: h
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 weekmonthyear
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 st january from to C for temperature,
from to for pH
from to ppm for chlorine concentration.
Moreover, we make the following assumptions:
each device has an id that is a string like POOL 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 multithreaded,
the server stores received data in four maps, declared as :
Map timestamps, Map temperature,
Map ph
Map chlorine,
for which the key is a pooldevice 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 week, month, year If the pool id does not exists ni maps, or if the period value is invalid, this method returns Otherwise, it re turns a value between and
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 or 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 errordescription
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 ClientServer
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 readwrite 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 For this application, give some pros and cons about using text streams compared to byte streams to communicate.
Question According to the communication protocol given above, give the code of hte method processQuality incliding type translations, validity checks, error cases,
Question 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 If the server is modified to be multithreaded, 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 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
