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.
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.
create_sorter
Factory Method.
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.
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);
}
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.
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"));
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.
Sort_Responses to a Sort_Observer.
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!).
~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.
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.