|
Assignments Links Schedule Syllabus |
Assignment 5: Distributed SnapshotRead the Chandy and Lamport article presenting an algorithm to construct consistent global state of a distributed system (distributed snapshot). Implement the global state detection algorithm to determine the state of a collection of remote objects and channels to and from their stubs. You may restrict the set of relevant remote objects to the arithmetic object that you implemented for the previous assignment. Record the state of an arithmetic object as the most recently computed value. The state of the stub is the most recently received value. Since we need to contact the stubs, they must register their names with the registry, too. Update the stub so that it listens to the network for snapshot commands. We will discuss a method shortly to reuse the exact same code to listen for network traffic, handle snapshot commands, and forward other traffic to the remote object or stub. Interpreter PatternWe will construct interpreters to filter network traffic of snapshot commands for remote objects and their stubs, passing on the filtered information to the remote object or its stub. The idea has a thread listening on a socket, read an entire line from the socket, and feed that line to a snapshot interpreter. The interpreter will execute any commands necessary to handle the snapshot, and reformulate the string to be passed to its client.Here is a usage example: public class CommandHandlingSlave implements Runnable
{ private SnapshotInterpreter snapInterp;
private Socket socket;
public CommandHandlingSlave (Socket _sock, _snapInterp) {
socket = _sock;
snapInterp = _snapInterp;
} // constructor
public void run ()
{ try
{ /* --> look here <-- -- -- -- -- -- -- -- */
Scanner scanner = new Scanner (socket.getInputStream ());
scanner = snapInterp.interpret (scanner);
/* --> end look here <-- -- -- -- -- -- */
// handle your commands as normal reading input from a scanner...
} catch (IOException e)
{ e.printStackTrace (System.err);
System.err.println ("Error handling network request: " + e);
}
} // run
} // class CommandHandlingSlave
A Snapshot InterpreterNow we're ready to handle the snap shots. Your interpreter should intercept any messages of the following forms:
Grading
|