CSCI 470
Web Science
Spring 2013

Montana Tech
Computer Science & Software Engineering



Assignment #7 - GeoTrack servlet
Due: 10PM, Thurs 3/14.

You will be building a Java servlet that provides a web service that tracks the location of users who are roaming around with their mobile devices. Users can update the system with their current location. They can also query the system to find people within a given distance of their location.


Overview. Each user in the system is uniquely identified by a string ID (e.g. a MAC address or cell phone ID). Only the user themselves knows their unique ID, the rest of the world only sees a friendly name that users get to choose themselves. You are building a Java servlet that provides the following functions: Coordinate system. Mobile devices report their position in UTM coordinates. UTM coordinates consist of two float-point numbers, an easting and a northing. The easting specifies how many meters the device is to the east of a fixed grid reference location. Similarly the northing is how far the device is north of the grid reference. To calculate the distance between two positions in UTM coordinates, use the Pythagorean theorem.

Web service input. You are building a servlet that provides a RESTful web service. The following GET parameters are accepted by the web service: Web service output. The web service returns results in JSON format. Every response always contains a string field status. The status contains the string "OK" if the request was successful. If their was an error, the string contains a human-readable description of what went wrong (e.g. "ERROR: unable to parse distance as a floating-point value!"). Your servlet should be robust to bad requests and always return a well-formed JSON result with a status field.

The only command with an additional result field is the query command. This command returns a field near containing an array with 0 or more elements. Each element in the array contains information about a user within the queried radius. The fields returned in each element are: Here is an example result from a query request:
{
    "status": "OK",
    "near": [
        {
            "name": "carol",
            "northing": 50,
            "easting": 150,
            "distance": 70.710678,
            "timestamp": 1362722508
        },
        {
            "name": "bob",
            "northing": 150,
            "easting": 150,
            "distance": 70.710678,
            "timestamp": 1362722494
        }
    ]
}
Pruning data. Users may disappear from the network without deleting themselves from the tracker. You need to implement a pruning mechanism. If more than 1 minute has elapsed since a user's last update command, then you should delete that user from the tracker. This pruning should happen in a timely manner (i.e. within a few seconds of being over 1 minute stale, the user is deleted).

Concurrency. Remember that only one instance of your servlet object will exist. This object may get called by multiple threads in parallel. This will almost certainly happen when I test your submission. Thus you should ensure that all access to non-thread safe variables is appropriately protected. You can test your program with the Apache benchmark utility ab with a concurrency > 1.

Example implementation. The course schedule page has links to a working servlet implementation. You can experiment by directly typing in URLs with GET parameters to the servlet. There is also a HTML test client. The HTML client uses a PHP proxy page to avoid the cross-origin restriction of the AJAX requests (due to the different port numbers of the servlet and web server).

Servlet details. You should build a Java servlet as an embedded Jetty application (see the Java Servlets lecture/links for example code). You will need to download a copy of Jetty v9. You can develop your servlet in Eclipse if you like or work on the command line. The schedule page has example unix scripts showing the JAR files you need on your CLASSPATH to compile and run an embedded Jetty servlet. You can obtain the handy jetty-all JAR file from /home/staff/vertanen/jetty/lib on katie.

Your application should take a single command-line argument specifying the port to start the server on. You can assume any HTTP request to the server is for the servlet (i.e. the server does nothing but provide the web service).
Submission. I will be testing your program on the URL (and port) you send me via email. It needs to work from a client on Tech's wired network, but does not need to be accessible from outside this network or from the wireless network (because it probably won't). You also need to submit your source file(s) to the Moodle dropbox. The Moodle timestamp is the completion time for the assignment.

Page last updated: May 15, 2013