Solved

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

Posted on 2004-04-19
6
308 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet requestdispatcher include and forward differences 1 39
Glassfish admin console not working 1 33
Html Table Looping (part 2) 5 27
junit as external jar or library 7 23
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

839 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