Previous Contents Index Next |
iPlanet Application Server Developer's Guide |
Chapter 14 Taking Advantage of the iPlanet Application Server Features
This chapter describes how to implement the iPlanet Application Server features in your application. The iPlanet Application Server provides many additional features to augment your servlets for use in an iPlanet Application Server environment. These features are not a part of the official servlet specification, though some, like the servlet security paradigm described in Chapter 13 "Writing Secure Applications," are based on emerging Sun Microsystems® standards and conforms to these future standards.This chapter contains the following sections:
Caching Servlet Results
Caching Servlet Results
The iPlanet Application Server has the ability to cache a servlet's results in order to make subsequent calls to the same servlet faster. The iPlanet Application Server caches the request results (for example, a servlet's execution) for a specific amount of time. In this way, if another data call occurs the iPlanet Application Server can return the cached data instead of performing the operation again. For example, if your servlet returns a stock quote that updates every 5 minutes, you set the cache to expire after 300 seconds.Whether to cache results and how to cache them, depends on the data type involved. For example, it makes no sense to cache the results of a quiz submission because the input to the servlet is different each time. However, you could cache a high level report showing demographic data taken from quiz results and updated once an hour.
You can define how an iPlanet Application Server servlet handles memory caching by editing specific fields in the servlet's configuration file. In this way, you can create programmatically standard servlets that still take advantage of this valuable iPlanet Application Server feature.
Table 14-1 shows the caching settings in a servlet configuration file.
For more information on these settings, see "Elements for Specifying Servlet Caching."
The cache-criteria field sets criteria to determine if servlet results are cached. This field tests one or more fields in the request. This allows conditionally cache results based on value or presence of one or more fields. If the tests succeed, the servlet results are cached.
Table 14-2 shows the cache-criteria field syntax.
Using a Startup Class
A startup class is a user-defined class object that is automatically loaded into memory when the iPlanet Application Server starts up. It performs initialization tasks within the Application Server environment. The characteristics of a StartupClass object are:
It spans through the life of server in which it runs.
A startup class must meet the following requirements:It is notified when the server shuts down.
It runs within the JVM of a kjs process, so each kjs process owns one instance of the StartupClass object.
It must be in the package com.iplanet.ias.startup.
The following sections describe how to create and use a startup class:It must be named StartupClass.
It must implement the interface com.iplanet.ias.startup.IStartupClass.
Note Only one StartupClass object can be deployed to an Application Server instance.
The IStartupClass Interface
The IStartupClass Interface
The StartupClass class must implement the IStartupClass interface. The IStartupClass interface defines two methods:
public void startUp() throws StartupClassException
A com.iplanet.ias.startup.StartupClassException is thrown if the startUp method fails. Its signature is as follows:
public void shutDown()
- This method is called to perform activities when kjs starts up (kjs calls the StartupClass default constructor, which calls this method). This method may perform any action. It is invoked after the kjs engine establishes all the relevant contexts, so it can access EJB and JDBC resources.
- If an exception occurs, this method throws a com.iplanet.ias.startup.StartupClassException.
- This method should deallocate any resources allocated during startup.
public class StartupClassException extends java.lang.Exception
Its one constructor is as follows:
public StartupClassException(java.lang.String msg)
Building the Startup Class
Building the class is supported through Ant (although using Ant is not required). Building the StartupClass file and any dependent java files in the install_dir/startup directory is recommended, because the files necessary for building it are there. Make sure you have done these things first:
Include install_dir/bin in the Shell's PATH environment variable.
The following are the build options:Include the path to the JDK in the Shell's PATH environment variable.
If you are not building the StartupClass file in the install_dir/startup directory, copy the StartupClass.java, startup.properties, and build.xml files from that directory into the build directory you are using.
Note The name of the .jar file must be startup.jar.
Deploying the Startup Class
Deployment is supported through the iasdeploy tool. There are two kinds of deployment:
Local deployment
The path can be the following:
Remote deployment
- iasdeploy deploystartup path/startup.jar
- For example:
- iasdeploy deploystartup /iasroot/ias/startup/classes/startup.jar
- iasdeploy deploystartup -host server -port port -user userName -password password path/startup.jar
- For example:
- iasdeploy deploystartup -host myserver -port 80 -user jjones -password secret /iasroot/ias/startup/classes/startup.jar
The relative path to the startup.jar file from the directory in which iasdeploy is run
Concurrent deployment on multiple machines is not supported by the iasdeploy tool.The startup.jar file is deployed to the install_dir/STARTUPCLASS directory.
Note If the startup class is deployed to a directory other than install_dir/STARTUPCLASS, an informational message is generated in the kjs log when the application server starts up.
Note The Deployment Tool does not provide support for assembling startup class modules.
How kjs Handles the StartupClass Object
For each kjs process that runs in its own JVM, there is one instance of the StartupClass object.Inside the run method of com.kivasoft.engine.Engine.java, the StartupClass object is created by the system class loader after the environment is set up, but before any other method is performed. The startUp method is performed when the StartupClass object is created.
If the startUp method executes successfully, kjs runs until it shuts down normally. At graceful shutdown (with iascontrol stop), kjs calls the shutDown method of the StartupClass object.
If the startUp method throws a com.iplanet.ias.StartupClassException, kjs calls the shutDown method, and the StartupClass object is immediately garbage collected. Then kjs exits.
Previous Contents Index Next
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.
Last Updated March 06, 2002