SoftwarePractice.org: Home | Courseware | Wiki | Archive

Lab exercise 1: Execution Architecture

From SoftwarePractice.org

The goal of this lab session is to explore some of the basic concepts of execution architecture. You will also learn how to access the source code repository that you will be using throughout the semester.

Contents

1.1 Checking out your repository

The first step is to check out your code from the source code repository server. For this purpose, you will be using subversion.

The exercise to familiarise yourself with TortoiseSVN, the client program for using subversion can be downloaded from UTSOnline. It is intended to be done with a pair of students, using two separate computers.

1.2 Interactive command-line servers

This exercise gives you the opportunity to examine and play around with two simple client-server architectures. Each server is a simple Java program that you compile and run on your computer, and the "client" is any implementation of telnet.

  1. Compile and run the "SimpleServer" Java program. (We assume that you know by now how to compile and run Java programs; if not, see an instructor for help during the lab session.)
  2. In a shell (or MS-DOS) window, use telnet to connect to the server, which should be listening on port 10,000:

    >telnet localhost 10000

    Verify that the server is operating correctly by typing at it.
  3. Open another shell (or MS-DOS) window and try to connect to the server in the same way. What happens, and why?
  4. The SimpleServer class has an obvious defect: it can serve only one request at a time. The "ThreadedServer" Java program is a much improved program.
    Compile and run ThreadedServer. Telnet to it again and type at it. Without quitting the first connection, create another shell window and connect to the server.
    • Read the source code of ThreadedServer. What is the key architectural difference of this server to SimpleServer?
    • What, in your opinion, makes it an architectural difference (if anything)?


Note. You may need to set the CLASSPATH for the Java compiler to the local working directory (indicated by . (dot) in Unix). To run the Java program, type

> java -classpath . SimpleServer

1.3 A multi-process system

The simple system you ran in the previous section consists of just a single process. In terms of the architectural viewpoint presented in this course, this is:

  • A single concurrent subsystem with internal concurrency (since it creates threads dynamically), that is
  • stereotyped as a service (since its main mode of operation is to respond to requests from other subsystems)

In this section of the lab, you will be working with a slightly more complex system, which has two services. By default, one of these simply forwards requests to the other, and returns its response.

  1. Make a copy of ThreadedServer.java, and name it NameServer.java. Modify NameServer.java so that:
    • It doesn't echo each received character. (This is useful when a person connects, but not for a computer.)
    • It listens on a different port, say, 8001.
    • It contains an ArrayList (or HashMap), where each key is the first name of one of your team members, and the value is that team member's full name.
    • When it receives a command such as "name Frank", it looks up "Frank" in the ArrayList and returns the result.
  2. Run NameServer and test it.
  3. Compile the program ProxyServer.java, and run it. ProxyServer, when started, needs three parameters:
    • The port number that it listens on.
    • The address of the other server.
    • The port number that the other server listens on.

    ProxyServer has been written to expect these parameters on the command line; here is an example:

    > java ProxyServer 8000 localhost 8001

  4. Connect to ProxyServer.java using telnet, and test it.
  5. Modify ProxyServer so that it forwards only "name" commands to NameServer, and returns an error message otherwise. Restart it and test.

Starting the two services separately, in two separate shell windows, is quite a pain. In the next part, we will create a shell script to start up the system. These scripts can become quite complicated.

1.4 Startup scripts

We will use a very simple script to start the two-server system created in the previous part.

  1. Open a text editor and create a new file called run.sh. This script will be used to start the two processes, and should look something like this:

    #!/bin/sh echo Starting up our two services...
    java NameServer 8001 &
    java ProxyServer 8000 localhost 8001 &

    Each line that invokes Java starts a new process that runs independently; this is indicated by the ampersand at the end of the line.
  2. Execute this script, using the Cygwin Unix Shell, as follows:

    $ ./run.sh

    (If you are on a Unix machine, you may need to change the permissions of the script. Use chmod a+x run.sh.)
  3. Use telnet to connect to ProxyServer and verify that the system is working as before.
  4. Use the ps command to see which processes are running.

    $ ps -f

    You will recognize the two services because they will show up as Java processes. For example, you may get a listing that looks like this:

    UID PID PPID TTY STIME COMMAND
    JohnR 300 1 con 15:21:32 /usr/bin/bash
    JohnR 992 1 con 16:06:17 /cygdrive/c/WINNT/system32/java
    JohnR 944 1 con 16:06:17 /cygdrive/c/WINNT/system32/java
    JohnR 740 300 con 16:13:33 /usr/bin/ps

    The PID column is the process ID. You can kill the processes by:

    $ kill -9 992
    $ kill -9 944
Personal tools