March 27, 2002
CDA 4932 Distributed Systems and Applications
Assignment 3
Description:
In this assignment,
you will implement a distributed database search system. This application is
useful for large database systems where the data records are partitioned
between several database servers to improve searching performance. For
instance, a database containing people’s names and addresses may be partitioned
between two servers to contain last names in the range (A – M) on the first
server and in the range (N – Z) on the second server. When performing a search on
a person’s last name, only one part of the global database will be searched.
Also, searching for a person based on age will take half the time, since the
two halves of the database may be searched concurrently.
You will implement three
servers and one client, based on HLA architecture. Provided for you (see below)
is a list of 100 records containing a person’s information in a comma-separated
format (Last_name, First_name, Age). Partition this data into three (approximately)
equal sets. Each server federate will have one different set of data (e.g.,
server 1 has first 33 records, server 2 has next 33 records, and server 3 has the
last 34 records).
A client is a
federate very similar to original Chat example. You will read the user input
from command line and broadcast a request to all servers. The request can be
one of the following types:
age=25
lname=Smith
fname=Mark
This gives user an
ability to search for a specific age, last name and first name, respectively.
Each server upon
receipt of a request searches the respective field (age, last name or first
name) and returns a string containing the list of records found (full record
should be returned, including full name and age of EACH person with suitable
criteria). Hint: form a #-separated string for each record – it will be easier
to parse this string for a client using StringTokenizer class with a delimiter
of #. For example, a returned string may be
Mark, Smith, 25 # Joe, Allen, 25 # Mary, Jane, 25
How you would store
the data sets (parts of the original data file) is up to you. One approach
would be to have 3 text files with portions of original data set, and to load
the files into respective server applications on startup. Another approach is
to hard-code the array of names into your program. However, you would have to
write a separate server application for each dataset partition in each of these
implementations. You can also receive a filename as an argument on a command
line and load respective file (when main() function is called, it has String
[] args – an array of parameters passed to it; to
extract a filename passed as an argument to your program, use args[0] ). This way, you only need to write one version of a server federate,
and during startup, specify a different data file name for each one.
The client upon
receipt of a search string, will display results (one
record per line).
Files:
ü
Data
file, containing 100 records: namelist.txt
ü
Client
skeleton code: use the original Chat example (or your Client.java
from assignment 2), with certain modifications (parse the received string and
display records one per line)
ü
Server
skeleton code: modify your Server.java file from
assignment 2 (add mechanism to read records and to search records in the
array).
Hints:
ü
Suggested
array structure is: String data[33][3],
with first index being a record number, and the second being a record. Then, to
access each record in this array, use syntax data[i][0] for person’s last name, data[i][0] for person’s first name, and data[i][0] for person’s age.
ü
Important: when a server receives a request from a
client, it performs a search and broadcasts
the results. This way, even other servers will receive these results. However,
they won’t be able to recognize that; so the solution is to prefix each string
that is broadcast from a client with “C”, and each string broadcast from a
server with “S”. When a message arrives to the server, check the first
character of a string – if it is ‘C’, it’s a client request, so the server
processes it; if the first character is not ‘C’, then
ignore the message.
Concepts Learned:
ü
Distributed
search algorithm
ü
Working
with files in Java
ü
Finding
a substring in a string
ü
Parsing
strings with random delimiters
Submission:
ü
Submit
your source code (.java files), partitioned data files and your printed report
by April 3, 2002. Include your name on the report and in each source file as a
comment.