![]() ![]() ![]() ![]() |
![]() |
This chapter provides a high-level overview of Enhydra, Enhydra applications, and the tools used to create Enhydra applications.
Enhydra is an application server for running robust and scalable multi-tier web applications, and a set of application development tools.
An application server usually operates between a web server and a database server, and provides dynamically-generated content for the web server to send to web browser clients.
As illustrated in Figure 2.1, Enhydra has three parts:
- Multiserver, that runs Enhydra applications either by itself or with a web server.
- The application framework, a collection of Java classes that provide the runtime infrastructure for Enhydra applications.
- Enhydra tools that you use to develop Enhydra applications.
An Enhydra application is a Java program that runs in Multiserver and uses the Enhydra application framework at runtime. Figure 2.1, "Enhydra application architecture" illustrates the basic elements of an Enhydra application within the context of the Enhydra architecture.
The next section describes Enhydra applications in more detail.
Figure 2.1 Enhydra application architecture
What's New in 3.0
Enhydra 3.0 includes a number of new features, including:
- Load balancing through Enhydra Director (see "Enhydra Director" for more information).
- Support for the Java Servlet 2.2 API.
- Support for Java Server Pages (JSP) 1.1 API.
- Dynamic recompilation of XMLC classes.
- Numerous other improvements, including:
An Enhydra application has, at a minimum:
These objects run in the context of the Enhydra application framework, as described in "The Enhydra Application Framework."
Application Object
The application object is the central hub of an Enhydra application, and is a subclass of com.lutris.appserver.server.StandardApplication. It contains application-wide data, such as:
- The application's name.
- The application's status (running/stopped/dead).
- The name and location of the configuration file that initializes the application.
- The log channel to use for logging.
- References to the application's: session manager, database manager, and presentation manager, as described in "The Enhydra Application Framework."
You can add properties (instance variables) to the application object to store information that needs to be accessible throughout the application. For example, if your application has a dozen pages that need to share a collection of customer data, you could make a vector containing the data a property of the application object so all the pages can easily access it.
Each application object has the following methods:
- The startup( ) method starts the application; you can extend this to perform other startup functions, such as reading settings from the configuration file.
- The requestPreprocessor( ) method initializes the Session data structure; you can extend this as needed; for example, to check for HTTP basic authorization.
In general, application objects do not deal with HTML, handle requests or otherwise talk to the network. The presentation objects perform these tasks.
Presentation Objects
A presentation object (PO) generates dynamic content for one or more pages in an Enhydra application.
When a browser requests a URL that ends in
.po
, Enhydra passes the request on to the corresponding presentation object. Enhydra then instantiates and calls the presentation object. For example, for the URLhttp://www.foo.com/myapp/Xyz.po
, Enhydra will call the presentation object Xyz.Note: Enhydra only calls a presentation object for URLs with a
.po
suffix. The web server will generally serve a static file for other requests.Presentation objects must implement the interface com.lutris.appserver.server.httpPresentation.HttpPresentation. This interface has one method, run( ), that Enhydra calls, passing it an HTTP request to handle. Presentation objects differ from Servlets in that they need handle only a single request at a time. No concurrency control is required.
Enhydra also provides a response object that a PO can use to write data in response (similar to a servlet's service( ) method). POs usually handle GET requests (for example form submissions) and respond by writing HTML, but they may perform other functions, for example, read files sent by a POST request.
The Three Layers
For modularity and ease of maintenance, you should divide your application into three distinct parts or layers:
- The presentation layer contains presentation object (POs). POs handle how the application is presented to web browsers through HTML.
- The business layer contains business objects (BOs). BOs contains the application's business logic, including algorithms and specialized functions, but not data access nor display functions.
- The data layer contains data objects (DOs). DOs interface with the persistent data source, which is typically a relational database.
The Enhydra Application Framework only requires that you use an application object and presentation objects. The business and data classes you create are up to you. Dividing your application into these three layers minimizes maintenance cost because it isolates the application's data layer from the user interface. This, in turn, enables you to change the data layer without affecting the presentation layer.
An additional benefit of having a distinct data layer is that you can use the Data Object Design Studio (DODS) to create your data objects. DODS graphically creates data objects to populate the data layer, and creates both Java code and SQL code to create the corresponding tables in the database.
Multiserver is the runtime component of Enhydra. It provides the services that an Enhydra application uses to communicate with the web server, and perform all its other runtime functions.
To understand Enhydra Multiserver, you need to understand a little about servlets. A servlet is a Java class that dynamically extends the functionality of a web server. Normally, when a browser sends a request to a web server, the server simply finds the files identified by the requested URL and returns them to the browser. However, if the browser requests a page constructed by a servlet, the server sends the request information to a servlet, which constructs the response dynamically and returns it to the server.
The Java servlet API is a standard extension to Java and is part of the Java2 Enterprise Edition (J2EE). Some web servers support the servlet API directly, while others require an adjunct servlet runner, such as JServ for the Apache web server. Enhydra 3.0 supports the servlet API version 2.2.
Each Enhydra application runs as a single servlet, in contrast to a generic servlet application, which typically has one servlet for each dynamically-generated page. Enhydra Multiserver is a servlet runner that executes servlets such as Enhydra applications, either with a web server or by itself. Multiserver can run applications in a small-scale development environment on its own; for a production environment requiring greater performance, you can use Multiserver in conjunction with a web server.
Note: Since an Enhydra application is a servlet, it can run in any standards-compliant servlet runner, not just in Multiserver.
Enhydra Multiserver has a custom class loader for each application (servlet). Because of this one-to-one correspondence between servlets and class loaders, you can install and start new applications without needing to stop the server. To update an existing application, you simply restart its class loader.
Enhydra Director
Enhydra Director is a new feature in Enhydra 3.0 that provides applications superior scalability by distributing the user load among several Enhydra Multiservers. The load balancing algorithm supports session affinity and weighted round-robin distribution with server failover. Session affinity means that a particular session instance will always access the same Multiserver instance. The weighted round-robin load balancing scheme takes into account the capacity of each Multiserver instance and the number of existing connections. Server failover ensures that if a Multiserver goes down, all application connections are automatically transferred to another Multiserver instance.
Director uses a new connection method, the Enhydra Director connection method, and a new set of web server extension modules. Enhydra Director works with Apache servers via the Apache Module interface, Netscape servers via Netscape Application Programming Interface (NSAPI), and Microsoft servers via the Internet Server Application Programming Interface (ISAPI), and other web servers via the Common Gateway Interface (CGI).
For more information and installation instructions for Enhydra Director, see the online documentation installed with Enhydra.
The Administration Console
Enhydra Multiserver provides an administration console for managing applications through a web browser. The administration console enables you to:
- Start and stop applications.
- Add and remove applications from management.
- Modify an application's operational attributes and check its status.
- Trace the execution of an application to aid in debugging.
The administration console is described in more detail in "Using the Multiserver Administration Console."
The Enhydra application framework includes:
In general, the application framework includes all the classes in the com.lutris.appserver.server.* packages, that provide the infrastructure that Enhydra applications use at runtime. The general architecture of an Enhydra application in the context of the application framework is illustrated in Figure 2.1, "Enhydra application architecture."
Figure 2.2 Enhydra Application and Enhydra Framework
Presentation Manager
The Enhydra presentation manager handles the loading and execution of the presentation objects in an Enhydra application. The presentation manager maps URLs to POs, and calls the PO's run( ) method.
Each Enhydra application has one instance of a presentation manager. To increase performance, the presentation manager caches POs and associated files in memory as necessary. The presentation manager also provides the key that the session manager uses to locate a session; this key is either a cookie or a string appended to each URL in the application.
Each application has a presentation manager that is an instance of the class com.lutris.appserver.server.httpPresentation.HttpPresentationManager. The com.lutris.appserver.server.httpPresentation package contains classes and interfaces that the presentation manager and POs use.
Session Manager
The Enhydra session manager enables an application to maintain state throughout a session. A session is defined as a series of requests from the same user (browser client) during a specified time period. Enhydra provides a general implementation of session management that you can extend to create more sophisticated state models.
Enhydra maintains user state by creating a Session object for each user. When a user first makes a request to an application, the session manager creates a new Session object and assigns it a unique session ID. The session manager uses the session ID to retrieve the Session object for subsequent requests. Applications can add user-specific information to the Session object, and then access the Session object from the request object, as it is passed through the application.
If a user has been idle (has not issued a request to the application) for more than the period specified in the configuration file, the user's session becomes invalid, and the session manager releases the corresponding Session object. This makes it possible to implement security schemes that require users to log in before accessing the application. In such a scheme, the user enters an appropriate password and gains access to the rest of the application; however, once the user's session has been idle for more than the allowed time (for example, ten minutes), the application requires the user to log in again.
Each application has a session manager that is an instance of the class com.lutris.appserver.server.session.StandardSessionManager. When it is created, the session manager reads the maximum time that a session can persist, the maximum session idle time, and other related information from the application configuration file, appName
.conf
. The com.lutris.appserver.server.session package contains classes and interfaces that the session manager and the application use for session management.Database Manager
The Enhydra database manager controls an application's pool of database connections. The database manager works with logical databases. A logical database is an abstraction that hides the differences between different database types. A logical database uses Java Database Connectivity (JDBC) to communicate with database servers such as Oracle, Sybase, and Informix.
The database manager is responsible for the state of a database connection, the SQL statements that are being executed, and the result sets that are in progress. Specifically, the database manager:
- Allocates and releases connections to the logical database.
- Allocates object IDs from the logical database.
- Creates queries and transactions.
- Maintains other database-related information.
Each application has a database manager that is an instance of the class com.lutris.appserver.server.sql.StandardDatabaseManager. When it is created, the database manager reads a configuration file that specifies the logical database to use, the actual database types to which it maps, and other related information.
The com.lutris.appserver.server.sql package contains the classes and interfaces that the database manager and data objects use.
Enhydra includes the following tools to help you create applications:
- The Application Wizard
- The Extensible Markup Language Compiler (XMLC)
- The Data Object Design Studio (DODS)
Application Wizard
The application wizard (newapp) is a command-line tool that creates a basic framework for an Enhydra application. The application wizard allows you to create and run a new "stub" application in a matter of minutes, giving your development project a jump-start.
The application wizard is also incorporated into the Enhydra Kelp tools, so that you can perform the same operation from the JBuilder graphical IDE.
For an example of using the application wizard, see "Creating Your First Application."
XMLC
The Extensible Markup Language Compiler (XMLC) creates a Java object that mirrors the structure of an XML document. Extensible Markup Language (XML), which is defined by the World Wide Web Consortium (W3C), is the universal format for structured documents and data on the Web. XMLC uses the document object model (DOM), a W3C standard interface to allow a programs to access and update the content and structure of XML documents.
Note: Although XMLC works with XML documents, this book will focus on its use with HTML pages.
XMLC enables you to cleanly separate HTML templates in your application, which are typically created by page designers from Java code, which is typically created by programmers. This provides increased modularity and eases team development and application maintenance. Page designers can change the user interface of the application without requiring any code changes, and the programmers can change the "back-end" Java code without requiring any changes to the HTML.
XMLC is a command-line tool that generates a Java class file from an HTML input file. An application can use the Java class at runtime to change the content or attributes of any tags with ID or CLASS attributes. For an example of using XMLC, see "Tutorial: Building Enhydra Applications."
XMLC dynamic recompilation is a new feature in Enhydra 3.0. It enables you to change HTML layouts at runtime without restarting an application.
With the new feature, you can make any changes to the static content of HTML pages, and the application will automatically pick up the changes. As long as you do not add or change any ID and CLASS attributes of tags in a page, you don't have to rebuild and restart the application.
The Data Object Design Studio (DODS)
The Data Object Design Studio (DODS) is a graphical tool you can use to define your data model.
![]()
Data Objects (DOs) in the DODS data model correspond to tables in the database. Each DO has attributes that describe database columns and reference attributes that refer to other DOs. Reference attributes enable you to create a hierarchy of DOs, for example many-to-one or many-to-many relationships.
Once you have defined your data model, DODS generates all of the code to implement it:
- The SQL code to define the database tables
- The Java code to create the corresponding application data objects
For each data object, DODS generates a set of source files. For example, if your data model includes the definition of an entity named "thing," then DODS would generate the following:
- A file containing the SQL CREATE TABLE command to construct a table in a relational database, named
thing.sql
.
- A Java source file defining a data object representing a row the table. This class provides a "set" and "get" method for each attribute, methods to handle caching, and is a subclass of the Enhydra framework class GenericDO. In this example, the class would be named ThingDO.
- A Java source file that defines a query class, which provides SQL query access to the database table. The query class will return a collection of ThingDO objects that represent the rows found in the table matching criteria passed from the application.
- Optionally, a Java source file that defines a business data object (BDO) class to handle interaction between the data object and the business layer. In this example, the class would be named ThingBDO by default.
When DODS generates source code, it creates a directory structure that matches the package hierarchy you have designed. DODS creates the make files in each directory, and runs make on the generated source code. All that is left for you to do is create a database using the SQL files, and write the more interesting components of your application.
For an example of using DODS, see "Using DODS."
The Kelp tools enable you to develop Enhydra applications in Borland JBuilder Oracle JDeveloper interactive development environments (IDEs). You can use Kelp in place of Enhydra's shell scripts and make files.
The following is a general outline of Kelp, as features will very depending on the IDE. See the documentation included with the Kelp tools for specific features supported by your Java IDE.
Enhydra Application Wizard
The Application Wizard generates an Enhydra application that you can develop, run and debug from within an IDE. The wizard lets you set the name, directory and package for your new application. It generates the files described in "Creating Your First Application." It also generates a
Readme.html
file that lists the steps to build and run the new application.XMLC Compiler Wizard
The compiler wizard lets you set XMLC options, select HTML files to compile and call the XMLC compiler from JBuilder.
The wizard also provides a mapping table that maps directories to package names. This is useful when you keep your HTML files in a directory that does not match the package name you want to use in the generated DOM classes. For example, the DiscRack sample project has HTML files in a
resources
directory that need to be compiled using the presentation package.XMLC Property Pages
Property pages give you full control over how XMLC builds DOM classes from HTML files. The property pages allow you to customize class name generation and set XMLC option files for the entire project as well as for individual HTML files.
For example, the DiscRack sample includes three XMLC options files: one for the presentation package, and two more for packages that reside within the presentation package. You can use the XMLC Property Pages to associate each HTML file in the resource directories with the appropriate XMLC options file in the presentation directories.
Enhydra Sample Project
The Enhydra sample project is an IDE project file that lets you build, debug and run your application from within the IDE. The project also demonstrates how to perform several dynamic page generation tasks using XMLC. When you run the Enhydra sample project, the pages display the HTML tags and the Java methods required to perform each task.
Lutris Technologies http://www.lutris.com 1200 Pacific Ave., Suite 300 Santa Cruz, CA 95060 Voice: (831) 471-9753 Fax: (831) 471-9754 documentation@lutris.com |