FTP Online
Search:
Locator+ Code:
FTPOnline Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

email article
printer friendly
more resources

Make Your Apps Operations Friendly With AOP
Learn how aspect-oriented programming (AOP) lets you add new behaviors to your application without modifying existing code.
by Robert Swarr

Posted March 15, 2004

For This Solution: AspectJ 1.0.6, Jarkarta Tomcat 4.1.x, and Jakarta Commons Logging 1.0.x are required.

All too often, organizations overlook operations management requirements until after applications are deployed. Then it's more difficult to address concerns. As a result, organizations are burdened with hard-to-manage applications.

Imagine this scenario: After completing a new application, the development team moves onto another project. Now you must support what they built, a Web application with numerous Java classes. At first the application runs well. You have more tasks than hours in the day, so you don't examine the new application too closely. Suddenly, it stops processing requests. After a half-hour of unsuccessful diagnostics, you stop and start the server, and, thankfully, the application begins processing requests again. After reviewing the application source code, you realize its logging is poorly designed and coded. You notice that many exception handlers are defined with empty blocks like this:

try {
   // Code that throws Exception
} catch (Exception e) {
   // Ignore Exception
}

Other exception handlers are defined like this:

try {
   // Code that throws Exception
} catch (Exception e) {
  System.out.println("Exception: 
     " e.getMessage()); 
}

The latter example is better because it reports the exception. However, the output could be lost among all the other messages on the console, and it doesn't supply enough information to help diagnose the problem.

You rightfully suspect that the application failure's root cause is an unreported or unnoticed Exception. But what do you do? You don't have the resources to rewrite the application. Fortunately, aspect-oriented programming (AOP) offers an elegant solution to this all-too-common problem. AOP allows you to add crosscutting behaviors such as logging to a Java application without changing the existing code.

What is Aspect-Oriented Programming?
How does AOP let you change an application's behavior without editing source code? The short answer is that the AOP implementations combine aspects and existing code to add new behavior to an application. They include a software component that weaves aspects and application code into an executable that embodies the behaviors defined in the aspects. Either a compiler or classloader can perform this weaver function. Different implementations interlace aspects and application code in different ways, which I'll discuss in the next section.




Back to top



ADVERTISEMENT

Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home