Implementation of one user registering and monitoring one sensor is done.
1. User interface
Now user can register and monitor any one of IUMSC sensors via application “CIMA Sensor Monitor” .
(1) Choose a sensor name, which is a CIMA service data source name, e.g “Bay1 Temperature”, from one of twelve IUMSC sensors;
(2) Type a data interval, which is CIMA service data reporting interval in seconds;
(3) Click button “Register”;
(4) After getting response from server “Successfully registered some sensor”, type a Monitor Rate, which is the frequency in seconds the user wants to send the polling requests to the server, and then click button “Monitor”, the most recent data will be shown on the screen continuously.
2. Implementation
(1) Client side[3]
Prototype provides a number of easy ways to make asynchronous requests via
new Ajax.Request(
"httpcimagateway.jsp?type="+encodeURI(type)+"&"+"source="+encodeURI(source)+"&"+"dataInterval="+encodeURI(dataInterval),
{
method:"get",
onComplete:function(xhr){
document.getElementById('fileUrl').value=xhr.responseText;
}
onFailure: function(xhr){
throw new Error('Registration failed: ' + xhr.statusText);
}
}
);
The asynchronous request itself is triggered by constructing a new instance of Ajax.Request, passing two parameters: the URL for the request, and a hash object containing properties that specify the options of the request. The URL specifies a JSP file that we will start CIMA service and register a sensor, and it passed the value of parcel type, CIMA service data source and CIMA service data reporting interval. In the options parameters object, we specify the HTTP method as a GET with the method property, and provide function reference for completion and failure handlers with onComplete and onFailure, respectively.
The completion handler is just to get the URL of the file which stores the data of the registed sensor. The failure handler, which is passed a reference to the XHR instance, throws an error depicting the failure status.
new Ajax.PeriodicalUpdater({success: 'details'}, fileUrl,
{
method: 'get',
frequency: monitorRate,
decay: 2,
onSuccess:function(xhr) {
eval(xhr.responseText);
}
}
);
This class can satisfy our needs to obtain and display data from the server at periodic intervals. First, we create an instance of Ajax.PeriodicalUpdater that refers to a new JSP page in the request URL(Note: for simplicity, currently this URL is just a file containing sensor data and this will be improved in next step). Second, frequency property in the parameters object controls the number of seconds between updates, and decay property controls the rate at which the request interval grows when the response is unchanged.
(2) Server side
- httpcimagateway.jsp
a. Handle HTTP request from the client;
b. If the parameter check passes, then do the service in the request, e.g. Register/Unregister/……
c. Return the URL of the file which contains the data
- do_Register
- Set up the embedded axis server and client listener;
- Set up the call to the CIMA service;
- Invoke the service
- do_Unregister
The procedure is similar with do_Register.
Discussion & Future work
- Change the storage of the data from file to queue;
- One user can register and monitor multiple sensors;
According to the requirement, users are allowed to
(a) register the different sensors, and/or
(b) register the same sensor with different data interval.
For one user, all registered sensors’ data will come to the same port, so
for (a), we only need to filter different data to different requests based on different sensors’ name, and this can be done easily; But
for (b), the current web service just outputs the “pure” data without any extra information to web service client. So the client cannot tell which data (parcel) belongs to which registration request.
- The problem with the interface of unregistering a sensor
Reference
[1] JSP : the complete reference. Hanna, Phil.
[2] Core servlets and JavaServer pages. Hall, Marty; Brown, Larry
[3]