CS 342 Labs 7A and 7B: Sort Server

Please note: the lab consists of two parts, A and B. Please complete part A before starting part B.

Please note: you must use GNU gmake instead of Sun make with the part B Makefile! If you see messages such as "make: Fatal error in reader: wrapper_macros.GNU, line 124: Unexpected end of line seen" when attempting to make, you're using Sun make. Either use gmake, or "alias make gmake" (which can be added to your .cshrc.mine).

Also, you must set your LD_LIBRARY_PATH environment variable.
For Sun CC:

% pkgadd sc
% setenv LD_LIBRARY_PATH ~levine/ACE_wrappers/build/SunOS5_sunc++:$LD_LIBRARY_PATH
Then, make and run main as usual.
For egcs:
% pkgadd egcs 
% setenv LD_LIBRARY_PATH ~levine/ACE_wrappers/build/SunOS5_egcs:$LD_LIBRARY_PATH
Then, make egcs=1 and run main as usual.

 

http://www.cs.wustl.edu/~levine/courses/cs342-s99/lab/lab7/

Lab date: 14 April-23 April 1999
Due date: 25 April 1999

Objective, Part A:

Extend/improve your sort program from Lab 6 to do the following:
  1. Support merge sort and at least one other sorting algorithm, in addition to selection sort.

  2. Support distributed sorting. Demonstrate this by reading at least two Sort_Requests from files and merging them together.

    A distributed sort partitions the original Sort_Request into multiple, smaller ones. It sends each small Sort_Request to a remote Sorter, then combines the results using mergesort. Note that we don't actually implement the distribution. We just provide the support for it, through the ability to read Sort_Requests from files. And, we provide mergesort, which is appropriate for combining sorted arrays.

  3. Decouple your code from the Sort_Viewer_Client.cc implementation by inserting an Adapter between them. The calls to the "raw" connect_to_viewer (), send_to_viewer (), and disconnect_from_viewer () functions work, but they're not clean. The Adapter class will 1) hide the sockfd and handle objects, and 2) make sure that connect_to_viewer () is called before send_to_viewer (), and disconnect_to_viewer () is called when done. That way, the user won't explicitly setup and teardown the connection to the viewer.

Objective, Part B:

Obtain familiarity with one OO programming framework, ACE.


Here's a high-level diagram of the sort program collaborators:

Preparation:

  1. Review your Lab 6, specifically the create_sorter Factory Method.
  2. Review the patterns used in this lab, including

Assignment, Part A:

  1. Add merge sort and at least one other sorting algorithm. Extend the create_sorter Factory Method to support creation of instances of Merge_Sort and your other Sorter.

    It's best if you structure your mergesort just like any other Sorter. Then, add a constructor that takes in an Array of Sort_Requests. Mergesort will then check each Sort_Request in the Array: if they're all SORTED, then it simply merges them together.

  2. Add support for reading Sort_Requests from a file, using IOStreams.

    To write/read Sort_Requests to/from files, you'll have to add ostream/istream operators. It's easiest to add a Sort_Request constructor that takes an istream argument. That way, you can construct a Sort_Request directly from the istream (instead of creating one, then streaming to it).

    Shifting enums is a bit tricky. Here's an example of on way to do it:

    
    enum E { a, b, c };
    
    ostream &operator<< (ostream &os, const E e)
    {
      return os << static_cast<const int> (e);
    }
    
    istream &operator>> (istream &is, E &e)
    {
      return is >> reinterpret_cast<int &> (e);
    }
    

  3. Insert an Adapter between your code and the Sort_Viewer_Client.cc. The Adapter's constructor should call connect_to_viewer, and its destructor should call disconnect_from_viewer. If connect_to_viewer fails, the Adapter can either assert failure, throw an exception (if you use exception handling), or return a failure status through a reference argument.

Assignment, Part B:

Update/replace the following components of your Sorter with ACE components:

  1. Update your Sort_Viewer_Client Adapter to use the ACE_SOCK_Connector class. Do this by replacing your calls to connect_to_viewer, send_to_viewer and disconnect_to_viewer with code that might look something like:
    
    ACE_SOCK_Connector con;
    ACE_SOCK_Stream sock;
    ACE_INET_Addr viewer_host ((u_short) JAVA_VIEWER_PORT, JAVA_VIEWER_HOST);
    
    const int status = con.connect (sock, viewer_host);
    // Check status for error indication!  You might want to
    // use ACE_ERROR's %p option; see example with close () below.
    
    // Use one of the ACE_SOCK_IO (base class of ACE_SOCK_STREAM)
    // methods to send the Sort_Response through the socket to the
    // Java viewer.
    // . . .
    
    if (sock.close () == -1)
      ACE_ERROR ((LM_ERROR, "%p\n", "close"));
    

  2. Replace your use of direct file (ifstream) reads with use of ACE_FILE_Connector. The code will look very similar to that for ACE_SOCK_Connector, shown above. There is an ACE_FILE_Addr constructor that takes a const char * argument (LPCTSTR is the same as const char * on Solaris). You shouldn't need to override any of the default ACE_FILE_Connector arguments.

  3. (Optional): Use an ACE Reactor to collect the Sort_Responses to a Sort_Observer.

  4. (Optional): Replace your Array template class with ACE_Array. ACE_Array is very similar to our Array, so this should be straightforward. (One difference is the order of the arguments to the set member function.) It's not required, but will reduce the amount of code that you turn in (and therefore, gets graded!).

Obtaining the Lab 7 distribution:

At a Unix shell prompt, type ~cs342/bin/lab7. That will copy a Makefile to a new lab7 subdirectory. You can cd lab7 and copy your Lab 6 code.

NOTE:: you must use GNU gmake with this Makefile. See above for more information.

What to Submit:

By the due date (Sunday 25 April 1159 pm), submit all source files from your final solution. Include a laboratory writeup file (named readme) documenting what you did to satisfy this assignment. readme contains a minimum list of sections that you must provide. (Please replace the comments in [] with your descriptions.) These files will be submitted automatically when you execute the command:
make turnin
NOTE: there is a Makefile target that allows you to test what you are going to turn in:
make test_turnin

It places the output that will be turned in into the TEST_TURNIN directory. You are responsible for using make test_turnin, and verifying that the files that you will submit are correct.


Please see the Lab 6 assignment for notes on using the Java Sort Viewer.


Please see the Lab 4 assignment for notes on installing the History class to help track and count instantiations and deletions of an instrumented class.


Please see the Lab 3 assignment for hints on compiling templates.


CS 342 newsgroup