![]() |
Business Internet Services |
DetailsThe dxp system is a framework for building web applications. It compiles XML source pages with special tags into server side objects that respond to http requests. It is normally used to interact with database tables and dynamically create html content on the fly. Simple and complex web applications can be constructed from a collection of dxp pages. Pages are controlled by a DxpServlet that runs in a compatible servlet runner like
Tomcat or Resin. Servlet Runners are often paried with Apache through a runtime module. The
diagram below shows an Apache/Resin combination. In a typical setup at plands.com each Virtual Host contains a separate application zone
with it's own set of active pages and default services. Classes in one zone can be reloaded
without affecting other Virtual Hosts. Connections to the appropriate database tables are
allocated in advance. Passing a reaquest to a .dxp pagePage requests with the file extension .dxp are passed by Apache to mod_caucho which forwards them to the correct Servlet Runner and the DxpServlet running in the correct Virtual Host. The DxpServlet will load pages from it's cache of precompiled pages or compile them from source and put them back into the cache if not found or out of date.
Strcuture of a compiled pageDxpPages are written as XML source files and parsed with a SAX parser. As the parser reads a .dxp file it uses the DxpNodeLinker to create a set of active and passive tags and link them together into a tree of DxpNodes. Each node may have a link to it's immediate parent, first child and first sibling. The top node parent (root node) is the DxpPage itself. All the other nodes are it's children. If you looked at the dxp source code for any page in the Sample
section you will notice that some active tags begin with the prefix <dxp: >.
The prefix tells the node linker to create an active node. The prefix also tells the linker where
to find the Java class files to create the node using the xmlns: attribute at the top
of the page.
The xmlns attribute refers to a namespace dxp.plands.com which points to this website but can also be reversed to create the package name com.plands.dxp. The default dxp classes reside in this package. Tags that are not associated with a prefix and namespace are considered passive. This includes html tags, whitespace and text outside active tags. All passive char data that occurs between any two active tags is stored in a single <dxp:Cdata> node. This is automatically created by the linker. Merging passive tags and character data into a single node greatly reduces the number of active objects, lowers the memory footprint and speeds execution. Extending dxp with your own tagsMultiple namespaces can exist on the same page so you can declare your own namespace to add your
own custom tags that load from your packages. For example, the prefix xyz.yourdomain.com
will be mapped to the package com.yourdomain.xyz. Custom tags need to subclass
com.plands.DxpNode or one of it's decendants so they can be linked into the tree.
Executing a page - a tree of DxpNodesWhen an http request is sent to a DxpPage the request is turned into a DxpRequest
and passed to the root node (the DxpPage node). The default execution path assumes that child nodes
perform a service for their parents so it passes the request to innermost child nodes first, then
their siblings and then back up to the parent. Controlling executionMany nodes override the default execution behavior and control their own children.
If, ElseIf nodes are a good example and test a simple expression with parameter
values before passing execution to child nodes they enclose.
Database results can be written out in tables using LoopSet and LoopSetIterator tags to format each row of data. Hyperlinks can be created dynamically from tags and result sets. All this can be done on the same page without resorting to complex stylesheet processing on the server. Execution order is top down and sequential so it's easy to follow. XSL Stylesheets are good at rendering XML tags and if you want to deliver straight XML you can use LoopSetX to format database results directly into XML and tell the browser to download an XSL stylesheet to display them. On the other hand, controlling program execution through stylesheets can be very confusing. Stylesheet processing is recursive and does not necessarily follow the top to bottom sequence you expect to see. It's easier to control execution on a dxp page and then format the result for display with a stylesheet when required. The xml-xsl section has a couple of examples. All modern browsers support XSL stylesheets so why do this on the server? Processing resultsWhen a node executes it can write data to an output buffer and/or it can store a result back
in the request under a new parameter name. Subsequent nodes that know the parameter name can get
these values when the request is passed to them and do further processing. Simple text or complex
Java objects can be produced, stored and passed down the execution tree in this manner. For example,
a database result is normally stored for another tag to process...
Because DxpNodes store temorary results back in the request rather than storing them internally a single node tree can handle multiple requests at the same time. This is similar to a properly designed servlet and is usually referred to as being 'thread safe'. If the result was stored in the node itself the page could only handle one request at a time and would not be thread safe. This behavior highlights a major difference between the dxp system and some other XML based systems that rely on DOM (Document Object Model) trees. A common practice is to create a new tree of nodes for each request and pass the tree to a server side stylesheet processor to format the result. This can be a very expensive operation when page content chages with every request. It still has a place when the content does not change very often and can be cached. Now that most browsers support XSL processing, there are fewer reasons to do this on the server. A typical DxpPage is not expensive because it uses the same page for all requests and formats the result itself or instructs the browser to download the appropriate stylesheet and do it's own formatting. Some pages can become expensive over time. A page that queries a database and returns a large result set for each request will create a lot of Java objects. Eventually they will use up the memory allocated to the JVM and the garbage collector will kick in to reclaim memory from objects that are no longer used. This will cause a brief pause in the Servlet Runner and the application. If a lot of pages have been removed form the cache due to non-use and suddenly need to be recompiled this can also cause a pause. These effects can be minimized by using dxp to write static pages that are updated at regular
intervals to reflect new data. Static files can be delivered by Apache directly from your disk
cache.
The TimerServlet can be used to call pages at regular intervals to refresh their static
files with new results. Here's a sample task file read by the TimerServlet...
If your static files change at regular intervals you can put instructions into the
head section of the page that tells browsers not to cache them.
Services available to dxpThere are a number of services that can be used by .dxp pages. These include:
ConfigurationThe hardest part of using the dxp system is integrating it with other applications such as Apache, Resin or Tomcat, MySQL. Xerces and Java. This is addressed in the Config section. |
|
© 2005 Planetary
Data Systems.
All rights reserved. |