Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Callables ? Use Thread pools ? Use Futures ? Design and develop a program that accepts the name of a directory that contains a

Use Callables ?

Use Thread pools ?

Use Futures ?

Design and develop a program that accepts the name of a directory that contains a set of text-only files. The program must be executable as below. ?java PA2

?The program ensures the following: ?

a) there are two parameters to the main method ?

b) is a valid, readable directory ?

c) the directory does not exist. ?

If there is a violation of these requirements, the program prints an error message and stops.

The program must read the files in in parallel using multiple threads and create an index of every token (a sequence of characters delineated by white space) in the input files: the token, the file name in which it occurs and the line number or offset in the file must all be output to a file in . All file names and line numbers associated with a token must be output before outputting the next token and its related information.

Implement your program according to the following design:

1) Directory Processor: A Callable class that processes a single directory. It reads a directory name and adds the list of file names to a synchronized list of file names. It then submits through the Configurer (see (4) below) one File Processor (see (2) below) for each file.

2) File Processor: A Callable class that processes a single file. It reads a specific file and adds the lines and associated information (line number and file name) to a synchronized list of line information. It then submits through the Configurer (see (4) below) one Line Processor (see (3) below) for each line.

3) Line Processor: A Callable class that processes a single piece of line information. It reads a specific line info and adds the word, line info pair to a concurrent hash map.

4) Configurer: Maintains a list of directories, a list of file names, a list of lines, and a concurrent hash map. Provides getters for all these data structures. This is a singleton class. It also maintains a thread pool and has methods for submission of jobs to the executor framework.

5) Driver: Gets the parameters from the user and stores the directory name in the list of directory names. Submits a job to start the directory processor.

Find a way to ensure that the executor is shut down when there are no more threads.

As I mentioned in class, submit the full program. I need the driver as well, unlike what the assignment handout originally said.

Suppose the files data1 and data2 are files in the folder C:\Classes\ICS 440\PA2 Map\data. The file data1 contains the following three lines.

one two

three four

four

And data2 contains the following three lines.

one two three

two three four five six seven

eight

An output would be as follows. (The order of the tokens is unimportant.)

six: C:\Classes\ICS 440\PA2 Map\data\file2.txt:2

1

four: C:\Classes\ICS 440\PA2 Map\data\file1.txt:2 C:\Classes\ICS 440\PA2

Map\data\file1.txt:3 C:\Classes\ICS 440\PA2 Map\data\file2.txt:2

one: C:\Classes\ICS 440\PA2 Map\data\file1.txt:1 C:\Classes\ICS 440\PA2

Map\data\file2.txt:1

seven: C:\Classes\ICS 440\PA2 Map\data\file2.txt:2

two: C:\Classes\ICS 440\PA2 Map\data\file1.txt:1 C:\Classes\ICS 440\PA2

Map\data\file2.txt:1 C:\Classes\ICS 440\PA2 Map\data\file2.txt:2

three: C:\Classes\ICS 440\PA2 Map\data\file1.txt:2 C:\Classes\ICS 440\PA2

Map\data\file2.txt:1 C:\Classes\ICS 440\PA2 Map\data\file2.txt:2

five: C:\Classes\ICS 440\PA2 Map\data\file2.txt:2

eight: C:\Classes\ICS 440\PA2 Map\data\file2.txt:3

It is fine to output just the file name relative to the folder as opposed to the absolute path name.

Use a combination of thread pools, Callables, and Futures. All files must be processed in parallel to update a concurrent map implementation from java.util.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions