On CS machines, the directory
contains java sources implementing the straightforward file
synchronizer discussed in class. (The same files can be found in the project handouts directory.) Copy this
directory to your own filespace.
Later, this program will form the basis for some of our experiments
with distributed programming. For the moment, we will deal with a
non-distributed version that simply synchronizes different files on
the same machine. Your job is to make several extensions to this
- We will be using Java version 1.1 for this assignment (and
probably for the whole course)
- To use the java compiler, make sure that your path contains the
directory PATH=/l/jdk/bin:$PATH. For example, if you use
bash as your shell, you can type
at the command prompt or, more permanently, add the line
to the file .bashrc in your home directory.
- Once your path is set, typing
will compile all the classes in all your .java source files
and produce appropriate .class files containing executable
in the handout directory will have the same effect.
- You can now run the synchronizer by typing
java Snc file1 file2
(where file1 and file2 are two files or directories
to be synchronized) or just
Your assignment consists of several small extensions to the existing
code, finishing with a more open-ended task (for extra credit) where
you're invited to do some design of your own. The main point of the
project is for you to get comfortable with Java programming.
- The synchronizer can operate in several modes, which control what
happens when an inconsistency is detected. One of these, the
Ask mode, has been left unimplemented.
Write the body of the class Ask. Your code should print
the string explanation on the terminal and offer the user
the options of
You will need to refer to the java api guide for information
about how to do terminal I/O.
- executing atobThunk (you should print
atobMesg to explain what will happen in this case),
- executing btoaThunk (print
btoaMesg to explain what will happen in this
- leaving this file unsynchronized.
- As it stands, the synchronizer is quite verbose, printing
messages pretty much every time it does anything. When
debugging new functionality, these messages may be useful; but
we'd like to be able to turn them off.
- Write a new class Tracer (in a separate file
Tracer.java) that allows this tracing information to be
turned on and off dynamically. The Tracer class will
not actually have any instances; instead, it should provide
static methods tracingOn and tracingOff that
control whether tracing information is printed, plus a static
method println that can be used instead of
System.out.println elsewhere in the program for printing
- Fix the rest of the program to use Tracer.println as
- Add a command-line switch to turn tracing on.
- The method snc in class Snc uses the hash
method of SncFile objects to compute cryptographic
signatures of the two files, and then compares them to see
whether the files are the same. (This will be useful later,
since it will avoid transmitting the whole contents of the files
across the network when comparing them.)
The result type of hash is byte (array of
bytes). Suppose we want to hide the fact that cryptographic
signatures are represented as byte arrays.
Define a new class Signature with a constructor that
takes an object of class MD5 as argument and a method
compare that takes another Signature and tests
Make SncFile.hash return a Signature.
Modify Snc.snc appropriately.
- Extra credit: The present synchronizer may not choose the
most efficient way of making two directories equal. In
particular, if a file has been renamed on one side since the
last synchronize, it will be deleted on the other side and
re-created with the new name by copying. If the two directories
were actually on different machines, this could lead to a lot of
unnecessary network traffic.
This is actually wrong: moving a file does not
change its modification time, so in fact both files will be
deleted (with no extra network traffic!). Thanks to Marat for
pointing this out. For purposes of the exercise, you can assume
that files will be touched every time they are moved.
Extend the synchronization program so that it can recognize
(some) situations in which
files have been renamed and perform updates more efficiently (by
renaming on the other side).
- Watch the course newsgroup (
announcements and discussion.
- If you have questions that other people might find interesting,
please post them to the newsgroup (and cc them to
email@example.com, if you want a quick response from
- Discussion and collaboration are encouraged. Please feel
free to work on this assignment with other people, get help from
wherever you want, etc. If a significant part of what you turn in is
taken from someone else, please say so in the cover
A finished project consists of the following files:
- A file
README (or, if you prefer,
README.html) containing a brief, but well polished,
design document. This does not need to be long, but should just
describe what you've done, concentrating on any novel extensions
- Java source files (the parts you write should be well structured
Makefile such that typing
will recompile files as necessary and then show your program
- Place all the files for your finished project in a directory by
themselves on a CS machine.
- Make sure that this directory, all the files in it, and all
enclosing directories are world-readable.
- Send me an email whose subject line is
Project 1 submission" and whose body contains the pathname
of this directory.
- Your project will be considered as submitted at the time you send
this email. Don't modify the contents of the directory any more after
The project is due at the beginning of class on
Wednesday, September 10th.
I may possibly announce a postponement of this deadline if
the project ends up taking many people more time than I expect. Watch
the course news group.
B629: Languages for Programming the Web