On this page:
t_  query
Details
6.2.0.2

Running the T

For this homework set, you will design an application for managing the T’s subway system.

The objective of this homework is to improve your knowledge about Rust’s concurrency model and constructs. The assignment "combines" knowledge from Graph Traversals and Serving the Web.

Deadline Friday 20 March NOON, new due date Friday 27 March NOON.

t_query

The purpose of the t_query service is to manage the MBTA’s subway stations. It has two distinct tasks. First, t_query responds to queries by T riders on how to get from one station to another. The queries have the following format:

  from STATION to STATION

where STATION is a string that is supposed to uniquely identify a subway station.

Second, t_query accepts en/disable two kinds of commands from T operators:

  disable STATION

  enable STATION

The first one temporarily takes the specified station out of operations, the second one brings it back on line.

Here are some sample dialogs. The first one is a query by a newly arrived freshman student on how to get from the Airport station to the Northeastern stop:

  ===>>> from Airport to Northeastern

  Airport Station, take blue

  Maverick Station, take blue

  Aquarium Station, take blue

  State Station, take blue

  Government Center Station, take blue

  ---switch from blue to green

  Park Street Station, take green

  Boylston Street Station, take green

  Arlington Station, take green

  Copley Station, take green

  ---ensure you are on E

  Prudential Station, take E

  Symphony Station, take E

  Northeastern University Station, take E

My sample implementation picks the route with the fewest switches because newly arrived freshman students tend to come with huge suitcases. Next, some operator disables the Government station:To repair Government station, a real T operator would not use such a command but take the station out of the database and restart the service.

  ===>>> disable Government

  done

Not surprisingly, the next passenger at the Airport station gets completely different advice from the above on how to get to Northeastern:

  ===>>> from Airport to Northeastern

  Airport Station, take blue

  Maverick Station, take blue

  Aquarium Station, take blue

  State Station, take blue

  ---switch from blue to orange

  Downtown Crossing Station, take orange

  ---switch from orange to red

  Park Street Station, take red

  ---switch from red to green

  Boylston Street Station, take green

  Arlington Station, take green

  Copley Station, take green

  ---ensure you are on E

  Prudential Station, take E

  Symphony Station, take E

  Northeastern University Station, take E

Once Government Center is put back on-line,

  ===>>> enable Government

  done

the service once again suggests a route with a single transfer:

  ===>>> from Airport to Northeastern

  Airport Station, take blue

  Maverick Station, take blue

  Aquarium Station, take blue

  State Station, take blue

  Government Center Station, take blue

  ---switch from blue to green

  Park Street Station, take green

  Boylston Street Station, take green

  Arlington Station, take green

  Copley Station, take green

  ---ensure you are on E

  Prudential Station, take E

  Symphony Station, take E

  Northeastern University Station, take E

The service is robust and survives typos in the names of stations:

  ===>>> from Airport to Northe**stern

  no such destination: Northe**stern

  ===>>> from Airport to Center

  disambiguate your destination: Quincy Center Station Government Center Station Tufts Medical Center Station Malden Center Station

Similarly, operators also can’t trip up t_query:

  ===>>> disable Nor'easter

  no such station to disable: Nor'easter

  ===>>> enable Gov'm**nt

  no such station to enable: Gov'm**nt

Even an insistent operator who enables stations that are on-line or disables stations twice, can’t get the service to crash:

  ===>>> enable Government

  done

  ===>>> disable Government

  done

  ===>>> disable Government

  done

  ===>>> enable Government

  done

  ===>>> from Airport to Hynes

  Airport Station, take blue

  Maverick Station, take blue

  Aquarium Station, take blue

  State Station, take blue

  Government Center Station, take blue

  ---switch from blue to green

  Park Street Station, take green

  Boylston Street Station, take green

  Arlington Station, take green

  Copley Station, take green

  ---ensure you are on C D B

  Hynes Convention Center, take C D B

A single enable command suffices to bring Government Center back on-line, even though it was disabled twice.

Details

The currentHope springs eternal. four T lines are specified in four data files, named after their color: green.dat, blue.dat, red.dat, and orange.dat.

Your t_query server must listen for queries and commands on the local loopback interface (127.0.0.1) on port 12345. For each command or query, it spawns a separate process so that the service can cope with many queries in parallel.

As for the format of the responses, they do not need to match the interactions above exactly but they should come close. Regardless, t_query must be robust with respect to errors from passengers and operators.