Solved

How to design complicated program with Supervisor/worker/threads?

Posted on 2004-04-19
6
300 Views
Last Modified: 2010-03-31
I'm really really lost right now in class.  I understand the basic concept of the Supervisor/worker pattern of developing a program, but have no idea how to design the following program.  My professor isn't much help, as I have asked him numerous questions with no results.  The problem is that I haven't had any networking/internet socket whatever you want to call it kind of class yet.  So the following program to be designed is a nightmare for me.  Please Help!  I must...

Develop a supervisor-worker system that will retrieve information from several web sites in parallel. The supervisor should provide a function to the outside world:
    public void getSites( int num_workers, ArrayList sitelist, ArrayList sitedata )
The caller will provide a list of URL's in sitelist. The entries will be structured as follows:  element i will be a computer name and element i+1 will be the item to retrieve. So, for example, if the user wants to retrieve these three web pages:
    http://www.cnn.com/index.html
    http://www.wired.com/news/
    http://www.lwn.net/Articles/

The sitelist list will contain these strings:
    "www.cnn.com"
    "/index.html"
    "www.wired.com"
    "/news/"
    "www.lwn.net"
    "/Articles/"

When the getSites() function returns, the array sitedata should have the results from each site (as strings), in order (so sitedata.get(0) would return the data from cnn.com; sitedata.get(1) returns the data from wired, and so forth).

After sending this data, the server responds with the contents of the site, including a few headers. You can include these in your sitedata ArrayList along with the rest of the site's response. HTTP requests are made to port 80.

How you structure your supervisor and workers is up to you, but each one should be its own object. The caller may want several workers to work simultaneously, so your program should work correctly for any number requested (it will be at least one, but your code should not impose an upper limit, in case the user has a really fast computer and wants to stress-test it).

You will probably want to create some test program that will call the supervisor with a list of sites to check. If you want to get fancy (which I don't), you can make a GUI interface with progress reporting, thermometers, and whatever else you like.
0
Comment
Question by:tmp09
  • 4
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10865469
you can use the URLConnection class to download page from varioius sites.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 10865510
your worker would look something like:

public class Worker implements Runnable
{
   private Supervisor Parent = null;

   public Worker(Supervisor parent)
   {
      Parent = parent;
   }

   public void run()
   {
      while supervisor still has pages to download
      {
          get next page to download from supervisor
          download page using URLConnection
          pass content back to supervisor
      }
   }
}
     
0
 
LVL 92

Expert Comment

by:objects
ID: 10865517
your supervisor would start the required number of worker threads and then wait until they have completed downloading all required pages.
0
 
LVL 92

Expert Comment

by:objects
ID: 10865525
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now