[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2004-04-19
6
Medium Priority
?
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

656 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