Multi-Tiered Applications


Application Distribution

The term application distribution refers to where (i.e., on what physical computer) one or more pieces of a network application reside. This section discusses the concepts of physically distributing client and server applications. Server applications themselves can be further divided into multiple application layers with each distinct application layer being physically deployed to one or more computers. The concepts associated with multi-layered applications are presented and discussed in the next section.

Physical Distribution On One Computer

Client and server applications can both be deployed on the same computer. This is most often done for the purposes of testing during development. When you write applets and client-server applications in chapters 20 and 21 you will test them on your development machine. If you are fortunate enough to have a home network that includes multiple computers you can test your client-server applications in a more real-world setting. Figure 19-5 illustrates the concept of running client and server applications on the same physical hardware.

image from book
Figure 19-5: Client and Server Applications Physically Deployed to Same Computer

Running Multiple Java Virtual Machines On The Same Computer

When writing and testing client-server applications using Java you will need to run the server application and client application in separate Java Virtual Machines (JVMs). Figure 19-6 illustrates the concept of running multiple JVM instances on the same computer.

image from book
Figure 19-6: Client and Server Applications Require Separate Java Virtual Machines

Starting Multiple JVMs In Windows

When programming Java applications in the Microsoft Windows environment you will use the MS-DOS command prompt emulator application extensively to compile and test your programs. You can launch separate instances of the JVM in their own command prompt windows by using the start command at the command line:

 start java <application class name>

Figure 19-7 shows multiple JVMs being started in separate command prompt windows using the start command. In this example the server application is named NetRatServer and the client application is named NetRatClient. The start command is shown being issued in the lower-right window titled “Shortcut to cmd”. The NetRatServer application is started first and is shown running in the upper-left command prompt window. The NetRatClient application is running in the upper-right window which is partially obscured by its GUI interface.

image from book
Figure 19-7: Starting Multiple Terminal Windows Using start Command

Starting Multiple JVMs In Unix And Linux

You can start multiple JVMs in Unix or Linux operating systems as well. You can do this in two ways. Either you can open multiple terminal windows and launch each application in a dedicated window or launch each application as a separate process using ‘&’. Figure 19-8 shows the NetRatServer and NetRatClient applications being launched in a Macintosh OS X terminal window as separate processes using the ‘&’.

image from book
Figure 19-8: Multiple JVMs Launched As Separate Processes In Mac OSX

Referring to figure 19-8 — One terminal window titled “Terminal — tcsh” is open. The first command launches the NetRatServer application as a separate process. Notice the ‘&’ applied at the end of the command line before hitting the return key. The following line shows a process number in brackets followed by a process number: [1] 464. The next several lines are the result of the server application start-up process.

Using The ps Command To List Processes In UNIX

The ps command is used to list currently running processes. After the NetRatServer application is launched the ps command is issued to list the processes. The NetRatClient application is then launched as another separate process and again the ps command is used to list the processes. As you can see from figure 19-8 both the server and client applications are now running as separate processes.

Killing Processes

When you start multiple JVM instances as separate processes closing the terminal window is not enough to kill the process. You will have to issue the kill command explicitly. Figure 19-9 shows the kill command being used to kill both the NetRatServer and NetRatClient processes.

image from book
Figure 19-9: Killing Unix Processes with the kill Command

Running Multiple Clients On The Same Computer

You can run multiple client applications on the same computer. Each client will require its own JVM as is shown in figure 19-10. Your server application must be capable of handling multiple concurrent client requests for service. A server application with this capability is generally referred to as being multi-threaded. Each incoming client connection is passed off to a unique thread for processing. The execution of multiple client applications, in addition to the server application, on the same hardware, is common practice during a software project’s development and testing phases.

image from book
Figure 19-10: Running Multiple Client JVMs On Same Hardware

Addressing The Local Machine

When testing client-server applications on your local machine you can use the localhost IP address of 127.0.0.1 as the server application’s host address.

Physical Distribution Across Multiple Computers

Although client and server applications can be co-located on the same hardware it is more often the case that they are physically deployed on different machines geographically separated by great distance. Figure 19-11 illustrates this concept.

image from book
Figure 19-11: Client and Server Applications Deployed On Different Computers

Multiple Java Virtual Machines

Regardless of where the client and server hosts are located the Java applications running on each will require an instance of the Java Virtual Machine. (Each computer needs the Java Runtime Environment (JRE) and any other third-party class libraries to support application execution.) This concept is illustrated in figure 19-12.

image from book
Figure 19-12: Physically Distributed Client and Server Applications Need A JVM

Quick Review

The term application distribution refers to where (i.e., on what physical computer) one or more pieces of a network application reside. Client and server applications can be deployed to the same physical computer. In this case multiple JVM instances are required to execute each client and server application. Client and server applications can be deployed to different physical computers. These computers may be in the same room or located a great distance from each other. Regardless of where the applications reside, each Java application (client or server) will require a JVM to execute.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net